atp870u.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897
  1. /*
  2. * Copyright (C) 1997 Wu Ching Chen
  3. * 2.1.x update (C) 1998 Krzysztof G. Baranowski
  4. * 2.5.x update (C) 2002 Red Hat
  5. * 2.6.x update (C) 2004 Red Hat
  6. *
  7. * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes
  8. *
  9. * Wu Ching Chen : NULL pointer fixes 2000/06/02
  10. * support atp876 chip
  11. * enable 32 bit fifo transfer
  12. * support cdrom & remove device run ultra speed
  13. * fix disconnect bug 2000/12/21
  14. * support atp880 chip lvd u160 2001/05/15
  15. * fix prd table bug 2001/09/12 (7.1)
  16. *
  17. * atp885 support add by ACARD Hao Ping Lian 2005/01/05
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/string.h>
  25. #include <linux/ioport.h>
  26. #include <linux/delay.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/pci.h>
  30. #include <linux/blkdev.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/slab.h>
  33. #include <asm/io.h>
  34. #include <scsi/scsi.h>
  35. #include <scsi/scsi_cmnd.h>
  36. #include <scsi/scsi_device.h>
  37. #include <scsi/scsi_host.h>
  38. #include "atp870u.h"
  39. static struct scsi_host_template atp870u_template;
  40. static void send_s870(struct atp_unit *dev,unsigned char c);
  41. static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c);
  42. static void tscam_885(void);
  43. static irqreturn_t atp870u_intr_handle(int irq, void *dev_id)
  44. {
  45. unsigned long flags;
  46. unsigned short int tmpcip, id;
  47. unsigned char i, j, c, target_id, lun,cmdp;
  48. unsigned char *prd;
  49. struct scsi_cmnd *workreq;
  50. unsigned int workport, tmport, tmport1;
  51. unsigned long adrcnt, k;
  52. #ifdef ED_DBGP
  53. unsigned long l;
  54. #endif
  55. int errstus;
  56. struct Scsi_Host *host = dev_id;
  57. struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
  58. for (c = 0; c < 2; c++) {
  59. tmport = dev->ioport[c] + 0x1f;
  60. j = inb(tmport);
  61. if ((j & 0x80) != 0)
  62. {
  63. goto ch_sel;
  64. }
  65. dev->in_int[c] = 0;
  66. }
  67. return IRQ_NONE;
  68. ch_sel:
  69. #ifdef ED_DBGP
  70. printk("atp870u_intr_handle enter\n");
  71. #endif
  72. dev->in_int[c] = 1;
  73. cmdp = inb(dev->ioport[c] + 0x10);
  74. workport = dev->ioport[c];
  75. if (dev->working[c] != 0) {
  76. if (dev->dev_id == ATP885_DEVID) {
  77. tmport1 = workport + 0x16;
  78. if ((inb(tmport1) & 0x80) == 0)
  79. outb((inb(tmport1) | 0x80), tmport1);
  80. }
  81. tmpcip = dev->pciport[c];
  82. if ((inb(tmpcip) & 0x08) != 0)
  83. {
  84. tmpcip += 0x2;
  85. for (k=0; k < 1000; k++) {
  86. if ((inb(tmpcip) & 0x08) == 0) {
  87. goto stop_dma;
  88. }
  89. if ((inb(tmpcip) & 0x01) == 0) {
  90. goto stop_dma;
  91. }
  92. }
  93. }
  94. stop_dma:
  95. tmpcip = dev->pciport[c];
  96. outb(0x00, tmpcip);
  97. tmport -= 0x08;
  98. i = inb(tmport);
  99. if (dev->dev_id == ATP885_DEVID) {
  100. tmpcip += 2;
  101. outb(0x06, tmpcip);
  102. tmpcip -= 2;
  103. }
  104. tmport -= 0x02;
  105. target_id = inb(tmport);
  106. tmport += 0x02;
  107. /*
  108. * Remap wide devices onto id numbers
  109. */
  110. if ((target_id & 0x40) != 0) {
  111. target_id = (target_id & 0x07) | 0x08;
  112. } else {
  113. target_id &= 0x07;
  114. }
  115. if ((j & 0x40) != 0) {
  116. if (dev->last_cmd[c] == 0xff) {
  117. dev->last_cmd[c] = target_id;
  118. }
  119. dev->last_cmd[c] |= 0x40;
  120. }
  121. if (dev->dev_id == ATP885_DEVID)
  122. dev->r1f[c][target_id] |= j;
  123. #ifdef ED_DBGP
  124. printk("atp870u_intr_handle status = %x\n",i);
  125. #endif
  126. if (i == 0x85) {
  127. if ((dev->last_cmd[c] & 0xf0) != 0x40) {
  128. dev->last_cmd[c] = 0xff;
  129. }
  130. if (dev->dev_id == ATP885_DEVID) {
  131. tmport -= 0x05;
  132. adrcnt = 0;
  133. ((unsigned char *) &adrcnt)[2] = inb(tmport++);
  134. ((unsigned char *) &adrcnt)[1] = inb(tmport++);
  135. ((unsigned char *) &adrcnt)[0] = inb(tmport);
  136. if (dev->id[c][target_id].last_len != adrcnt)
  137. {
  138. k = dev->id[c][target_id].last_len;
  139. k -= adrcnt;
  140. dev->id[c][target_id].tran_len = k;
  141. dev->id[c][target_id].last_len = adrcnt;
  142. }
  143. #ifdef ED_DBGP
  144. printk("tmport = %x dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",tmport,dev->id[c][target_id].last_len,dev->id[c][target_id].tran_len);
  145. #endif
  146. }
  147. /*
  148. * Flip wide
  149. */
  150. if (dev->wide_id[c] != 0) {
  151. tmport = workport + 0x1b;
  152. outb(0x01, tmport);
  153. while ((inb(tmport) & 0x01) != 0x01) {
  154. outb(0x01, tmport);
  155. }
  156. }
  157. /*
  158. * Issue more commands
  159. */
  160. spin_lock_irqsave(dev->host->host_lock, flags);
  161. if (((dev->quhd[c] != dev->quend[c]) || (dev->last_cmd[c] != 0xff)) &&
  162. (dev->in_snd[c] == 0)) {
  163. #ifdef ED_DBGP
  164. printk("Call sent_s870\n");
  165. #endif
  166. send_s870(dev,c);
  167. }
  168. spin_unlock_irqrestore(dev->host->host_lock, flags);
  169. /*
  170. * Done
  171. */
  172. dev->in_int[c] = 0;
  173. #ifdef ED_DBGP
  174. printk("Status 0x85 return\n");
  175. #endif
  176. goto handled;
  177. }
  178. if (i == 0x40) {
  179. dev->last_cmd[c] |= 0x40;
  180. dev->in_int[c] = 0;
  181. goto handled;
  182. }
  183. if (i == 0x21) {
  184. if ((dev->last_cmd[c] & 0xf0) != 0x40) {
  185. dev->last_cmd[c] = 0xff;
  186. }
  187. tmport -= 0x05;
  188. adrcnt = 0;
  189. ((unsigned char *) &adrcnt)[2] = inb(tmport++);
  190. ((unsigned char *) &adrcnt)[1] = inb(tmport++);
  191. ((unsigned char *) &adrcnt)[0] = inb(tmport);
  192. k = dev->id[c][target_id].last_len;
  193. k -= adrcnt;
  194. dev->id[c][target_id].tran_len = k;
  195. dev->id[c][target_id].last_len = adrcnt;
  196. tmport -= 0x04;
  197. outb(0x41, tmport);
  198. tmport += 0x08;
  199. outb(0x08, tmport);
  200. dev->in_int[c] = 0;
  201. goto handled;
  202. }
  203. if (dev->dev_id == ATP885_DEVID) {
  204. if ((i == 0x4c) || (i == 0x4d) || (i == 0x8c) || (i == 0x8d)) {
  205. if ((i == 0x4c) || (i == 0x8c))
  206. i=0x48;
  207. else
  208. i=0x49;
  209. }
  210. }
  211. if ((i == 0x80) || (i == 0x8f)) {
  212. #ifdef ED_DBGP
  213. printk(KERN_DEBUG "Device reselect\n");
  214. #endif
  215. lun = 0;
  216. tmport -= 0x07;
  217. if (cmdp == 0x44 || i==0x80) {
  218. tmport += 0x0d;
  219. lun = inb(tmport) & 0x07;
  220. } else {
  221. if ((dev->last_cmd[c] & 0xf0) != 0x40) {
  222. dev->last_cmd[c] = 0xff;
  223. }
  224. if (cmdp == 0x41) {
  225. #ifdef ED_DBGP
  226. printk("cmdp = 0x41\n");
  227. #endif
  228. tmport += 0x02;
  229. adrcnt = 0;
  230. ((unsigned char *) &adrcnt)[2] = inb(tmport++);
  231. ((unsigned char *) &adrcnt)[1] = inb(tmport++);
  232. ((unsigned char *) &adrcnt)[0] = inb(tmport);
  233. k = dev->id[c][target_id].last_len;
  234. k -= adrcnt;
  235. dev->id[c][target_id].tran_len = k;
  236. dev->id[c][target_id].last_len = adrcnt;
  237. tmport += 0x04;
  238. outb(0x08, tmport);
  239. dev->in_int[c] = 0;
  240. goto handled;
  241. } else {
  242. #ifdef ED_DBGP
  243. printk("cmdp != 0x41\n");
  244. #endif
  245. outb(0x46, tmport);
  246. dev->id[c][target_id].dirct = 0x00;
  247. tmport += 0x02;
  248. outb(0x00, tmport++);
  249. outb(0x00, tmport++);
  250. outb(0x00, tmport++);
  251. tmport += 0x03;
  252. outb(0x08, tmport);
  253. dev->in_int[c] = 0;
  254. goto handled;
  255. }
  256. }
  257. if (dev->last_cmd[c] != 0xff) {
  258. dev->last_cmd[c] |= 0x40;
  259. }
  260. if (dev->dev_id == ATP885_DEVID) {
  261. j = inb(dev->baseport + 0x29) & 0xfe;
  262. outb(j, dev->baseport + 0x29);
  263. tmport = workport + 0x16;
  264. } else {
  265. tmport = workport + 0x10;
  266. outb(0x45, tmport);
  267. tmport += 0x06;
  268. }
  269. target_id = inb(tmport);
  270. /*
  271. * Remap wide identifiers
  272. */
  273. if ((target_id & 0x10) != 0) {
  274. target_id = (target_id & 0x07) | 0x08;
  275. } else {
  276. target_id &= 0x07;
  277. }
  278. if (dev->dev_id == ATP885_DEVID) {
  279. tmport = workport + 0x10;
  280. outb(0x45, tmport);
  281. }
  282. workreq = dev->id[c][target_id].curr_req;
  283. #ifdef ED_DBGP
  284. scmd_printk(KERN_DEBUG, workreq, "CDB");
  285. for (l = 0; l < workreq->cmd_len; l++)
  286. printk(KERN_DEBUG " %x",workreq->cmnd[l]);
  287. printk("\n");
  288. #endif
  289. tmport = workport + 0x0f;
  290. outb(lun, tmport);
  291. tmport += 0x02;
  292. outb(dev->id[c][target_id].devsp, tmport++);
  293. adrcnt = dev->id[c][target_id].tran_len;
  294. k = dev->id[c][target_id].last_len;
  295. outb(((unsigned char *) &k)[2], tmport++);
  296. outb(((unsigned char *) &k)[1], tmport++);
  297. outb(((unsigned char *) &k)[0], tmport++);
  298. #ifdef ED_DBGP
  299. printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k, inb(tmport-1), inb(tmport-2), inb(tmport-3));
  300. #endif
  301. /* Remap wide */
  302. j = target_id;
  303. if (target_id > 7) {
  304. j = (j & 0x07) | 0x40;
  305. }
  306. /* Add direction */
  307. j |= dev->id[c][target_id].dirct;
  308. outb(j, tmport++);
  309. outb(0x80,tmport);
  310. /* enable 32 bit fifo transfer */
  311. if (dev->dev_id == ATP885_DEVID) {
  312. tmpcip = dev->pciport[c] + 1;
  313. i=inb(tmpcip) & 0xf3;
  314. //j=workreq->cmnd[0];
  315. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  316. i |= 0x0c;
  317. }
  318. outb(i,tmpcip);
  319. } else if ((dev->dev_id == ATP880_DEVID1) ||
  320. (dev->dev_id == ATP880_DEVID2) ) {
  321. tmport = workport - 0x05;
  322. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  323. outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
  324. } else {
  325. outb((unsigned char) (inb(tmport) & 0x3f), tmport);
  326. }
  327. } else {
  328. tmport = workport + 0x3a;
  329. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  330. outb((unsigned char) ((inb(tmport) & 0xf3) | 0x08), tmport);
  331. } else {
  332. outb((unsigned char) (inb(tmport) & 0xf3), tmport);
  333. }
  334. }
  335. tmport = workport + 0x1b;
  336. j = 0;
  337. id = 1;
  338. id = id << target_id;
  339. /*
  340. * Is this a wide device
  341. */
  342. if ((id & dev->wide_id[c]) != 0) {
  343. j |= 0x01;
  344. }
  345. outb(j, tmport);
  346. while ((inb(tmport) & 0x01) != j) {
  347. outb(j,tmport);
  348. }
  349. if (dev->id[c][target_id].last_len == 0) {
  350. tmport = workport + 0x18;
  351. outb(0x08, tmport);
  352. dev->in_int[c] = 0;
  353. #ifdef ED_DBGP
  354. printk("dev->id[c][target_id].last_len = 0\n");
  355. #endif
  356. goto handled;
  357. }
  358. #ifdef ED_DBGP
  359. printk("target_id = %d adrcnt = %d\n",target_id,adrcnt);
  360. #endif
  361. prd = dev->id[c][target_id].prd_pos;
  362. while (adrcnt != 0) {
  363. id = ((unsigned short int *)prd)[2];
  364. if (id == 0) {
  365. k = 0x10000;
  366. } else {
  367. k = id;
  368. }
  369. if (k > adrcnt) {
  370. ((unsigned short int *)prd)[2] = (unsigned short int)
  371. (k - adrcnt);
  372. ((unsigned long *)prd)[0] += adrcnt;
  373. adrcnt = 0;
  374. dev->id[c][target_id].prd_pos = prd;
  375. } else {
  376. adrcnt -= k;
  377. dev->id[c][target_id].prdaddr += 0x08;
  378. prd += 0x08;
  379. if (adrcnt == 0) {
  380. dev->id[c][target_id].prd_pos = prd;
  381. }
  382. }
  383. }
  384. tmpcip = dev->pciport[c] + 0x04;
  385. outl(dev->id[c][target_id].prdaddr, tmpcip);
  386. #ifdef ED_DBGP
  387. printk("dev->id[%d][%d].prdaddr 0x%8x\n", c, target_id, dev->id[c][target_id].prdaddr);
  388. #endif
  389. if (dev->dev_id == ATP885_DEVID) {
  390. tmpcip -= 0x04;
  391. } else {
  392. tmpcip -= 0x02;
  393. outb(0x06, tmpcip);
  394. outb(0x00, tmpcip);
  395. tmpcip -= 0x02;
  396. }
  397. tmport = workport + 0x18;
  398. /*
  399. * Check transfer direction
  400. */
  401. if (dev->id[c][target_id].dirct != 0) {
  402. outb(0x08, tmport);
  403. outb(0x01, tmpcip);
  404. dev->in_int[c] = 0;
  405. #ifdef ED_DBGP
  406. printk("status 0x80 return dirct != 0\n");
  407. #endif
  408. goto handled;
  409. }
  410. outb(0x08, tmport);
  411. outb(0x09, tmpcip);
  412. dev->in_int[c] = 0;
  413. #ifdef ED_DBGP
  414. printk("status 0x80 return dirct = 0\n");
  415. #endif
  416. goto handled;
  417. }
  418. /*
  419. * Current scsi request on this target
  420. */
  421. workreq = dev->id[c][target_id].curr_req;
  422. if (i == 0x42) {
  423. if ((dev->last_cmd[c] & 0xf0) != 0x40)
  424. {
  425. dev->last_cmd[c] = 0xff;
  426. }
  427. errstus = 0x02;
  428. workreq->result = errstus;
  429. goto go_42;
  430. }
  431. if (i == 0x16) {
  432. if ((dev->last_cmd[c] & 0xf0) != 0x40) {
  433. dev->last_cmd[c] = 0xff;
  434. }
  435. errstus = 0;
  436. tmport -= 0x08;
  437. errstus = inb(tmport);
  438. if (((dev->r1f[c][target_id] & 0x10) != 0)&&(dev->dev_id==ATP885_DEVID)) {
  439. printk(KERN_WARNING "AEC67162 CRC ERROR !\n");
  440. errstus = 0x02;
  441. }
  442. workreq->result = errstus;
  443. go_42:
  444. if (dev->dev_id == ATP885_DEVID) {
  445. j = inb(dev->baseport + 0x29) | 0x01;
  446. outb(j, dev->baseport + 0x29);
  447. }
  448. /*
  449. * Complete the command
  450. */
  451. scsi_dma_unmap(workreq);
  452. spin_lock_irqsave(dev->host->host_lock, flags);
  453. (*workreq->scsi_done) (workreq);
  454. #ifdef ED_DBGP
  455. printk("workreq->scsi_done\n");
  456. #endif
  457. /*
  458. * Clear it off the queue
  459. */
  460. dev->id[c][target_id].curr_req = NULL;
  461. dev->working[c]--;
  462. spin_unlock_irqrestore(dev->host->host_lock, flags);
  463. /*
  464. * Take it back wide
  465. */
  466. if (dev->wide_id[c] != 0) {
  467. tmport = workport + 0x1b;
  468. outb(0x01, tmport);
  469. while ((inb(tmport) & 0x01) != 0x01) {
  470. outb(0x01, tmport);
  471. }
  472. }
  473. /*
  474. * If there is stuff to send and nothing going then send it
  475. */
  476. spin_lock_irqsave(dev->host->host_lock, flags);
  477. if (((dev->last_cmd[c] != 0xff) || (dev->quhd[c] != dev->quend[c])) &&
  478. (dev->in_snd[c] == 0)) {
  479. #ifdef ED_DBGP
  480. printk("Call sent_s870(scsi_done)\n");
  481. #endif
  482. send_s870(dev,c);
  483. }
  484. spin_unlock_irqrestore(dev->host->host_lock, flags);
  485. dev->in_int[c] = 0;
  486. goto handled;
  487. }
  488. if ((dev->last_cmd[c] & 0xf0) != 0x40) {
  489. dev->last_cmd[c] = 0xff;
  490. }
  491. if (i == 0x4f) {
  492. i = 0x89;
  493. }
  494. i &= 0x0f;
  495. if (i == 0x09) {
  496. tmpcip += 4;
  497. outl(dev->id[c][target_id].prdaddr, tmpcip);
  498. tmpcip = tmpcip - 2;
  499. outb(0x06, tmpcip);
  500. outb(0x00, tmpcip);
  501. tmpcip = tmpcip - 2;
  502. tmport = workport + 0x10;
  503. outb(0x41, tmport);
  504. if (dev->dev_id == ATP885_DEVID) {
  505. tmport += 2;
  506. k = dev->id[c][target_id].last_len;
  507. outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
  508. outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
  509. outb((unsigned char) (((unsigned char *) (&k))[0]), tmport);
  510. dev->id[c][target_id].dirct = 0x00;
  511. tmport += 0x04;
  512. } else {
  513. dev->id[c][target_id].dirct = 0x00;
  514. tmport += 0x08;
  515. }
  516. outb(0x08, tmport);
  517. outb(0x09, tmpcip);
  518. dev->in_int[c] = 0;
  519. goto handled;
  520. }
  521. if (i == 0x08) {
  522. tmpcip += 4;
  523. outl(dev->id[c][target_id].prdaddr, tmpcip);
  524. tmpcip = tmpcip - 2;
  525. outb(0x06, tmpcip);
  526. outb(0x00, tmpcip);
  527. tmpcip = tmpcip - 2;
  528. tmport = workport + 0x10;
  529. outb(0x41, tmport);
  530. if (dev->dev_id == ATP885_DEVID) {
  531. tmport += 2;
  532. k = dev->id[c][target_id].last_len;
  533. outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
  534. outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
  535. outb((unsigned char) (((unsigned char *) (&k))[0]), tmport++);
  536. } else {
  537. tmport += 5;
  538. }
  539. outb((unsigned char) (inb(tmport) | 0x20), tmport);
  540. dev->id[c][target_id].dirct = 0x20;
  541. tmport += 0x03;
  542. outb(0x08, tmport);
  543. outb(0x01, tmpcip);
  544. dev->in_int[c] = 0;
  545. goto handled;
  546. }
  547. tmport -= 0x07;
  548. if (i == 0x0a) {
  549. outb(0x30, tmport);
  550. } else {
  551. outb(0x46, tmport);
  552. }
  553. dev->id[c][target_id].dirct = 0x00;
  554. tmport += 0x02;
  555. outb(0x00, tmport++);
  556. outb(0x00, tmport++);
  557. outb(0x00, tmport++);
  558. tmport += 0x03;
  559. outb(0x08, tmport);
  560. dev->in_int[c] = 0;
  561. goto handled;
  562. } else {
  563. // tmport = workport + 0x17;
  564. // inb(tmport);
  565. // dev->working[c] = 0;
  566. dev->in_int[c] = 0;
  567. goto handled;
  568. }
  569. handled:
  570. #ifdef ED_DBGP
  571. printk("atp870u_intr_handle exit\n");
  572. #endif
  573. return IRQ_HANDLED;
  574. }
  575. /**
  576. * atp870u_queuecommand - Queue SCSI command
  577. * @req_p: request block
  578. * @done: completion function
  579. *
  580. * Queue a command to the ATP queue. Called with the host lock held.
  581. */
  582. static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p,
  583. void (*done) (struct scsi_cmnd *))
  584. {
  585. unsigned char c;
  586. unsigned int tmport,m;
  587. struct atp_unit *dev;
  588. struct Scsi_Host *host;
  589. c = scmd_channel(req_p);
  590. req_p->sense_buffer[0]=0;
  591. scsi_set_resid(req_p, 0);
  592. if (scmd_channel(req_p) > 1) {
  593. req_p->result = 0x00040000;
  594. done(req_p);
  595. #ifdef ED_DBGP
  596. printk("atp870u_queuecommand : req_p->device->channel > 1\n");
  597. #endif
  598. return 0;
  599. }
  600. host = req_p->device->host;
  601. dev = (struct atp_unit *)&host->hostdata;
  602. m = 1;
  603. m = m << scmd_id(req_p);
  604. /*
  605. * Fake a timeout for missing targets
  606. */
  607. if ((m & dev->active_id[c]) == 0) {
  608. req_p->result = 0x00040000;
  609. done(req_p);
  610. return 0;
  611. }
  612. if (done) {
  613. req_p->scsi_done = done;
  614. } else {
  615. #ifdef ED_DBGP
  616. printk( "atp870u_queuecommand: done can't be NULL\n");
  617. #endif
  618. req_p->result = 0;
  619. done(req_p);
  620. return 0;
  621. }
  622. /*
  623. * Count new command
  624. */
  625. dev->quend[c]++;
  626. if (dev->quend[c] >= qcnt) {
  627. dev->quend[c] = 0;
  628. }
  629. /*
  630. * Check queue state
  631. */
  632. if (dev->quhd[c] == dev->quend[c]) {
  633. if (dev->quend[c] == 0) {
  634. dev->quend[c] = qcnt;
  635. }
  636. #ifdef ED_DBGP
  637. printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
  638. #endif
  639. dev->quend[c]--;
  640. req_p->result = 0x00020000;
  641. done(req_p);
  642. return 0;
  643. }
  644. dev->quereq[c][dev->quend[c]] = req_p;
  645. tmport = dev->ioport[c] + 0x1c;
  646. #ifdef ED_DBGP
  647. printk("dev->ioport[c] = %x inb(tmport) = %x dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",dev->ioport[c],inb(tmport),c,dev->in_int[c],c,dev->in_snd[c]);
  648. #endif
  649. if ((inb(tmport) == 0) && (dev->in_int[c] == 0) && (dev->in_snd[c] == 0)) {
  650. #ifdef ED_DBGP
  651. printk("Call sent_s870(atp870u_queuecommand)\n");
  652. #endif
  653. send_s870(dev,c);
  654. }
  655. #ifdef ED_DBGP
  656. printk("atp870u_queuecommand : exit\n");
  657. #endif
  658. return 0;
  659. }
  660. static DEF_SCSI_QCMD(atp870u_queuecommand)
  661. /**
  662. * send_s870 - send a command to the controller
  663. * @host: host
  664. *
  665. * On entry there is work queued to be done. We move some of that work to the
  666. * controller itself.
  667. *
  668. * Caller holds the host lock.
  669. */
  670. static void send_s870(struct atp_unit *dev,unsigned char c)
  671. {
  672. unsigned int tmport;
  673. struct scsi_cmnd *workreq;
  674. unsigned int i;//,k;
  675. unsigned char j, target_id;
  676. unsigned char *prd;
  677. unsigned short int tmpcip, w;
  678. unsigned long l, bttl = 0;
  679. unsigned int workport;
  680. unsigned long sg_count;
  681. if (dev->in_snd[c] != 0) {
  682. #ifdef ED_DBGP
  683. printk("cmnd in_snd\n");
  684. #endif
  685. return;
  686. }
  687. #ifdef ED_DBGP
  688. printk("Sent_s870 enter\n");
  689. #endif
  690. dev->in_snd[c] = 1;
  691. if ((dev->last_cmd[c] != 0xff) && ((dev->last_cmd[c] & 0x40) != 0)) {
  692. dev->last_cmd[c] &= 0x0f;
  693. workreq = dev->id[c][dev->last_cmd[c]].curr_req;
  694. if (workreq != NULL) { /* check NULL pointer */
  695. goto cmd_subp;
  696. }
  697. dev->last_cmd[c] = 0xff;
  698. if (dev->quhd[c] == dev->quend[c]) {
  699. dev->in_snd[c] = 0;
  700. return ;
  701. }
  702. }
  703. if ((dev->last_cmd[c] != 0xff) && (dev->working[c] != 0)) {
  704. dev->in_snd[c] = 0;
  705. return ;
  706. }
  707. dev->working[c]++;
  708. j = dev->quhd[c];
  709. dev->quhd[c]++;
  710. if (dev->quhd[c] >= qcnt) {
  711. dev->quhd[c] = 0;
  712. }
  713. workreq = dev->quereq[c][dev->quhd[c]];
  714. if (dev->id[c][scmd_id(workreq)].curr_req == NULL) {
  715. dev->id[c][scmd_id(workreq)].curr_req = workreq;
  716. dev->last_cmd[c] = scmd_id(workreq);
  717. goto cmd_subp;
  718. }
  719. dev->quhd[c] = j;
  720. dev->working[c]--;
  721. dev->in_snd[c] = 0;
  722. return;
  723. cmd_subp:
  724. workport = dev->ioport[c];
  725. tmport = workport + 0x1f;
  726. if ((inb(tmport) & 0xb0) != 0) {
  727. goto abortsnd;
  728. }
  729. tmport = workport + 0x1c;
  730. if (inb(tmport) == 0) {
  731. goto oktosend;
  732. }
  733. abortsnd:
  734. #ifdef ED_DBGP
  735. printk("Abort to Send\n");
  736. #endif
  737. dev->last_cmd[c] |= 0x40;
  738. dev->in_snd[c] = 0;
  739. return;
  740. oktosend:
  741. #ifdef ED_DBGP
  742. printk("OK to Send\n");
  743. scmd_printk(KERN_DEBUG, workreq, "CDB");
  744. for(i=0;i<workreq->cmd_len;i++) {
  745. printk(" %x",workreq->cmnd[i]);
  746. }
  747. printk("\n");
  748. #endif
  749. l = scsi_bufflen(workreq);
  750. if (dev->dev_id == ATP885_DEVID) {
  751. j = inb(dev->baseport + 0x29) & 0xfe;
  752. outb(j, dev->baseport + 0x29);
  753. dev->r1f[c][scmd_id(workreq)] = 0;
  754. }
  755. if (workreq->cmnd[0] == READ_CAPACITY) {
  756. if (l > 8)
  757. l = 8;
  758. }
  759. if (workreq->cmnd[0] == 0x00) {
  760. l = 0;
  761. }
  762. tmport = workport + 0x1b;
  763. j = 0;
  764. target_id = scmd_id(workreq);
  765. /*
  766. * Wide ?
  767. */
  768. w = 1;
  769. w = w << target_id;
  770. if ((w & dev->wide_id[c]) != 0) {
  771. j |= 0x01;
  772. }
  773. outb(j, tmport);
  774. while ((inb(tmport) & 0x01) != j) {
  775. outb(j,tmport);
  776. #ifdef ED_DBGP
  777. printk("send_s870 while loop 1\n");
  778. #endif
  779. }
  780. /*
  781. * Write the command
  782. */
  783. tmport = workport;
  784. outb(workreq->cmd_len, tmport++);
  785. outb(0x2c, tmport++);
  786. if (dev->dev_id == ATP885_DEVID) {
  787. outb(0x7f, tmport++);
  788. } else {
  789. outb(0xcf, tmport++);
  790. }
  791. for (i = 0; i < workreq->cmd_len; i++) {
  792. outb(workreq->cmnd[i], tmport++);
  793. }
  794. tmport = workport + 0x0f;
  795. outb(workreq->device->lun, tmport);
  796. tmport += 0x02;
  797. /*
  798. * Write the target
  799. */
  800. outb(dev->id[c][target_id].devsp, tmport++);
  801. #ifdef ED_DBGP
  802. printk("dev->id[%d][%d].devsp = %2x\n",c,target_id,dev->id[c][target_id].devsp);
  803. #endif
  804. sg_count = scsi_dma_map(workreq);
  805. /*
  806. * Write transfer size
  807. */
  808. outb((unsigned char) (((unsigned char *) (&l))[2]), tmport++);
  809. outb((unsigned char) (((unsigned char *) (&l))[1]), tmport++);
  810. outb((unsigned char) (((unsigned char *) (&l))[0]), tmport++);
  811. j = target_id;
  812. dev->id[c][j].last_len = l;
  813. dev->id[c][j].tran_len = 0;
  814. #ifdef ED_DBGP
  815. printk("dev->id[%2d][%2d].last_len = %d\n",c,j,dev->id[c][j].last_len);
  816. #endif
  817. /*
  818. * Flip the wide bits
  819. */
  820. if ((j & 0x08) != 0) {
  821. j = (j & 0x07) | 0x40;
  822. }
  823. /*
  824. * Check transfer direction
  825. */
  826. if (workreq->sc_data_direction == DMA_TO_DEVICE) {
  827. outb((unsigned char) (j | 0x20), tmport++);
  828. } else {
  829. outb(j, tmport++);
  830. }
  831. outb((unsigned char) (inb(tmport) | 0x80), tmport);
  832. outb(0x80, tmport);
  833. tmport = workport + 0x1c;
  834. dev->id[c][target_id].dirct = 0;
  835. if (l == 0) {
  836. if (inb(tmport) == 0) {
  837. tmport = workport + 0x18;
  838. #ifdef ED_DBGP
  839. printk("change SCSI_CMD_REG 0x08\n");
  840. #endif
  841. outb(0x08, tmport);
  842. } else {
  843. dev->last_cmd[c] |= 0x40;
  844. }
  845. dev->in_snd[c] = 0;
  846. return;
  847. }
  848. tmpcip = dev->pciport[c];
  849. prd = dev->id[c][target_id].prd_table;
  850. dev->id[c][target_id].prd_pos = prd;
  851. /*
  852. * Now write the request list. Either as scatter/gather or as
  853. * a linear chain.
  854. */
  855. if (l) {
  856. struct scatterlist *sgpnt;
  857. i = 0;
  858. scsi_for_each_sg(workreq, sgpnt, sg_count, j) {
  859. bttl = sg_dma_address(sgpnt);
  860. l=sg_dma_len(sgpnt);
  861. #ifdef ED_DBGP
  862. printk("1. bttl %x, l %x\n",bttl, l);
  863. #endif
  864. while (l > 0x10000) {
  865. (((u16 *) (prd))[i + 3]) = 0x0000;
  866. (((u16 *) (prd))[i + 2]) = 0x0000;
  867. (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
  868. l -= 0x10000;
  869. bttl += 0x10000;
  870. i += 0x04;
  871. }
  872. (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
  873. (((u16 *) (prd))[i + 2]) = cpu_to_le16(l);
  874. (((u16 *) (prd))[i + 3]) = 0;
  875. i += 0x04;
  876. }
  877. (((u16 *) (prd))[i - 1]) = cpu_to_le16(0x8000);
  878. #ifdef ED_DBGP
  879. printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd)[0]),(((unsigned short int *)prd)[1]),(((unsigned short int *)prd)[2]),(((unsigned short int *)prd)[3]));
  880. printk("2. bttl %x, l %x\n",bttl, l);
  881. #endif
  882. }
  883. tmpcip += 4;
  884. #ifdef ED_DBGP
  885. printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev->id[c][target_id].prdaddr,tmpcip,target_id);
  886. #endif
  887. dev->id[c][target_id].prdaddr = dev->id[c][target_id].prd_bus;
  888. outl(dev->id[c][target_id].prdaddr, tmpcip);
  889. tmpcip = tmpcip - 2;
  890. outb(0x06, tmpcip);
  891. outb(0x00, tmpcip);
  892. if (dev->dev_id == ATP885_DEVID) {
  893. tmpcip--;
  894. j=inb(tmpcip) & 0xf3;
  895. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) ||
  896. (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  897. j |= 0x0c;
  898. }
  899. outb(j,tmpcip);
  900. tmpcip--;
  901. } else if ((dev->dev_id == ATP880_DEVID1) ||
  902. (dev->dev_id == ATP880_DEVID2)) {
  903. tmpcip =tmpcip -2;
  904. tmport = workport - 0x05;
  905. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  906. outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
  907. } else {
  908. outb((unsigned char) (inb(tmport) & 0x3f), tmport);
  909. }
  910. } else {
  911. tmpcip =tmpcip -2;
  912. tmport = workport + 0x3a;
  913. if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
  914. outb((inb(tmport) & 0xf3) | 0x08, tmport);
  915. } else {
  916. outb(inb(tmport) & 0xf3, tmport);
  917. }
  918. }
  919. tmport = workport + 0x1c;
  920. if(workreq->sc_data_direction == DMA_TO_DEVICE) {
  921. dev->id[c][target_id].dirct = 0x20;
  922. if (inb(tmport) == 0) {
  923. tmport = workport + 0x18;
  924. outb(0x08, tmport);
  925. outb(0x01, tmpcip);
  926. #ifdef ED_DBGP
  927. printk( "start DMA(to target)\n");
  928. #endif
  929. } else {
  930. dev->last_cmd[c] |= 0x40;
  931. }
  932. dev->in_snd[c] = 0;
  933. return;
  934. }
  935. if (inb(tmport) == 0) {
  936. tmport = workport + 0x18;
  937. outb(0x08, tmport);
  938. outb(0x09, tmpcip);
  939. #ifdef ED_DBGP
  940. printk( "start DMA(to host)\n");
  941. #endif
  942. } else {
  943. dev->last_cmd[c] |= 0x40;
  944. }
  945. dev->in_snd[c] = 0;
  946. return;
  947. }
  948. static unsigned char fun_scam(struct atp_unit *dev, unsigned short int *val)
  949. {
  950. unsigned int tmport;
  951. unsigned short int i, k;
  952. unsigned char j;
  953. tmport = dev->ioport[0] + 0x1c;
  954. outw(*val, tmport);
  955. FUN_D7:
  956. for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
  957. k = inw(tmport);
  958. j = (unsigned char) (k >> 8);
  959. if ((k & 0x8000) != 0) { /* DB7 all release? */
  960. goto FUN_D7;
  961. }
  962. }
  963. *val |= 0x4000; /* assert DB6 */
  964. outw(*val, tmport);
  965. *val &= 0xdfff; /* assert DB5 */
  966. outw(*val, tmport);
  967. FUN_D5:
  968. for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
  969. if ((inw(tmport) & 0x2000) != 0) { /* DB5 all release? */
  970. goto FUN_D5;
  971. }
  972. }
  973. *val |= 0x8000; /* no DB4-0, assert DB7 */
  974. *val &= 0xe0ff;
  975. outw(*val, tmport);
  976. *val &= 0xbfff; /* release DB6 */
  977. outw(*val, tmport);
  978. FUN_D6:
  979. for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
  980. if ((inw(tmport) & 0x4000) != 0) { /* DB6 all release? */
  981. goto FUN_D6;
  982. }
  983. }
  984. return j;
  985. }
  986. static void tscam(struct Scsi_Host *host)
  987. {
  988. unsigned int tmport;
  989. unsigned char i, j, k;
  990. unsigned long n;
  991. unsigned short int m, assignid_map, val;
  992. unsigned char mbuf[33], quintet[2];
  993. struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
  994. static unsigned char g2q_tab[8] = {
  995. 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
  996. };
  997. /* I can't believe we need this before we've even done anything. Remove it
  998. * and see if anyone bitches.
  999. for (i = 0; i < 0x10; i++) {
  1000. udelay(0xffff);
  1001. }
  1002. */
  1003. tmport = dev->ioport[0] + 1;
  1004. outb(0x08, tmport++);
  1005. outb(0x7f, tmport);
  1006. tmport = dev->ioport[0] + 0x11;
  1007. outb(0x20, tmport);
  1008. if ((dev->scam_on & 0x40) == 0) {
  1009. return;
  1010. }
  1011. m = 1;
  1012. m <<= dev->host_id[0];
  1013. j = 16;
  1014. if (dev->chip_ver < 4) {
  1015. m |= 0xff00;
  1016. j = 8;
  1017. }
  1018. assignid_map = m;
  1019. tmport = dev->ioport[0] + 0x02;
  1020. outb(0x02, tmport++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
  1021. outb(0, tmport++);
  1022. outb(0, tmport++);
  1023. outb(0, tmport++);
  1024. outb(0, tmport++);
  1025. outb(0, tmport++);
  1026. outb(0, tmport++);
  1027. for (i = 0; i < j; i++) {
  1028. m = 1;
  1029. m = m << i;
  1030. if ((m & assignid_map) != 0) {
  1031. continue;
  1032. }
  1033. tmport = dev->ioport[0] + 0x0f;
  1034. outb(0, tmport++);
  1035. tmport += 0x02;
  1036. outb(0, tmport++);
  1037. outb(0, tmport++);
  1038. outb(0, tmport++);
  1039. if (i > 7) {
  1040. k = (i & 0x07) | 0x40;
  1041. } else {
  1042. k = i;
  1043. }
  1044. outb(k, tmport++);
  1045. tmport = dev->ioport[0] + 0x1b;
  1046. if (dev->chip_ver == 4) {
  1047. outb(0x01, tmport);
  1048. } else {
  1049. outb(0x00, tmport);
  1050. }
  1051. wait_rdyok:
  1052. tmport = dev->ioport[0] + 0x18;
  1053. outb(0x09, tmport);
  1054. tmport += 0x07;
  1055. while ((inb(tmport) & 0x80) == 0x00)
  1056. cpu_relax();
  1057. tmport -= 0x08;
  1058. k = inb(tmport);
  1059. if (k != 0x16) {
  1060. if ((k == 0x85) || (k == 0x42)) {
  1061. continue;
  1062. }
  1063. tmport = dev->ioport[0] + 0x10;
  1064. outb(0x41, tmport);
  1065. goto wait_rdyok;
  1066. }
  1067. assignid_map |= m;
  1068. }
  1069. tmport = dev->ioport[0] + 0x02;
  1070. outb(0x7f, tmport);
  1071. tmport = dev->ioport[0] + 0x1b;
  1072. outb(0x02, tmport);
  1073. outb(0, 0x80);
  1074. val = 0x0080; /* bsy */
  1075. tmport = dev->ioport[0] + 0x1c;
  1076. outw(val, tmport);
  1077. val |= 0x0040; /* sel */
  1078. outw(val, tmport);
  1079. val |= 0x0004; /* msg */
  1080. outw(val, tmport);
  1081. inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
  1082. val &= 0x007f; /* no bsy */
  1083. outw(val, tmport);
  1084. mdelay(128);
  1085. val &= 0x00fb; /* after 1ms no msg */
  1086. outw(val, tmport);
  1087. wait_nomsg:
  1088. if ((inb(tmport) & 0x04) != 0) {
  1089. goto wait_nomsg;
  1090. }
  1091. outb(1, 0x80);
  1092. udelay(100);
  1093. for (n = 0; n < 0x30000; n++) {
  1094. if ((inb(tmport) & 0x80) != 0) { /* bsy ? */
  1095. goto wait_io;
  1096. }
  1097. }
  1098. goto TCM_SYNC;
  1099. wait_io:
  1100. for (n = 0; n < 0x30000; n++) {
  1101. if ((inb(tmport) & 0x81) == 0x0081) {
  1102. goto wait_io1;
  1103. }
  1104. }
  1105. goto TCM_SYNC;
  1106. wait_io1:
  1107. inb(0x80);
  1108. val |= 0x8003; /* io,cd,db7 */
  1109. outw(val, tmport);
  1110. inb(0x80);
  1111. val &= 0x00bf; /* no sel */
  1112. outw(val, tmport);
  1113. outb(2, 0x80);
  1114. TCM_SYNC:
  1115. /*
  1116. * The funny division into multiple delays is to accomodate
  1117. * arches like ARM where udelay() multiplies its argument by
  1118. * a large number to initialize a loop counter. To avoid
  1119. * overflow, the maximum supported udelay is 2000 microseconds.
  1120. *
  1121. * XXX it would be more polite to find a way to use msleep()
  1122. */
  1123. mdelay(2);
  1124. udelay(48);
  1125. if ((inb(tmport) & 0x80) == 0x00) { /* bsy ? */
  1126. outw(0, tmport--);
  1127. outb(0, tmport);
  1128. tmport = dev->ioport[0] + 0x15;
  1129. outb(0, tmport);
  1130. tmport += 0x03;
  1131. outb(0x09, tmport);
  1132. tmport += 0x07;
  1133. while ((inb(tmport) & 0x80) == 0)
  1134. cpu_relax();
  1135. tmport -= 0x08;
  1136. inb(tmport);
  1137. return;
  1138. }
  1139. val &= 0x00ff; /* synchronization */
  1140. val |= 0x3f00;
  1141. fun_scam(dev, &val);
  1142. outb(3, 0x80);
  1143. val &= 0x00ff; /* isolation */
  1144. val |= 0x2000;
  1145. fun_scam(dev, &val);
  1146. outb(4, 0x80);
  1147. i = 8;
  1148. j = 0;
  1149. TCM_ID:
  1150. if ((inw(tmport) & 0x2000) == 0) {
  1151. goto TCM_ID;
  1152. }
  1153. outb(5, 0x80);
  1154. val &= 0x00ff; /* get ID_STRING */
  1155. val |= 0x2000;
  1156. k = fun_scam(dev, &val);
  1157. if ((k & 0x03) == 0) {
  1158. goto TCM_5;
  1159. }
  1160. mbuf[j] <<= 0x01;
  1161. mbuf[j] &= 0xfe;
  1162. if ((k & 0x02) != 0) {
  1163. mbuf[j] |= 0x01;
  1164. }
  1165. i--;
  1166. if (i > 0) {
  1167. goto TCM_ID;
  1168. }
  1169. j++;
  1170. i = 8;
  1171. goto TCM_ID;
  1172. TCM_5: /* isolation complete.. */
  1173. /* mbuf[32]=0;
  1174. printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
  1175. i = 15;
  1176. j = mbuf[0];
  1177. if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */
  1178. i = 7;
  1179. }
  1180. if ((j & 0x06) == 0) { /* IDvalid? */
  1181. goto G2Q5;
  1182. }
  1183. k = mbuf[1];
  1184. small_id:
  1185. m = 1;
  1186. m <<= k;
  1187. if ((m & assignid_map) == 0) {
  1188. goto G2Q_QUIN;
  1189. }
  1190. if (k > 0) {
  1191. k--;
  1192. goto small_id;
  1193. }
  1194. G2Q5: /* srch from max acceptable ID# */
  1195. k = i; /* max acceptable ID# */
  1196. G2Q_LP:
  1197. m = 1;
  1198. m <<= k;
  1199. if ((m & assignid_map) == 0) {
  1200. goto G2Q_QUIN;
  1201. }
  1202. if (k > 0) {
  1203. k--;
  1204. goto G2Q_LP;
  1205. }
  1206. G2Q_QUIN: /* k=binID#, */
  1207. assignid_map |= m;
  1208. if (k < 8) {
  1209. quintet[0] = 0x38; /* 1st dft ID<8 */
  1210. } else {
  1211. quintet[0] = 0x31; /* 1st ID>=8 */
  1212. }
  1213. k &= 0x07;
  1214. quintet[1] = g2q_tab[k];
  1215. val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
  1216. m = quintet[0] << 8;
  1217. val |= m;
  1218. fun_scam(dev, &val);
  1219. val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
  1220. m = quintet[1] << 8;
  1221. val |= m;
  1222. fun_scam(dev, &val);
  1223. goto TCM_SYNC;
  1224. }
  1225. static void is870(struct atp_unit *dev, unsigned int wkport)
  1226. {
  1227. unsigned int tmport;
  1228. unsigned char i, j, k, rmb, n;
  1229. unsigned short int m;
  1230. static unsigned char mbuf[512];
  1231. static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
  1232. static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
  1233. static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1234. static unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
  1235. static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
  1236. static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
  1237. tmport = wkport + 0x3a;
  1238. outb((unsigned char) (inb(tmport) | 0x10), tmport);
  1239. for (i = 0; i < 16; i++) {
  1240. if ((dev->chip_ver != 4) && (i > 7)) {
  1241. break;
  1242. }
  1243. m = 1;
  1244. m = m << i;
  1245. if ((m & dev->active_id[0]) != 0) {
  1246. continue;
  1247. }
  1248. if (i == dev->host_id[0]) {
  1249. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
  1250. continue;
  1251. }
  1252. tmport = wkport + 0x1b;
  1253. if (dev->chip_ver == 4) {
  1254. outb(0x01, tmport);
  1255. } else {
  1256. outb(0x00, tmport);
  1257. }
  1258. tmport = wkport + 1;
  1259. outb(0x08, tmport++);
  1260. outb(0x7f, tmport++);
  1261. outb(satn[0], tmport++);
  1262. outb(satn[1], tmport++);
  1263. outb(satn[2], tmport++);
  1264. outb(satn[3], tmport++);
  1265. outb(satn[4], tmport++);
  1266. outb(satn[5], tmport++);
  1267. tmport += 0x06;
  1268. outb(0, tmport);
  1269. tmport += 0x02;
  1270. outb(dev->id[0][i].devsp, tmport++);
  1271. outb(0, tmport++);
  1272. outb(satn[6], tmport++);
  1273. outb(satn[7], tmport++);
  1274. j = i;
  1275. if ((j & 0x08) != 0) {
  1276. j = (j & 0x07) | 0x40;
  1277. }
  1278. outb(j, tmport);
  1279. tmport += 0x03;
  1280. outb(satn[8], tmport);
  1281. tmport += 0x07;
  1282. while ((inb(tmport) & 0x80) == 0x00)
  1283. cpu_relax();
  1284. tmport -= 0x08;
  1285. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1286. continue;
  1287. while (inb(tmport) != 0x8e)
  1288. cpu_relax();
  1289. dev->active_id[0] |= m;
  1290. tmport = wkport + 0x10;
  1291. outb(0x30, tmport);
  1292. tmport = wkport + 0x04;
  1293. outb(0x00, tmport);
  1294. phase_cmd:
  1295. tmport = wkport + 0x18;
  1296. outb(0x08, tmport);
  1297. tmport += 0x07;
  1298. while ((inb(tmport) & 0x80) == 0x00)
  1299. cpu_relax();
  1300. tmport -= 0x08;
  1301. j = inb(tmport);
  1302. if (j != 0x16) {
  1303. tmport = wkport + 0x10;
  1304. outb(0x41, tmport);
  1305. goto phase_cmd;
  1306. }
  1307. sel_ok:
  1308. tmport = wkport + 3;
  1309. outb(inqd[0], tmport++);
  1310. outb(inqd[1], tmport++);
  1311. outb(inqd[2], tmport++);
  1312. outb(inqd[3], tmport++);
  1313. outb(inqd[4], tmport++);
  1314. outb(inqd[5], tmport);
  1315. tmport += 0x07;
  1316. outb(0, tmport);
  1317. tmport += 0x02;
  1318. outb(dev->id[0][i].devsp, tmport++);
  1319. outb(0, tmport++);
  1320. outb(inqd[6], tmport++);
  1321. outb(inqd[7], tmport++);
  1322. tmport += 0x03;
  1323. outb(inqd[8], tmport);
  1324. tmport += 0x07;
  1325. while ((inb(tmport) & 0x80) == 0x00)
  1326. cpu_relax();
  1327. tmport -= 0x08;
  1328. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1329. continue;
  1330. while (inb(tmport) != 0x8e)
  1331. cpu_relax();
  1332. tmport = wkport + 0x1b;
  1333. if (dev->chip_ver == 4)
  1334. outb(0x00, tmport);
  1335. tmport = wkport + 0x18;
  1336. outb(0x08, tmport);
  1337. tmport += 0x07;
  1338. j = 0;
  1339. rd_inq_data:
  1340. k = inb(tmport);
  1341. if ((k & 0x01) != 0) {
  1342. tmport -= 0x06;
  1343. mbuf[j++] = inb(tmport);
  1344. tmport += 0x06;
  1345. goto rd_inq_data;
  1346. }
  1347. if ((k & 0x80) == 0) {
  1348. goto rd_inq_data;
  1349. }
  1350. tmport -= 0x08;
  1351. j = inb(tmport);
  1352. if (j == 0x16) {
  1353. goto inq_ok;
  1354. }
  1355. tmport = wkport + 0x10;
  1356. outb(0x46, tmport);
  1357. tmport += 0x02;
  1358. outb(0, tmport++);
  1359. outb(0, tmport++);
  1360. outb(0, tmport++);
  1361. tmport += 0x03;
  1362. outb(0x08, tmport);
  1363. tmport += 0x07;
  1364. while ((inb(tmport) & 0x80) == 0x00)
  1365. cpu_relax();
  1366. tmport -= 0x08;
  1367. if (inb(tmport) != 0x16) {
  1368. goto sel_ok;
  1369. }
  1370. inq_ok:
  1371. mbuf[36] = 0;
  1372. printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
  1373. dev->id[0][i].devtype = mbuf[0];
  1374. rmb = mbuf[1];
  1375. n = mbuf[7];
  1376. if (dev->chip_ver != 4) {
  1377. goto not_wide;
  1378. }
  1379. if ((mbuf[7] & 0x60) == 0) {
  1380. goto not_wide;
  1381. }
  1382. if ((dev->global_map[0] & 0x20) == 0) {
  1383. goto not_wide;
  1384. }
  1385. tmport = wkport + 0x1b;
  1386. outb(0x01, tmport);
  1387. tmport = wkport + 3;
  1388. outb(satn[0], tmport++);
  1389. outb(satn[1], tmport++);
  1390. outb(satn[2], tmport++);
  1391. outb(satn[3], tmport++);
  1392. outb(satn[4], tmport++);
  1393. outb(satn[5], tmport++);
  1394. tmport += 0x06;
  1395. outb(0, tmport);
  1396. tmport += 0x02;
  1397. outb(dev->id[0][i].devsp, tmport++);
  1398. outb(0, tmport++);
  1399. outb(satn[6], tmport++);
  1400. outb(satn[7], tmport++);
  1401. tmport += 0x03;
  1402. outb(satn[8], tmport);
  1403. tmport += 0x07;
  1404. while ((inb(tmport) & 0x80) == 0x00)
  1405. cpu_relax();
  1406. tmport -= 0x08;
  1407. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1408. continue;
  1409. while (inb(tmport) != 0x8e)
  1410. cpu_relax();
  1411. try_wide:
  1412. j = 0;
  1413. tmport = wkport + 0x14;
  1414. outb(0x05, tmport);
  1415. tmport += 0x04;
  1416. outb(0x20, tmport);
  1417. tmport += 0x07;
  1418. while ((inb(tmport) & 0x80) == 0) {
  1419. if ((inb(tmport) & 0x01) != 0) {
  1420. tmport -= 0x06;
  1421. outb(wide[j++], tmport);
  1422. tmport += 0x06;
  1423. }
  1424. }
  1425. tmport -= 0x08;
  1426. while ((inb(tmport) & 0x80) == 0x00)
  1427. cpu_relax();
  1428. j = inb(tmport) & 0x0f;
  1429. if (j == 0x0f) {
  1430. goto widep_in;
  1431. }
  1432. if (j == 0x0a) {
  1433. goto widep_cmd;
  1434. }
  1435. if (j == 0x0e) {
  1436. goto try_wide;
  1437. }
  1438. continue;
  1439. widep_out:
  1440. tmport = wkport + 0x18;
  1441. outb(0x20, tmport);
  1442. tmport += 0x07;
  1443. while ((inb(tmport) & 0x80) == 0) {
  1444. if ((inb(tmport) & 0x01) != 0) {
  1445. tmport -= 0x06;
  1446. outb(0, tmport);
  1447. tmport += 0x06;
  1448. }
  1449. }
  1450. tmport -= 0x08;
  1451. j = inb(tmport) & 0x0f;
  1452. if (j == 0x0f) {
  1453. goto widep_in;
  1454. }
  1455. if (j == 0x0a) {
  1456. goto widep_cmd;
  1457. }
  1458. if (j == 0x0e) {
  1459. goto widep_out;
  1460. }
  1461. continue;
  1462. widep_in:
  1463. tmport = wkport + 0x14;
  1464. outb(0xff, tmport);
  1465. tmport += 0x04;
  1466. outb(0x20, tmport);
  1467. tmport += 0x07;
  1468. k = 0;
  1469. widep_in1:
  1470. j = inb(tmport);
  1471. if ((j & 0x01) != 0) {
  1472. tmport -= 0x06;
  1473. mbuf[k++] = inb(tmport);
  1474. tmport += 0x06;
  1475. goto widep_in1;
  1476. }
  1477. if ((j & 0x80) == 0x00) {
  1478. goto widep_in1;
  1479. }
  1480. tmport -= 0x08;
  1481. j = inb(tmport) & 0x0f;
  1482. if (j == 0x0f) {
  1483. goto widep_in;
  1484. }
  1485. if (j == 0x0a) {
  1486. goto widep_cmd;
  1487. }
  1488. if (j == 0x0e) {
  1489. goto widep_out;
  1490. }
  1491. continue;
  1492. widep_cmd:
  1493. tmport = wkport + 0x10;
  1494. outb(0x30, tmport);
  1495. tmport = wkport + 0x14;
  1496. outb(0x00, tmport);
  1497. tmport += 0x04;
  1498. outb(0x08, tmport);
  1499. tmport += 0x07;
  1500. while ((inb(tmport) & 0x80) == 0x00)
  1501. cpu_relax();
  1502. tmport -= 0x08;
  1503. j = inb(tmport);
  1504. if (j != 0x16) {
  1505. if (j == 0x4e) {
  1506. goto widep_out;
  1507. }
  1508. continue;
  1509. }
  1510. if (mbuf[0] != 0x01) {
  1511. goto not_wide;
  1512. }
  1513. if (mbuf[1] != 0x02) {
  1514. goto not_wide;
  1515. }
  1516. if (mbuf[2] != 0x03) {
  1517. goto not_wide;
  1518. }
  1519. if (mbuf[3] != 0x01) {
  1520. goto not_wide;
  1521. }
  1522. m = 1;
  1523. m = m << i;
  1524. dev->wide_id[0] |= m;
  1525. not_wide:
  1526. if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  1527. goto set_sync;
  1528. }
  1529. continue;
  1530. set_sync:
  1531. tmport = wkport + 0x1b;
  1532. j = 0;
  1533. if ((m & dev->wide_id[0]) != 0) {
  1534. j |= 0x01;
  1535. }
  1536. outb(j, tmport);
  1537. tmport = wkport + 3;
  1538. outb(satn[0], tmport++);
  1539. outb(satn[1], tmport++);
  1540. outb(satn[2], tmport++);
  1541. outb(satn[3], tmport++);
  1542. outb(satn[4], tmport++);
  1543. outb(satn[5], tmport++);
  1544. tmport += 0x06;
  1545. outb(0, tmport);
  1546. tmport += 0x02;
  1547. outb(dev->id[0][i].devsp, tmport++);
  1548. outb(0, tmport++);
  1549. outb(satn[6], tmport++);
  1550. outb(satn[7], tmport++);
  1551. tmport += 0x03;
  1552. outb(satn[8], tmport);
  1553. tmport += 0x07;
  1554. while ((inb(tmport) & 0x80) == 0x00)
  1555. cpu_relax();
  1556. tmport -= 0x08;
  1557. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1558. continue;
  1559. while (inb(tmport) != 0x8e)
  1560. cpu_relax();
  1561. try_sync:
  1562. j = 0;
  1563. tmport = wkport + 0x14;
  1564. outb(0x06, tmport);
  1565. tmport += 0x04;
  1566. outb(0x20, tmport);
  1567. tmport += 0x07;
  1568. while ((inb(tmport) & 0x80) == 0) {
  1569. if ((inb(tmport) & 0x01) != 0) {
  1570. tmport -= 0x06;
  1571. if ((m & dev->wide_id[0]) != 0) {
  1572. outb(synw[j++], tmport);
  1573. } else {
  1574. if ((m & dev->ultra_map[0]) != 0) {
  1575. outb(synu[j++], tmport);
  1576. } else {
  1577. outb(synn[j++], tmport);
  1578. }
  1579. }
  1580. tmport += 0x06;
  1581. }
  1582. }
  1583. tmport -= 0x08;
  1584. while ((inb(tmport) & 0x80) == 0x00)
  1585. cpu_relax();
  1586. j = inb(tmport) & 0x0f;
  1587. if (j == 0x0f) {
  1588. goto phase_ins;
  1589. }
  1590. if (j == 0x0a) {
  1591. goto phase_cmds;
  1592. }
  1593. if (j == 0x0e) {
  1594. goto try_sync;
  1595. }
  1596. continue;
  1597. phase_outs:
  1598. tmport = wkport + 0x18;
  1599. outb(0x20, tmport);
  1600. tmport += 0x07;
  1601. while ((inb(tmport) & 0x80) == 0x00) {
  1602. if ((inb(tmport) & 0x01) != 0x00) {
  1603. tmport -= 0x06;
  1604. outb(0x00, tmport);
  1605. tmport += 0x06;
  1606. }
  1607. }
  1608. tmport -= 0x08;
  1609. j = inb(tmport);
  1610. if (j == 0x85) {
  1611. goto tar_dcons;
  1612. }
  1613. j &= 0x0f;
  1614. if (j == 0x0f) {
  1615. goto phase_ins;
  1616. }
  1617. if (j == 0x0a) {
  1618. goto phase_cmds;
  1619. }
  1620. if (j == 0x0e) {
  1621. goto phase_outs;
  1622. }
  1623. continue;
  1624. phase_ins:
  1625. tmport = wkport + 0x14;
  1626. outb(0xff, tmport);
  1627. tmport += 0x04;
  1628. outb(0x20, tmport);
  1629. tmport += 0x07;
  1630. k = 0;
  1631. phase_ins1:
  1632. j = inb(tmport);
  1633. if ((j & 0x01) != 0x00) {
  1634. tmport -= 0x06;
  1635. mbuf[k++] = inb(tmport);
  1636. tmport += 0x06;
  1637. goto phase_ins1;
  1638. }
  1639. if ((j & 0x80) == 0x00) {
  1640. goto phase_ins1;
  1641. }
  1642. tmport -= 0x08;
  1643. while ((inb(tmport) & 0x80) == 0x00)
  1644. cpu_relax();
  1645. j = inb(tmport);
  1646. if (j == 0x85) {
  1647. goto tar_dcons;
  1648. }
  1649. j &= 0x0f;
  1650. if (j == 0x0f) {
  1651. goto phase_ins;
  1652. }
  1653. if (j == 0x0a) {
  1654. goto phase_cmds;
  1655. }
  1656. if (j == 0x0e) {
  1657. goto phase_outs;
  1658. }
  1659. continue;
  1660. phase_cmds:
  1661. tmport = wkport + 0x10;
  1662. outb(0x30, tmport);
  1663. tar_dcons:
  1664. tmport = wkport + 0x14;
  1665. outb(0x00, tmport);
  1666. tmport += 0x04;
  1667. outb(0x08, tmport);
  1668. tmport += 0x07;
  1669. while ((inb(tmport) & 0x80) == 0x00)
  1670. cpu_relax();
  1671. tmport -= 0x08;
  1672. j = inb(tmport);
  1673. if (j != 0x16) {
  1674. continue;
  1675. }
  1676. if (mbuf[0] != 0x01) {
  1677. continue;
  1678. }
  1679. if (mbuf[1] != 0x03) {
  1680. continue;
  1681. }
  1682. if (mbuf[4] == 0x00) {
  1683. continue;
  1684. }
  1685. if (mbuf[3] > 0x64) {
  1686. continue;
  1687. }
  1688. if (mbuf[4] > 0x0c) {
  1689. mbuf[4] = 0x0c;
  1690. }
  1691. dev->id[0][i].devsp = mbuf[4];
  1692. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  1693. j = 0xa0;
  1694. goto set_syn_ok;
  1695. }
  1696. if (mbuf[3] < 0x1a) {
  1697. j = 0x20;
  1698. goto set_syn_ok;
  1699. }
  1700. if (mbuf[3] < 0x33) {
  1701. j = 0x40;
  1702. goto set_syn_ok;
  1703. }
  1704. if (mbuf[3] < 0x4c) {
  1705. j = 0x50;
  1706. goto set_syn_ok;
  1707. }
  1708. j = 0x60;
  1709. set_syn_ok:
  1710. dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
  1711. }
  1712. tmport = wkport + 0x3a;
  1713. outb((unsigned char) (inb(tmport) & 0xef), tmport);
  1714. }
  1715. static void is880(struct atp_unit *dev, unsigned int wkport)
  1716. {
  1717. unsigned int tmport;
  1718. unsigned char i, j, k, rmb, n, lvdmode;
  1719. unsigned short int m;
  1720. static unsigned char mbuf[512];
  1721. static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
  1722. static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
  1723. static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1724. unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
  1725. static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1726. unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
  1727. static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
  1728. static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
  1729. lvdmode = inb(wkport + 0x3f) & 0x40;
  1730. for (i = 0; i < 16; i++) {
  1731. m = 1;
  1732. m = m << i;
  1733. if ((m & dev->active_id[0]) != 0) {
  1734. continue;
  1735. }
  1736. if (i == dev->host_id[0]) {
  1737. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
  1738. continue;
  1739. }
  1740. tmport = wkport + 0x5b;
  1741. outb(0x01, tmport);
  1742. tmport = wkport + 0x41;
  1743. outb(0x08, tmport++);
  1744. outb(0x7f, tmport++);
  1745. outb(satn[0], tmport++);
  1746. outb(satn[1], tmport++);
  1747. outb(satn[2], tmport++);
  1748. outb(satn[3], tmport++);
  1749. outb(satn[4], tmport++);
  1750. outb(satn[5], tmport++);
  1751. tmport += 0x06;
  1752. outb(0, tmport);
  1753. tmport += 0x02;
  1754. outb(dev->id[0][i].devsp, tmport++);
  1755. outb(0, tmport++);
  1756. outb(satn[6], tmport++);
  1757. outb(satn[7], tmport++);
  1758. j = i;
  1759. if ((j & 0x08) != 0) {
  1760. j = (j & 0x07) | 0x40;
  1761. }
  1762. outb(j, tmport);
  1763. tmport += 0x03;
  1764. outb(satn[8], tmport);
  1765. tmport += 0x07;
  1766. while ((inb(tmport) & 0x80) == 0x00)
  1767. cpu_relax();
  1768. tmport -= 0x08;
  1769. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1770. continue;
  1771. while (inb(tmport) != 0x8e)
  1772. cpu_relax();
  1773. dev->active_id[0] |= m;
  1774. tmport = wkport + 0x50;
  1775. outb(0x30, tmport);
  1776. tmport = wkport + 0x54;
  1777. outb(0x00, tmport);
  1778. phase_cmd:
  1779. tmport = wkport + 0x58;
  1780. outb(0x08, tmport);
  1781. tmport += 0x07;
  1782. while ((inb(tmport) & 0x80) == 0x00)
  1783. cpu_relax();
  1784. tmport -= 0x08;
  1785. j = inb(tmport);
  1786. if (j != 0x16) {
  1787. tmport = wkport + 0x50;
  1788. outb(0x41, tmport);
  1789. goto phase_cmd;
  1790. }
  1791. sel_ok:
  1792. tmport = wkport + 0x43;
  1793. outb(inqd[0], tmport++);
  1794. outb(inqd[1], tmport++);
  1795. outb(inqd[2], tmport++);
  1796. outb(inqd[3], tmport++);
  1797. outb(inqd[4], tmport++);
  1798. outb(inqd[5], tmport);
  1799. tmport += 0x07;
  1800. outb(0, tmport);
  1801. tmport += 0x02;
  1802. outb(dev->id[0][i].devsp, tmport++);
  1803. outb(0, tmport++);
  1804. outb(inqd[6], tmport++);
  1805. outb(inqd[7], tmport++);
  1806. tmport += 0x03;
  1807. outb(inqd[8], tmport);
  1808. tmport += 0x07;
  1809. while ((inb(tmport) & 0x80) == 0x00)
  1810. cpu_relax();
  1811. tmport -= 0x08;
  1812. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1813. continue;
  1814. while (inb(tmport) != 0x8e)
  1815. cpu_relax();
  1816. tmport = wkport + 0x5b;
  1817. outb(0x00, tmport);
  1818. tmport = wkport + 0x58;
  1819. outb(0x08, tmport);
  1820. tmport += 0x07;
  1821. j = 0;
  1822. rd_inq_data:
  1823. k = inb(tmport);
  1824. if ((k & 0x01) != 0) {
  1825. tmport -= 0x06;
  1826. mbuf[j++] = inb(tmport);
  1827. tmport += 0x06;
  1828. goto rd_inq_data;
  1829. }
  1830. if ((k & 0x80) == 0) {
  1831. goto rd_inq_data;
  1832. }
  1833. tmport -= 0x08;
  1834. j = inb(tmport);
  1835. if (j == 0x16) {
  1836. goto inq_ok;
  1837. }
  1838. tmport = wkport + 0x50;
  1839. outb(0x46, tmport);
  1840. tmport += 0x02;
  1841. outb(0, tmport++);
  1842. outb(0, tmport++);
  1843. outb(0, tmport++);
  1844. tmport += 0x03;
  1845. outb(0x08, tmport);
  1846. tmport += 0x07;
  1847. while ((inb(tmport) & 0x80) == 0x00)
  1848. cpu_relax();
  1849. tmport -= 0x08;
  1850. if (inb(tmport) != 0x16)
  1851. goto sel_ok;
  1852. inq_ok:
  1853. mbuf[36] = 0;
  1854. printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
  1855. dev->id[0][i].devtype = mbuf[0];
  1856. rmb = mbuf[1];
  1857. n = mbuf[7];
  1858. if ((mbuf[7] & 0x60) == 0) {
  1859. goto not_wide;
  1860. }
  1861. if ((i < 8) && ((dev->global_map[0] & 0x20) == 0)) {
  1862. goto not_wide;
  1863. }
  1864. if (lvdmode == 0) {
  1865. goto chg_wide;
  1866. }
  1867. if (dev->sp[0][i] != 0x04) // force u2
  1868. {
  1869. goto chg_wide;
  1870. }
  1871. tmport = wkport + 0x5b;
  1872. outb(0x01, tmport);
  1873. tmport = wkport + 0x43;
  1874. outb(satn[0], tmport++);
  1875. outb(satn[1], tmport++);
  1876. outb(satn[2], tmport++);
  1877. outb(satn[3], tmport++);
  1878. outb(satn[4], tmport++);
  1879. outb(satn[5], tmport++);
  1880. tmport += 0x06;
  1881. outb(0, tmport);
  1882. tmport += 0x02;
  1883. outb(dev->id[0][i].devsp, tmport++);
  1884. outb(0, tmport++);
  1885. outb(satn[6], tmport++);
  1886. outb(satn[7], tmport++);
  1887. tmport += 0x03;
  1888. outb(satn[8], tmport);
  1889. tmport += 0x07;
  1890. while ((inb(tmport) & 0x80) == 0x00)
  1891. cpu_relax();
  1892. tmport -= 0x08;
  1893. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1894. continue;
  1895. while (inb(tmport) != 0x8e)
  1896. cpu_relax();
  1897. try_u3:
  1898. j = 0;
  1899. tmport = wkport + 0x54;
  1900. outb(0x09, tmport);
  1901. tmport += 0x04;
  1902. outb(0x20, tmport);
  1903. tmport += 0x07;
  1904. while ((inb(tmport) & 0x80) == 0) {
  1905. if ((inb(tmport) & 0x01) != 0) {
  1906. tmport -= 0x06;
  1907. outb(u3[j++], tmport);
  1908. tmport += 0x06;
  1909. }
  1910. }
  1911. tmport -= 0x08;
  1912. while ((inb(tmport) & 0x80) == 0x00)
  1913. cpu_relax();
  1914. j = inb(tmport) & 0x0f;
  1915. if (j == 0x0f) {
  1916. goto u3p_in;
  1917. }
  1918. if (j == 0x0a) {
  1919. goto u3p_cmd;
  1920. }
  1921. if (j == 0x0e) {
  1922. goto try_u3;
  1923. }
  1924. continue;
  1925. u3p_out:
  1926. tmport = wkport + 0x58;
  1927. outb(0x20, tmport);
  1928. tmport += 0x07;
  1929. while ((inb(tmport) & 0x80) == 0) {
  1930. if ((inb(tmport) & 0x01) != 0) {
  1931. tmport -= 0x06;
  1932. outb(0, tmport);
  1933. tmport += 0x06;
  1934. }
  1935. }
  1936. tmport -= 0x08;
  1937. j = inb(tmport) & 0x0f;
  1938. if (j == 0x0f) {
  1939. goto u3p_in;
  1940. }
  1941. if (j == 0x0a) {
  1942. goto u3p_cmd;
  1943. }
  1944. if (j == 0x0e) {
  1945. goto u3p_out;
  1946. }
  1947. continue;
  1948. u3p_in:
  1949. tmport = wkport + 0x54;
  1950. outb(0x09, tmport);
  1951. tmport += 0x04;
  1952. outb(0x20, tmport);
  1953. tmport += 0x07;
  1954. k = 0;
  1955. u3p_in1:
  1956. j = inb(tmport);
  1957. if ((j & 0x01) != 0) {
  1958. tmport -= 0x06;
  1959. mbuf[k++] = inb(tmport);
  1960. tmport += 0x06;
  1961. goto u3p_in1;
  1962. }
  1963. if ((j & 0x80) == 0x00) {
  1964. goto u3p_in1;
  1965. }
  1966. tmport -= 0x08;
  1967. j = inb(tmport) & 0x0f;
  1968. if (j == 0x0f) {
  1969. goto u3p_in;
  1970. }
  1971. if (j == 0x0a) {
  1972. goto u3p_cmd;
  1973. }
  1974. if (j == 0x0e) {
  1975. goto u3p_out;
  1976. }
  1977. continue;
  1978. u3p_cmd:
  1979. tmport = wkport + 0x50;
  1980. outb(0x30, tmport);
  1981. tmport = wkport + 0x54;
  1982. outb(0x00, tmport);
  1983. tmport += 0x04;
  1984. outb(0x08, tmport);
  1985. tmport += 0x07;
  1986. while ((inb(tmport) & 0x80) == 0x00)
  1987. cpu_relax();
  1988. tmport -= 0x08;
  1989. j = inb(tmport);
  1990. if (j != 0x16) {
  1991. if (j == 0x4e) {
  1992. goto u3p_out;
  1993. }
  1994. continue;
  1995. }
  1996. if (mbuf[0] != 0x01) {
  1997. goto chg_wide;
  1998. }
  1999. if (mbuf[1] != 0x06) {
  2000. goto chg_wide;
  2001. }
  2002. if (mbuf[2] != 0x04) {
  2003. goto chg_wide;
  2004. }
  2005. if (mbuf[3] == 0x09) {
  2006. m = 1;
  2007. m = m << i;
  2008. dev->wide_id[0] |= m;
  2009. dev->id[0][i].devsp = 0xce;
  2010. continue;
  2011. }
  2012. chg_wide:
  2013. tmport = wkport + 0x5b;
  2014. outb(0x01, tmport);
  2015. tmport = wkport + 0x43;
  2016. outb(satn[0], tmport++);
  2017. outb(satn[1], tmport++);
  2018. outb(satn[2], tmport++);
  2019. outb(satn[3], tmport++);
  2020. outb(satn[4], tmport++);
  2021. outb(satn[5], tmport++);
  2022. tmport += 0x06;
  2023. outb(0, tmport);
  2024. tmport += 0x02;
  2025. outb(dev->id[0][i].devsp, tmport++);
  2026. outb(0, tmport++);
  2027. outb(satn[6], tmport++);
  2028. outb(satn[7], tmport++);
  2029. tmport += 0x03;
  2030. outb(satn[8], tmport);
  2031. tmport += 0x07;
  2032. while ((inb(tmport) & 0x80) == 0x00)
  2033. cpu_relax();
  2034. tmport -= 0x08;
  2035. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  2036. continue;
  2037. while (inb(tmport) != 0x8e)
  2038. cpu_relax();
  2039. try_wide:
  2040. j = 0;
  2041. tmport = wkport + 0x54;
  2042. outb(0x05, tmport);
  2043. tmport += 0x04;
  2044. outb(0x20, tmport);
  2045. tmport += 0x07;
  2046. while ((inb(tmport) & 0x80) == 0) {
  2047. if ((inb(tmport) & 0x01) != 0) {
  2048. tmport -= 0x06;
  2049. outb(wide[j++], tmport);
  2050. tmport += 0x06;
  2051. }
  2052. }
  2053. tmport -= 0x08;
  2054. while ((inb(tmport) & 0x80) == 0x00)
  2055. cpu_relax();
  2056. j = inb(tmport) & 0x0f;
  2057. if (j == 0x0f) {
  2058. goto widep_in;
  2059. }
  2060. if (j == 0x0a) {
  2061. goto widep_cmd;
  2062. }
  2063. if (j == 0x0e) {
  2064. goto try_wide;
  2065. }
  2066. continue;
  2067. widep_out:
  2068. tmport = wkport + 0x58;
  2069. outb(0x20, tmport);
  2070. tmport += 0x07;
  2071. while ((inb(tmport) & 0x80) == 0) {
  2072. if ((inb(tmport) & 0x01) != 0) {
  2073. tmport -= 0x06;
  2074. outb(0, tmport);
  2075. tmport += 0x06;
  2076. }
  2077. }
  2078. tmport -= 0x08;
  2079. j = inb(tmport) & 0x0f;
  2080. if (j == 0x0f) {
  2081. goto widep_in;
  2082. }
  2083. if (j == 0x0a) {
  2084. goto widep_cmd;
  2085. }
  2086. if (j == 0x0e) {
  2087. goto widep_out;
  2088. }
  2089. continue;
  2090. widep_in:
  2091. tmport = wkport + 0x54;
  2092. outb(0xff, tmport);
  2093. tmport += 0x04;
  2094. outb(0x20, tmport);
  2095. tmport += 0x07;
  2096. k = 0;
  2097. widep_in1:
  2098. j = inb(tmport);
  2099. if ((j & 0x01) != 0) {
  2100. tmport -= 0x06;
  2101. mbuf[k++] = inb(tmport);
  2102. tmport += 0x06;
  2103. goto widep_in1;
  2104. }
  2105. if ((j & 0x80) == 0x00) {
  2106. goto widep_in1;
  2107. }
  2108. tmport -= 0x08;
  2109. j = inb(tmport) & 0x0f;
  2110. if (j == 0x0f) {
  2111. goto widep_in;
  2112. }
  2113. if (j == 0x0a) {
  2114. goto widep_cmd;
  2115. }
  2116. if (j == 0x0e) {
  2117. goto widep_out;
  2118. }
  2119. continue;
  2120. widep_cmd:
  2121. tmport = wkport + 0x50;
  2122. outb(0x30, tmport);
  2123. tmport = wkport + 0x54;
  2124. outb(0x00, tmport);
  2125. tmport += 0x04;
  2126. outb(0x08, tmport);
  2127. tmport += 0x07;
  2128. while ((inb(tmport) & 0x80) == 0x00)
  2129. cpu_relax();
  2130. tmport -= 0x08;
  2131. j = inb(tmport);
  2132. if (j != 0x16) {
  2133. if (j == 0x4e) {
  2134. goto widep_out;
  2135. }
  2136. continue;
  2137. }
  2138. if (mbuf[0] != 0x01) {
  2139. goto not_wide;
  2140. }
  2141. if (mbuf[1] != 0x02) {
  2142. goto not_wide;
  2143. }
  2144. if (mbuf[2] != 0x03) {
  2145. goto not_wide;
  2146. }
  2147. if (mbuf[3] != 0x01) {
  2148. goto not_wide;
  2149. }
  2150. m = 1;
  2151. m = m << i;
  2152. dev->wide_id[0] |= m;
  2153. not_wide:
  2154. if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  2155. m = 1;
  2156. m = m << i;
  2157. if ((dev->async[0] & m) != 0) {
  2158. goto set_sync;
  2159. }
  2160. }
  2161. continue;
  2162. set_sync:
  2163. if (dev->sp[0][i] == 0x02) {
  2164. synu[4] = 0x0c;
  2165. synuw[4] = 0x0c;
  2166. } else {
  2167. if (dev->sp[0][i] >= 0x03) {
  2168. synu[4] = 0x0a;
  2169. synuw[4] = 0x0a;
  2170. }
  2171. }
  2172. tmport = wkport + 0x5b;
  2173. j = 0;
  2174. if ((m & dev->wide_id[0]) != 0) {
  2175. j |= 0x01;
  2176. }
  2177. outb(j, tmport);
  2178. tmport = wkport + 0x43;
  2179. outb(satn[0], tmport++);
  2180. outb(satn[1], tmport++);
  2181. outb(satn[2], tmport++);
  2182. outb(satn[3], tmport++);
  2183. outb(satn[4], tmport++);
  2184. outb(satn[5], tmport++);
  2185. tmport += 0x06;
  2186. outb(0, tmport);
  2187. tmport += 0x02;
  2188. outb(dev->id[0][i].devsp, tmport++);
  2189. outb(0, tmport++);
  2190. outb(satn[6], tmport++);
  2191. outb(satn[7], tmport++);
  2192. tmport += 0x03;
  2193. outb(satn[8], tmport);
  2194. tmport += 0x07;
  2195. while ((inb(tmport) & 0x80) == 0x00)
  2196. cpu_relax();
  2197. tmport -= 0x08;
  2198. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  2199. continue;
  2200. }
  2201. while (inb(tmport) != 0x8e)
  2202. cpu_relax();
  2203. try_sync:
  2204. j = 0;
  2205. tmport = wkport + 0x54;
  2206. outb(0x06, tmport);
  2207. tmport += 0x04;
  2208. outb(0x20, tmport);
  2209. tmport += 0x07;
  2210. while ((inb(tmport) & 0x80) == 0) {
  2211. if ((inb(tmport) & 0x01) != 0) {
  2212. tmport -= 0x06;
  2213. if ((m & dev->wide_id[0]) != 0) {
  2214. if ((m & dev->ultra_map[0]) != 0) {
  2215. outb(synuw[j++], tmport);
  2216. } else {
  2217. outb(synw[j++], tmport);
  2218. }
  2219. } else {
  2220. if ((m & dev->ultra_map[0]) != 0) {
  2221. outb(synu[j++], tmport);
  2222. } else {
  2223. outb(synn[j++], tmport);
  2224. }
  2225. }
  2226. tmport += 0x06;
  2227. }
  2228. }
  2229. tmport -= 0x08;
  2230. while ((inb(tmport) & 0x80) == 0x00)
  2231. cpu_relax();
  2232. j = inb(tmport) & 0x0f;
  2233. if (j == 0x0f) {
  2234. goto phase_ins;
  2235. }
  2236. if (j == 0x0a) {
  2237. goto phase_cmds;
  2238. }
  2239. if (j == 0x0e) {
  2240. goto try_sync;
  2241. }
  2242. continue;
  2243. phase_outs:
  2244. tmport = wkport + 0x58;
  2245. outb(0x20, tmport);
  2246. tmport += 0x07;
  2247. while ((inb(tmport) & 0x80) == 0x00) {
  2248. if ((inb(tmport) & 0x01) != 0x00) {
  2249. tmport -= 0x06;
  2250. outb(0x00, tmport);
  2251. tmport += 0x06;
  2252. }
  2253. }
  2254. tmport -= 0x08;
  2255. j = inb(tmport);
  2256. if (j == 0x85) {
  2257. goto tar_dcons;
  2258. }
  2259. j &= 0x0f;
  2260. if (j == 0x0f) {
  2261. goto phase_ins;
  2262. }
  2263. if (j == 0x0a) {
  2264. goto phase_cmds;
  2265. }
  2266. if (j == 0x0e) {
  2267. goto phase_outs;
  2268. }
  2269. continue;
  2270. phase_ins:
  2271. tmport = wkport + 0x54;
  2272. outb(0x06, tmport);
  2273. tmport += 0x04;
  2274. outb(0x20, tmport);
  2275. tmport += 0x07;
  2276. k = 0;
  2277. phase_ins1:
  2278. j = inb(tmport);
  2279. if ((j & 0x01) != 0x00) {
  2280. tmport -= 0x06;
  2281. mbuf[k++] = inb(tmport);
  2282. tmport += 0x06;
  2283. goto phase_ins1;
  2284. }
  2285. if ((j & 0x80) == 0x00) {
  2286. goto phase_ins1;
  2287. }
  2288. tmport -= 0x08;
  2289. while ((inb(tmport) & 0x80) == 0x00)
  2290. cpu_relax();
  2291. j = inb(tmport);
  2292. if (j == 0x85) {
  2293. goto tar_dcons;
  2294. }
  2295. j &= 0x0f;
  2296. if (j == 0x0f) {
  2297. goto phase_ins;
  2298. }
  2299. if (j == 0x0a) {
  2300. goto phase_cmds;
  2301. }
  2302. if (j == 0x0e) {
  2303. goto phase_outs;
  2304. }
  2305. continue;
  2306. phase_cmds:
  2307. tmport = wkport + 0x50;
  2308. outb(0x30, tmport);
  2309. tar_dcons:
  2310. tmport = wkport + 0x54;
  2311. outb(0x00, tmport);
  2312. tmport += 0x04;
  2313. outb(0x08, tmport);
  2314. tmport += 0x07;
  2315. while ((inb(tmport) & 0x80) == 0x00)
  2316. cpu_relax();
  2317. tmport -= 0x08;
  2318. j = inb(tmport);
  2319. if (j != 0x16) {
  2320. continue;
  2321. }
  2322. if (mbuf[0] != 0x01) {
  2323. continue;
  2324. }
  2325. if (mbuf[1] != 0x03) {
  2326. continue;
  2327. }
  2328. if (mbuf[4] == 0x00) {
  2329. continue;
  2330. }
  2331. if (mbuf[3] > 0x64) {
  2332. continue;
  2333. }
  2334. if (mbuf[4] > 0x0e) {
  2335. mbuf[4] = 0x0e;
  2336. }
  2337. dev->id[0][i].devsp = mbuf[4];
  2338. if (mbuf[3] < 0x0c) {
  2339. j = 0xb0;
  2340. goto set_syn_ok;
  2341. }
  2342. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  2343. j = 0xa0;
  2344. goto set_syn_ok;
  2345. }
  2346. if (mbuf[3] < 0x1a) {
  2347. j = 0x20;
  2348. goto set_syn_ok;
  2349. }
  2350. if (mbuf[3] < 0x33) {
  2351. j = 0x40;
  2352. goto set_syn_ok;
  2353. }
  2354. if (mbuf[3] < 0x4c) {
  2355. j = 0x50;
  2356. goto set_syn_ok;
  2357. }
  2358. j = 0x60;
  2359. set_syn_ok:
  2360. dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
  2361. }
  2362. }
  2363. static void atp870u_free_tables(struct Scsi_Host *host)
  2364. {
  2365. struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
  2366. int j, k;
  2367. for (j=0; j < 2; j++) {
  2368. for (k = 0; k < 16; k++) {
  2369. if (!atp_dev->id[j][k].prd_table)
  2370. continue;
  2371. pci_free_consistent(atp_dev->pdev, 1024, atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
  2372. atp_dev->id[j][k].prd_table = NULL;
  2373. }
  2374. }
  2375. }
  2376. static int atp870u_init_tables(struct Scsi_Host *host)
  2377. {
  2378. struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
  2379. int c,k;
  2380. for(c=0;c < 2;c++) {
  2381. for(k=0;k<16;k++) {
  2382. atp_dev->id[c][k].prd_table = pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus));
  2383. if (!atp_dev->id[c][k].prd_table) {
  2384. printk("atp870u_init_tables fail\n");
  2385. atp870u_free_tables(host);
  2386. return -ENOMEM;
  2387. }
  2388. atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus;
  2389. atp_dev->id[c][k].devsp=0x20;
  2390. atp_dev->id[c][k].devtype = 0x7f;
  2391. atp_dev->id[c][k].curr_req = NULL;
  2392. }
  2393. atp_dev->active_id[c] = 0;
  2394. atp_dev->wide_id[c] = 0;
  2395. atp_dev->host_id[c] = 0x07;
  2396. atp_dev->quhd[c] = 0;
  2397. atp_dev->quend[c] = 0;
  2398. atp_dev->last_cmd[c] = 0xff;
  2399. atp_dev->in_snd[c] = 0;
  2400. atp_dev->in_int[c] = 0;
  2401. for (k = 0; k < qcnt; k++) {
  2402. atp_dev->quereq[c][k] = NULL;
  2403. }
  2404. for (k = 0; k < 16; k++) {
  2405. atp_dev->id[c][k].curr_req = NULL;
  2406. atp_dev->sp[c][k] = 0x04;
  2407. }
  2408. }
  2409. return 0;
  2410. }
  2411. /* return non-zero on detection */
  2412. static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2413. {
  2414. unsigned char k, m, c;
  2415. unsigned long flags;
  2416. unsigned int base_io, tmport, error,n;
  2417. unsigned char host_id;
  2418. struct Scsi_Host *shpnt = NULL;
  2419. struct atp_unit *atpdev, *p;
  2420. unsigned char setupdata[2][16];
  2421. int count = 0;
  2422. atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL);
  2423. if (!atpdev)
  2424. return -ENOMEM;
  2425. if (pci_enable_device(pdev))
  2426. goto err_eio;
  2427. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  2428. printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
  2429. } else {
  2430. printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
  2431. goto err_eio;
  2432. }
  2433. /*
  2434. * It's probably easier to weed out some revisions like
  2435. * this than via the PCI device table
  2436. */
  2437. if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
  2438. atpdev->chip_ver = pdev->revision;
  2439. if (atpdev->chip_ver < 2)
  2440. goto err_eio;
  2441. }
  2442. switch (ent->device) {
  2443. case PCI_DEVICE_ID_ARTOP_AEC7612UW:
  2444. case PCI_DEVICE_ID_ARTOP_AEC7612SUW:
  2445. case ATP880_DEVID1:
  2446. case ATP880_DEVID2:
  2447. case ATP885_DEVID:
  2448. atpdev->chip_ver = 0x04;
  2449. default:
  2450. break;
  2451. }
  2452. base_io = pci_resource_start(pdev, 0);
  2453. base_io &= 0xfffffff8;
  2454. if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
  2455. atpdev->chip_ver = pdev->revision;
  2456. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
  2457. host_id = inb(base_io + 0x39);
  2458. host_id >>= 0x04;
  2459. printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
  2460. " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2461. atpdev->ioport[0] = base_io + 0x40;
  2462. atpdev->pciport[0] = base_io + 0x28;
  2463. atpdev->dev_id = ent->device;
  2464. atpdev->host_id[0] = host_id;
  2465. tmport = base_io + 0x22;
  2466. atpdev->scam_on = inb(tmport);
  2467. tmport += 0x13;
  2468. atpdev->global_map[0] = inb(tmport);
  2469. tmport += 0x07;
  2470. atpdev->ultra_map[0] = inw(tmport);
  2471. n = 0x3f09;
  2472. next_fblk_880:
  2473. if (n >= 0x4000)
  2474. goto flash_ok_880;
  2475. m = 0;
  2476. outw(n, base_io + 0x34);
  2477. n += 0x0002;
  2478. if (inb(base_io + 0x30) == 0xff)
  2479. goto flash_ok_880;
  2480. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2481. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2482. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2483. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2484. outw(n, base_io + 0x34);
  2485. n += 0x0002;
  2486. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2487. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2488. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2489. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2490. outw(n, base_io + 0x34);
  2491. n += 0x0002;
  2492. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2493. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2494. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2495. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2496. outw(n, base_io + 0x34);
  2497. n += 0x0002;
  2498. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2499. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2500. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2501. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2502. n += 0x0018;
  2503. goto next_fblk_880;
  2504. flash_ok_880:
  2505. outw(0, base_io + 0x34);
  2506. atpdev->ultra_map[0] = 0;
  2507. atpdev->async[0] = 0;
  2508. for (k = 0; k < 16; k++) {
  2509. n = 1;
  2510. n = n << k;
  2511. if (atpdev->sp[0][k] > 1) {
  2512. atpdev->ultra_map[0] |= n;
  2513. } else {
  2514. if (atpdev->sp[0][k] == 0)
  2515. atpdev->async[0] |= n;
  2516. }
  2517. }
  2518. atpdev->async[0] = ~(atpdev->async[0]);
  2519. outb(atpdev->global_map[0], base_io + 0x35);
  2520. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2521. if (!shpnt)
  2522. goto err_nomem;
  2523. p = (struct atp_unit *)&shpnt->hostdata;
  2524. atpdev->host = shpnt;
  2525. atpdev->pdev = pdev;
  2526. pci_set_drvdata(pdev, p);
  2527. memcpy(p, atpdev, sizeof(*atpdev));
  2528. if (atp870u_init_tables(shpnt) < 0) {
  2529. printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
  2530. goto unregister;
  2531. }
  2532. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp880i", shpnt)) {
  2533. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2534. goto free_tables;
  2535. }
  2536. spin_lock_irqsave(shpnt->host_lock, flags);
  2537. tmport = base_io + 0x38;
  2538. k = inb(tmport) & 0x80;
  2539. outb(k, tmport);
  2540. tmport += 0x03;
  2541. outb(0x20, tmport);
  2542. mdelay(32);
  2543. outb(0, tmport);
  2544. mdelay(32);
  2545. tmport = base_io + 0x5b;
  2546. inb(tmport);
  2547. tmport -= 0x04;
  2548. inb(tmport);
  2549. tmport = base_io + 0x40;
  2550. outb((host_id | 0x08), tmport);
  2551. tmport += 0x18;
  2552. outb(0, tmport);
  2553. tmport += 0x07;
  2554. while ((inb(tmport) & 0x80) == 0)
  2555. mdelay(1);
  2556. tmport -= 0x08;
  2557. inb(tmport);
  2558. tmport = base_io + 0x41;
  2559. outb(8, tmport++);
  2560. outb(0x7f, tmport);
  2561. tmport = base_io + 0x51;
  2562. outb(0x20, tmport);
  2563. tscam(shpnt);
  2564. is880(p, base_io);
  2565. tmport = base_io + 0x38;
  2566. outb(0xb0, tmport);
  2567. shpnt->max_id = 16;
  2568. shpnt->this_id = host_id;
  2569. shpnt->unique_id = base_io;
  2570. shpnt->io_port = base_io;
  2571. shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */
  2572. shpnt->irq = pdev->irq;
  2573. } else if (ent->device == ATP885_DEVID) {
  2574. printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
  2575. , base_io, pdev->irq);
  2576. atpdev->pdev = pdev;
  2577. atpdev->dev_id = ent->device;
  2578. atpdev->baseport = base_io;
  2579. atpdev->ioport[0] = base_io + 0x80;
  2580. atpdev->ioport[1] = base_io + 0xc0;
  2581. atpdev->pciport[0] = base_io + 0x40;
  2582. atpdev->pciport[1] = base_io + 0x50;
  2583. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2584. if (!shpnt)
  2585. goto err_nomem;
  2586. p = (struct atp_unit *)&shpnt->hostdata;
  2587. atpdev->host = shpnt;
  2588. atpdev->pdev = pdev;
  2589. pci_set_drvdata(pdev, p);
  2590. memcpy(p, atpdev, sizeof(struct atp_unit));
  2591. if (atp870u_init_tables(shpnt) < 0)
  2592. goto unregister;
  2593. #ifdef ED_DBGP
  2594. printk("request_irq() shpnt %p hostdata %p\n", shpnt, p);
  2595. #endif
  2596. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt)) {
  2597. printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
  2598. goto free_tables;
  2599. }
  2600. spin_lock_irqsave(shpnt->host_lock, flags);
  2601. c=inb(base_io + 0x29);
  2602. outb((c | 0x04),base_io + 0x29);
  2603. n=0x1f80;
  2604. next_fblk_885:
  2605. if (n >= 0x2000) {
  2606. goto flash_ok_885;
  2607. }
  2608. outw(n,base_io + 0x3c);
  2609. if (inl(base_io + 0x38) == 0xffffffff) {
  2610. goto flash_ok_885;
  2611. }
  2612. for (m=0; m < 2; m++) {
  2613. p->global_map[m]= 0;
  2614. for (k=0; k < 4; k++) {
  2615. outw(n++,base_io + 0x3c);
  2616. ((unsigned long *)&setupdata[m][0])[k]=inl(base_io + 0x38);
  2617. }
  2618. for (k=0; k < 4; k++) {
  2619. outw(n++,base_io + 0x3c);
  2620. ((unsigned long *)&p->sp[m][0])[k]=inl(base_io + 0x38);
  2621. }
  2622. n += 8;
  2623. }
  2624. goto next_fblk_885;
  2625. flash_ok_885:
  2626. #ifdef ED_DBGP
  2627. printk( "Flash Read OK\n");
  2628. #endif
  2629. c=inb(base_io + 0x29);
  2630. outb((c & 0xfb),base_io + 0x29);
  2631. for (c=0;c < 2;c++) {
  2632. p->ultra_map[c]=0;
  2633. p->async[c] = 0;
  2634. for (k=0; k < 16; k++) {
  2635. n=1;
  2636. n = n << k;
  2637. if (p->sp[c][k] > 1) {
  2638. p->ultra_map[c] |= n;
  2639. } else {
  2640. if (p->sp[c][k] == 0) {
  2641. p->async[c] |= n;
  2642. }
  2643. }
  2644. }
  2645. p->async[c] = ~(p->async[c]);
  2646. if (p->global_map[c] == 0) {
  2647. k=setupdata[c][1];
  2648. if ((k & 0x40) != 0)
  2649. p->global_map[c] |= 0x20;
  2650. k &= 0x07;
  2651. p->global_map[c] |= k;
  2652. if ((setupdata[c][2] & 0x04) != 0)
  2653. p->global_map[c] |= 0x08;
  2654. p->host_id[c] = setupdata[c][0] & 0x07;
  2655. }
  2656. }
  2657. k = inb(base_io + 0x28) & 0x8f;
  2658. k |= 0x10;
  2659. outb(k, base_io + 0x28);
  2660. outb(0x80, base_io + 0x41);
  2661. outb(0x80, base_io + 0x51);
  2662. mdelay(100);
  2663. outb(0, base_io + 0x41);
  2664. outb(0, base_io + 0x51);
  2665. mdelay(1000);
  2666. inb(base_io + 0x9b);
  2667. inb(base_io + 0x97);
  2668. inb(base_io + 0xdb);
  2669. inb(base_io + 0xd7);
  2670. tmport = base_io + 0x80;
  2671. k=p->host_id[0];
  2672. if (k > 7)
  2673. k = (k & 0x07) | 0x40;
  2674. k |= 0x08;
  2675. outb(k, tmport);
  2676. tmport += 0x18;
  2677. outb(0, tmport);
  2678. tmport += 0x07;
  2679. while ((inb(tmport) & 0x80) == 0)
  2680. cpu_relax();
  2681. tmport -= 0x08;
  2682. inb(tmport);
  2683. tmport = base_io + 0x81;
  2684. outb(8, tmport++);
  2685. outb(0x7f, tmport);
  2686. tmport = base_io + 0x91;
  2687. outb(0x20, tmport);
  2688. tmport = base_io + 0xc0;
  2689. k=p->host_id[1];
  2690. if (k > 7)
  2691. k = (k & 0x07) | 0x40;
  2692. k |= 0x08;
  2693. outb(k, tmport);
  2694. tmport += 0x18;
  2695. outb(0, tmport);
  2696. tmport += 0x07;
  2697. while ((inb(tmport) & 0x80) == 0)
  2698. cpu_relax();
  2699. tmport -= 0x08;
  2700. inb(tmport);
  2701. tmport = base_io + 0xc1;
  2702. outb(8, tmport++);
  2703. outb(0x7f, tmport);
  2704. tmport = base_io + 0xd1;
  2705. outb(0x20, tmport);
  2706. tscam_885();
  2707. printk(KERN_INFO " Scanning Channel A SCSI Device ...\n");
  2708. is885(p, base_io + 0x80, 0);
  2709. printk(KERN_INFO " Scanning Channel B SCSI Device ...\n");
  2710. is885(p, base_io + 0xc0, 1);
  2711. k = inb(base_io + 0x28) & 0xcf;
  2712. k |= 0xc0;
  2713. outb(k, base_io + 0x28);
  2714. k = inb(base_io + 0x1f) | 0x80;
  2715. outb(k, base_io + 0x1f);
  2716. k = inb(base_io + 0x29) | 0x01;
  2717. outb(k, base_io + 0x29);
  2718. #ifdef ED_DBGP
  2719. //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
  2720. #endif
  2721. shpnt->max_id = 16;
  2722. shpnt->max_lun = (p->global_map[0] & 0x07) + 1;
  2723. shpnt->max_channel = 1;
  2724. shpnt->this_id = p->host_id[0];
  2725. shpnt->unique_id = base_io;
  2726. shpnt->io_port = base_io;
  2727. shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */
  2728. shpnt->irq = pdev->irq;
  2729. } else {
  2730. error = pci_read_config_byte(pdev, 0x49, &host_id);
  2731. printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
  2732. "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2733. atpdev->ioport[0] = base_io;
  2734. atpdev->pciport[0] = base_io + 0x20;
  2735. atpdev->dev_id = ent->device;
  2736. host_id &= 0x07;
  2737. atpdev->host_id[0] = host_id;
  2738. tmport = base_io + 0x22;
  2739. atpdev->scam_on = inb(tmport);
  2740. tmport += 0x0b;
  2741. atpdev->global_map[0] = inb(tmport++);
  2742. atpdev->ultra_map[0] = inw(tmport);
  2743. if (atpdev->ultra_map[0] == 0) {
  2744. atpdev->scam_on = 0x00;
  2745. atpdev->global_map[0] = 0x20;
  2746. atpdev->ultra_map[0] = 0xffff;
  2747. }
  2748. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2749. if (!shpnt)
  2750. goto err_nomem;
  2751. p = (struct atp_unit *)&shpnt->hostdata;
  2752. atpdev->host = shpnt;
  2753. atpdev->pdev = pdev;
  2754. pci_set_drvdata(pdev, p);
  2755. memcpy(p, atpdev, sizeof(*atpdev));
  2756. if (atp870u_init_tables(shpnt) < 0)
  2757. goto unregister;
  2758. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870i", shpnt)) {
  2759. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2760. goto free_tables;
  2761. }
  2762. spin_lock_irqsave(shpnt->host_lock, flags);
  2763. if (atpdev->chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
  2764. tmport = base_io + 0x3e;
  2765. outb(0x00, tmport);
  2766. }
  2767. tmport = base_io + 0x3a;
  2768. k = (inb(tmport) & 0xf3) | 0x10;
  2769. outb(k, tmport);
  2770. outb((k & 0xdf), tmport);
  2771. mdelay(32);
  2772. outb(k, tmport);
  2773. mdelay(32);
  2774. tmport = base_io;
  2775. outb((host_id | 0x08), tmport);
  2776. tmport += 0x18;
  2777. outb(0, tmport);
  2778. tmport += 0x07;
  2779. while ((inb(tmport) & 0x80) == 0)
  2780. mdelay(1);
  2781. tmport -= 0x08;
  2782. inb(tmport);
  2783. tmport = base_io + 1;
  2784. outb(8, tmport++);
  2785. outb(0x7f, tmport);
  2786. tmport = base_io + 0x11;
  2787. outb(0x20, tmport);
  2788. tscam(shpnt);
  2789. is870(p, base_io);
  2790. tmport = base_io + 0x3a;
  2791. outb((inb(tmport) & 0xef), tmport);
  2792. tmport++;
  2793. outb((inb(tmport) | 0x20), tmport);
  2794. if (atpdev->chip_ver == 4)
  2795. shpnt->max_id = 16;
  2796. else
  2797. shpnt->max_id = 8;
  2798. shpnt->this_id = host_id;
  2799. shpnt->unique_id = base_io;
  2800. shpnt->io_port = base_io;
  2801. shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */
  2802. shpnt->irq = pdev->irq;
  2803. }
  2804. spin_unlock_irqrestore(shpnt->host_lock, flags);
  2805. if(ent->device==ATP885_DEVID) {
  2806. if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */
  2807. goto request_io_fail;
  2808. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2809. if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */
  2810. goto request_io_fail;
  2811. } else {
  2812. if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */
  2813. goto request_io_fail;
  2814. }
  2815. count++;
  2816. if (scsi_add_host(shpnt, &pdev->dev))
  2817. goto scsi_add_fail;
  2818. scsi_scan_host(shpnt);
  2819. #ifdef ED_DBGP
  2820. printk("atp870u_prob : exit\n");
  2821. #endif
  2822. return 0;
  2823. scsi_add_fail:
  2824. printk("atp870u_prob:scsi_add_fail\n");
  2825. if(ent->device==ATP885_DEVID) {
  2826. release_region(base_io, 0xff);
  2827. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2828. release_region(base_io, 0x60);
  2829. } else {
  2830. release_region(base_io, 0x40);
  2831. }
  2832. request_io_fail:
  2833. printk("atp870u_prob:request_io_fail\n");
  2834. free_irq(pdev->irq, shpnt);
  2835. free_tables:
  2836. printk("atp870u_prob:free_table\n");
  2837. atp870u_free_tables(shpnt);
  2838. unregister:
  2839. printk("atp870u_prob:unregister\n");
  2840. scsi_host_put(shpnt);
  2841. return -1;
  2842. err_eio:
  2843. kfree(atpdev);
  2844. return -EIO;
  2845. err_nomem:
  2846. kfree(atpdev);
  2847. return -ENOMEM;
  2848. }
  2849. /* The abort command does not leave the device in a clean state where
  2850. it is available to be used again. Until this gets worked out, we will
  2851. leave it commented out. */
  2852. static int atp870u_abort(struct scsi_cmnd * SCpnt)
  2853. {
  2854. unsigned char j, k, c;
  2855. struct scsi_cmnd *workrequ;
  2856. unsigned int tmport;
  2857. struct atp_unit *dev;
  2858. struct Scsi_Host *host;
  2859. host = SCpnt->device->host;
  2860. dev = (struct atp_unit *)&host->hostdata;
  2861. c = scmd_channel(SCpnt);
  2862. printk(" atp870u: abort Channel = %x \n", c);
  2863. printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
  2864. printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
  2865. tmport = dev->ioport[c];
  2866. for (j = 0; j < 0x18; j++) {
  2867. printk(" r%2x=%2x", j, inb(tmport++));
  2868. }
  2869. tmport += 0x04;
  2870. printk(" r1c=%2x", inb(tmport));
  2871. tmport += 0x03;
  2872. printk(" r1f=%2x in_snd=%2x ", inb(tmport), dev->in_snd[c]);
  2873. tmport= dev->pciport[c];
  2874. printk(" d00=%2x", inb(tmport));
  2875. tmport += 0x02;
  2876. printk(" d02=%2x", inb(tmport));
  2877. for(j=0;j<16;j++) {
  2878. if (dev->id[c][j].curr_req != NULL) {
  2879. workrequ = dev->id[c][j].curr_req;
  2880. printk("\n que cdb= ");
  2881. for (k=0; k < workrequ->cmd_len; k++) {
  2882. printk(" %2x ",workrequ->cmnd[k]);
  2883. }
  2884. printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
  2885. }
  2886. }
  2887. return SUCCESS;
  2888. }
  2889. static const char *atp870u_info(struct Scsi_Host *notused)
  2890. {
  2891. static char buffer[128];
  2892. strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
  2893. return buffer;
  2894. }
  2895. static int atp870u_show_info(struct seq_file *m, struct Scsi_Host *HBAptr)
  2896. {
  2897. seq_puts(m, "ACARD AEC-671X Driver Version: 2.6+ac\n\n"
  2898. "Adapter Configuration:\n");
  2899. seq_printf(m, " Base IO: %#.4lx\n", HBAptr->io_port);
  2900. seq_printf(m, " IRQ: %d\n", HBAptr->irq);
  2901. return 0;
  2902. }
  2903. static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
  2904. sector_t capacity, int *ip)
  2905. {
  2906. int heads, sectors, cylinders;
  2907. heads = 64;
  2908. sectors = 32;
  2909. cylinders = (unsigned long)capacity / (heads * sectors);
  2910. if (cylinders > 1024) {
  2911. heads = 255;
  2912. sectors = 63;
  2913. cylinders = (unsigned long)capacity / (heads * sectors);
  2914. }
  2915. ip[0] = heads;
  2916. ip[1] = sectors;
  2917. ip[2] = cylinders;
  2918. return 0;
  2919. }
  2920. static void atp870u_remove (struct pci_dev *pdev)
  2921. {
  2922. struct atp_unit *devext = pci_get_drvdata(pdev);
  2923. struct Scsi_Host *pshost = devext->host;
  2924. scsi_remove_host(pshost);
  2925. printk(KERN_INFO "free_irq : %d\n",pshost->irq);
  2926. free_irq(pshost->irq, pshost);
  2927. release_region(pshost->io_port, pshost->n_io_port);
  2928. printk(KERN_INFO "atp870u_free_tables : %p\n",pshost);
  2929. atp870u_free_tables(pshost);
  2930. printk(KERN_INFO "scsi_host_put : %p\n",pshost);
  2931. scsi_host_put(pshost);
  2932. }
  2933. MODULE_LICENSE("GPL");
  2934. static struct scsi_host_template atp870u_template = {
  2935. .module = THIS_MODULE,
  2936. .name = "atp870u" /* name */,
  2937. .proc_name = "atp870u",
  2938. .show_info = atp870u_show_info,
  2939. .info = atp870u_info /* info */,
  2940. .queuecommand = atp870u_queuecommand /* queuecommand */,
  2941. .eh_abort_handler = atp870u_abort /* abort */,
  2942. .bios_param = atp870u_biosparam /* biosparm */,
  2943. .can_queue = qcnt /* can_queue */,
  2944. .this_id = 7 /* SCSI ID */,
  2945. .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/,
  2946. .use_clustering = ENABLE_CLUSTERING,
  2947. .max_sectors = ATP870U_MAX_SECTORS,
  2948. };
  2949. static struct pci_device_id atp870u_id_table[] = {
  2950. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
  2951. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
  2952. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
  2953. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
  2954. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
  2955. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
  2956. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
  2957. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
  2958. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
  2959. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
  2960. { 0, },
  2961. };
  2962. MODULE_DEVICE_TABLE(pci, atp870u_id_table);
  2963. static struct pci_driver atp870u_driver = {
  2964. .id_table = atp870u_id_table,
  2965. .name = "atp870u",
  2966. .probe = atp870u_probe,
  2967. .remove = atp870u_remove,
  2968. };
  2969. static int __init atp870u_init(void)
  2970. {
  2971. #ifdef ED_DBGP
  2972. printk("atp870u_init: Entry\n");
  2973. #endif
  2974. return pci_register_driver(&atp870u_driver);
  2975. }
  2976. static void __exit atp870u_exit(void)
  2977. {
  2978. #ifdef ED_DBGP
  2979. printk("atp870u_exit: Entry\n");
  2980. #endif
  2981. pci_unregister_driver(&atp870u_driver);
  2982. }
  2983. static void tscam_885(void)
  2984. {
  2985. unsigned char i;
  2986. for (i = 0; i < 0x2; i++) {
  2987. mdelay(300);
  2988. }
  2989. return;
  2990. }
  2991. static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c)
  2992. {
  2993. unsigned int tmport;
  2994. unsigned char i, j, k, rmb, n, lvdmode;
  2995. unsigned short int m;
  2996. static unsigned char mbuf[512];
  2997. static unsigned char satn[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
  2998. static unsigned char inqd[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
  2999. static unsigned char synn[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3000. unsigned char synu[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3001. static unsigned char synw[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3002. unsigned char synuw[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3003. static unsigned char wide[6] = {0x80, 1, 2, 3, 1, 0};
  3004. static unsigned char u3[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
  3005. lvdmode=inb(wkport + 0x1b) >> 7;
  3006. for (i = 0; i < 16; i++) {
  3007. m = 1;
  3008. m = m << i;
  3009. if ((m & dev->active_id[c]) != 0) {
  3010. continue;
  3011. }
  3012. if (i == dev->host_id[c]) {
  3013. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
  3014. continue;
  3015. }
  3016. tmport = wkport + 0x1b;
  3017. outb(0x01, tmport);
  3018. tmport = wkport + 0x01;
  3019. outb(0x08, tmport++);
  3020. outb(0x7f, tmport++);
  3021. outb(satn[0], tmport++);
  3022. outb(satn[1], tmport++);
  3023. outb(satn[2], tmport++);
  3024. outb(satn[3], tmport++);
  3025. outb(satn[4], tmport++);
  3026. outb(satn[5], tmport++);
  3027. tmport += 0x06;
  3028. outb(0, tmport);
  3029. tmport += 0x02;
  3030. outb(dev->id[c][i].devsp, tmport++);
  3031. outb(0, tmport++);
  3032. outb(satn[6], tmport++);
  3033. outb(satn[7], tmport++);
  3034. j = i;
  3035. if ((j & 0x08) != 0) {
  3036. j = (j & 0x07) | 0x40;
  3037. }
  3038. outb(j, tmport);
  3039. tmport += 0x03;
  3040. outb(satn[8], tmport);
  3041. tmport += 0x07;
  3042. while ((inb(tmport) & 0x80) == 0x00)
  3043. cpu_relax();
  3044. tmport -= 0x08;
  3045. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3046. continue;
  3047. }
  3048. while (inb(tmport) != 0x8e)
  3049. cpu_relax();
  3050. dev->active_id[c] |= m;
  3051. tmport = wkport + 0x10;
  3052. outb(0x30, tmport);
  3053. tmport = wkport + 0x14;
  3054. outb(0x00, tmport);
  3055. phase_cmd:
  3056. tmport = wkport + 0x18;
  3057. outb(0x08, tmport);
  3058. tmport += 0x07;
  3059. while ((inb(tmport) & 0x80) == 0x00)
  3060. cpu_relax();
  3061. tmport -= 0x08;
  3062. j = inb(tmport);
  3063. if (j != 0x16) {
  3064. tmport = wkport + 0x10;
  3065. outb(0x41, tmport);
  3066. goto phase_cmd;
  3067. }
  3068. sel_ok:
  3069. tmport = wkport + 0x03;
  3070. outb(inqd[0], tmport++);
  3071. outb(inqd[1], tmport++);
  3072. outb(inqd[2], tmport++);
  3073. outb(inqd[3], tmport++);
  3074. outb(inqd[4], tmport++);
  3075. outb(inqd[5], tmport);
  3076. tmport += 0x07;
  3077. outb(0, tmport);
  3078. tmport += 0x02;
  3079. outb(dev->id[c][i].devsp, tmport++);
  3080. outb(0, tmport++);
  3081. outb(inqd[6], tmport++);
  3082. outb(inqd[7], tmport++);
  3083. tmport += 0x03;
  3084. outb(inqd[8], tmport);
  3085. tmport += 0x07;
  3086. while ((inb(tmport) & 0x80) == 0x00)
  3087. cpu_relax();
  3088. tmport -= 0x08;
  3089. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3090. continue;
  3091. }
  3092. while (inb(tmport) != 0x8e)
  3093. cpu_relax();
  3094. tmport = wkport + 0x1b;
  3095. outb(0x00, tmport);
  3096. tmport = wkport + 0x18;
  3097. outb(0x08, tmport);
  3098. tmport += 0x07;
  3099. j = 0;
  3100. rd_inq_data:
  3101. k = inb(tmport);
  3102. if ((k & 0x01) != 0) {
  3103. tmport -= 0x06;
  3104. mbuf[j++] = inb(tmport);
  3105. tmport += 0x06;
  3106. goto rd_inq_data;
  3107. }
  3108. if ((k & 0x80) == 0) {
  3109. goto rd_inq_data;
  3110. }
  3111. tmport -= 0x08;
  3112. j = inb(tmport);
  3113. if (j == 0x16) {
  3114. goto inq_ok;
  3115. }
  3116. tmport = wkport + 0x10;
  3117. outb(0x46, tmport);
  3118. tmport += 0x02;
  3119. outb(0, tmport++);
  3120. outb(0, tmport++);
  3121. outb(0, tmport++);
  3122. tmport += 0x03;
  3123. outb(0x08, tmport);
  3124. tmport += 0x07;
  3125. while ((inb(tmport) & 0x80) == 0x00)
  3126. cpu_relax();
  3127. tmport -= 0x08;
  3128. if (inb(tmport) != 0x16) {
  3129. goto sel_ok;
  3130. }
  3131. inq_ok:
  3132. mbuf[36] = 0;
  3133. printk( KERN_INFO" ID: %2d %s\n", i, &mbuf[8]);
  3134. dev->id[c][i].devtype = mbuf[0];
  3135. rmb = mbuf[1];
  3136. n = mbuf[7];
  3137. if ((mbuf[7] & 0x60) == 0) {
  3138. goto not_wide;
  3139. }
  3140. if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) {
  3141. goto not_wide;
  3142. }
  3143. if (lvdmode == 0) {
  3144. goto chg_wide;
  3145. }
  3146. if (dev->sp[c][i] != 0x04) { // force u2
  3147. goto chg_wide;
  3148. }
  3149. tmport = wkport + 0x1b;
  3150. outb(0x01, tmport);
  3151. tmport = wkport + 0x03;
  3152. outb(satn[0], tmport++);
  3153. outb(satn[1], tmport++);
  3154. outb(satn[2], tmport++);
  3155. outb(satn[3], tmport++);
  3156. outb(satn[4], tmport++);
  3157. outb(satn[5], tmport++);
  3158. tmport += 0x06;
  3159. outb(0, tmport);
  3160. tmport += 0x02;
  3161. outb(dev->id[c][i].devsp, tmport++);
  3162. outb(0, tmport++);
  3163. outb(satn[6], tmport++);
  3164. outb(satn[7], tmport++);
  3165. tmport += 0x03;
  3166. outb(satn[8], tmport);
  3167. tmport += 0x07;
  3168. while ((inb(tmport) & 0x80) == 0x00)
  3169. cpu_relax();
  3170. tmport -= 0x08;
  3171. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3172. continue;
  3173. }
  3174. while (inb(tmport) != 0x8e)
  3175. cpu_relax();
  3176. try_u3:
  3177. j = 0;
  3178. tmport = wkport + 0x14;
  3179. outb(0x09, tmport);
  3180. tmport += 0x04;
  3181. outb(0x20, tmport);
  3182. tmport += 0x07;
  3183. while ((inb(tmport) & 0x80) == 0) {
  3184. if ((inb(tmport) & 0x01) != 0) {
  3185. tmport -= 0x06;
  3186. outb(u3[j++], tmport);
  3187. tmport += 0x06;
  3188. }
  3189. cpu_relax();
  3190. }
  3191. tmport -= 0x08;
  3192. while ((inb(tmport) & 0x80) == 0x00)
  3193. cpu_relax();
  3194. j = inb(tmport) & 0x0f;
  3195. if (j == 0x0f) {
  3196. goto u3p_in;
  3197. }
  3198. if (j == 0x0a) {
  3199. goto u3p_cmd;
  3200. }
  3201. if (j == 0x0e) {
  3202. goto try_u3;
  3203. }
  3204. continue;
  3205. u3p_out:
  3206. tmport = wkport + 0x18;
  3207. outb(0x20, tmport);
  3208. tmport += 0x07;
  3209. while ((inb(tmport) & 0x80) == 0) {
  3210. if ((inb(tmport) & 0x01) != 0) {
  3211. tmport -= 0x06;
  3212. outb(0, tmport);
  3213. tmport += 0x06;
  3214. }
  3215. cpu_relax();
  3216. }
  3217. tmport -= 0x08;
  3218. j = inb(tmport) & 0x0f;
  3219. if (j == 0x0f) {
  3220. goto u3p_in;
  3221. }
  3222. if (j == 0x0a) {
  3223. goto u3p_cmd;
  3224. }
  3225. if (j == 0x0e) {
  3226. goto u3p_out;
  3227. }
  3228. continue;
  3229. u3p_in:
  3230. tmport = wkport + 0x14;
  3231. outb(0x09, tmport);
  3232. tmport += 0x04;
  3233. outb(0x20, tmport);
  3234. tmport += 0x07;
  3235. k = 0;
  3236. u3p_in1:
  3237. j = inb(tmport);
  3238. if ((j & 0x01) != 0) {
  3239. tmport -= 0x06;
  3240. mbuf[k++] = inb(tmport);
  3241. tmport += 0x06;
  3242. goto u3p_in1;
  3243. }
  3244. if ((j & 0x80) == 0x00) {
  3245. goto u3p_in1;
  3246. }
  3247. tmport -= 0x08;
  3248. j = inb(tmport) & 0x0f;
  3249. if (j == 0x0f) {
  3250. goto u3p_in;
  3251. }
  3252. if (j == 0x0a) {
  3253. goto u3p_cmd;
  3254. }
  3255. if (j == 0x0e) {
  3256. goto u3p_out;
  3257. }
  3258. continue;
  3259. u3p_cmd:
  3260. tmport = wkport + 0x10;
  3261. outb(0x30, tmport);
  3262. tmport = wkport + 0x14;
  3263. outb(0x00, tmport);
  3264. tmport += 0x04;
  3265. outb(0x08, tmport);
  3266. tmport += 0x07;
  3267. while ((inb(tmport) & 0x80) == 0x00);
  3268. tmport -= 0x08;
  3269. j = inb(tmport);
  3270. if (j != 0x16) {
  3271. if (j == 0x4e) {
  3272. goto u3p_out;
  3273. }
  3274. continue;
  3275. }
  3276. if (mbuf[0] != 0x01) {
  3277. goto chg_wide;
  3278. }
  3279. if (mbuf[1] != 0x06) {
  3280. goto chg_wide;
  3281. }
  3282. if (mbuf[2] != 0x04) {
  3283. goto chg_wide;
  3284. }
  3285. if (mbuf[3] == 0x09) {
  3286. m = 1;
  3287. m = m << i;
  3288. dev->wide_id[c] |= m;
  3289. dev->id[c][i].devsp = 0xce;
  3290. #ifdef ED_DBGP
  3291. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3292. #endif
  3293. continue;
  3294. }
  3295. chg_wide:
  3296. tmport = wkport + 0x1b;
  3297. outb(0x01, tmport);
  3298. tmport = wkport + 0x03;
  3299. outb(satn[0], tmport++);
  3300. outb(satn[1], tmport++);
  3301. outb(satn[2], tmport++);
  3302. outb(satn[3], tmport++);
  3303. outb(satn[4], tmport++);
  3304. outb(satn[5], tmport++);
  3305. tmport += 0x06;
  3306. outb(0, tmport);
  3307. tmport += 0x02;
  3308. outb(dev->id[c][i].devsp, tmport++);
  3309. outb(0, tmport++);
  3310. outb(satn[6], tmport++);
  3311. outb(satn[7], tmport++);
  3312. tmport += 0x03;
  3313. outb(satn[8], tmport);
  3314. tmport += 0x07;
  3315. while ((inb(tmport) & 0x80) == 0x00)
  3316. cpu_relax();
  3317. tmport -= 0x08;
  3318. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3319. continue;
  3320. }
  3321. while (inb(tmport) != 0x8e)
  3322. cpu_relax();
  3323. try_wide:
  3324. j = 0;
  3325. tmport = wkport + 0x14;
  3326. outb(0x05, tmport);
  3327. tmport += 0x04;
  3328. outb(0x20, tmport);
  3329. tmport += 0x07;
  3330. while ((inb(tmport) & 0x80) == 0) {
  3331. if ((inb(tmport) & 0x01) != 0) {
  3332. tmport -= 0x06;
  3333. outb(wide[j++], tmport);
  3334. tmport += 0x06;
  3335. }
  3336. cpu_relax();
  3337. }
  3338. tmport -= 0x08;
  3339. while ((inb(tmport) & 0x80) == 0x00)
  3340. cpu_relax();
  3341. j = inb(tmport) & 0x0f;
  3342. if (j == 0x0f) {
  3343. goto widep_in;
  3344. }
  3345. if (j == 0x0a) {
  3346. goto widep_cmd;
  3347. }
  3348. if (j == 0x0e) {
  3349. goto try_wide;
  3350. }
  3351. continue;
  3352. widep_out:
  3353. tmport = wkport + 0x18;
  3354. outb(0x20, tmport);
  3355. tmport += 0x07;
  3356. while ((inb(tmport) & 0x80) == 0) {
  3357. if ((inb(tmport) & 0x01) != 0) {
  3358. tmport -= 0x06;
  3359. outb(0, tmport);
  3360. tmport += 0x06;
  3361. }
  3362. cpu_relax();
  3363. }
  3364. tmport -= 0x08;
  3365. j = inb(tmport) & 0x0f;
  3366. if (j == 0x0f) {
  3367. goto widep_in;
  3368. }
  3369. if (j == 0x0a) {
  3370. goto widep_cmd;
  3371. }
  3372. if (j == 0x0e) {
  3373. goto widep_out;
  3374. }
  3375. continue;
  3376. widep_in:
  3377. tmport = wkport + 0x14;
  3378. outb(0xff, tmport);
  3379. tmport += 0x04;
  3380. outb(0x20, tmport);
  3381. tmport += 0x07;
  3382. k = 0;
  3383. widep_in1:
  3384. j = inb(tmport);
  3385. if ((j & 0x01) != 0) {
  3386. tmport -= 0x06;
  3387. mbuf[k++] = inb(tmport);
  3388. tmport += 0x06;
  3389. goto widep_in1;
  3390. }
  3391. if ((j & 0x80) == 0x00) {
  3392. goto widep_in1;
  3393. }
  3394. tmport -= 0x08;
  3395. j = inb(tmport) & 0x0f;
  3396. if (j == 0x0f) {
  3397. goto widep_in;
  3398. }
  3399. if (j == 0x0a) {
  3400. goto widep_cmd;
  3401. }
  3402. if (j == 0x0e) {
  3403. goto widep_out;
  3404. }
  3405. continue;
  3406. widep_cmd:
  3407. tmport = wkport + 0x10;
  3408. outb(0x30, tmport);
  3409. tmport = wkport + 0x14;
  3410. outb(0x00, tmport);
  3411. tmport += 0x04;
  3412. outb(0x08, tmport);
  3413. tmport += 0x07;
  3414. while ((inb(tmport) & 0x80) == 0x00)
  3415. cpu_relax();
  3416. tmport -= 0x08;
  3417. j = inb(tmport);
  3418. if (j != 0x16) {
  3419. if (j == 0x4e) {
  3420. goto widep_out;
  3421. }
  3422. continue;
  3423. }
  3424. if (mbuf[0] != 0x01) {
  3425. goto not_wide;
  3426. }
  3427. if (mbuf[1] != 0x02) {
  3428. goto not_wide;
  3429. }
  3430. if (mbuf[2] != 0x03) {
  3431. goto not_wide;
  3432. }
  3433. if (mbuf[3] != 0x01) {
  3434. goto not_wide;
  3435. }
  3436. m = 1;
  3437. m = m << i;
  3438. dev->wide_id[c] |= m;
  3439. not_wide:
  3440. if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) ||
  3441. ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  3442. m = 1;
  3443. m = m << i;
  3444. if ((dev->async[c] & m) != 0) {
  3445. goto set_sync;
  3446. }
  3447. }
  3448. continue;
  3449. set_sync:
  3450. if (dev->sp[c][i] == 0x02) {
  3451. synu[4]=0x0c;
  3452. synuw[4]=0x0c;
  3453. } else {
  3454. if (dev->sp[c][i] >= 0x03) {
  3455. synu[4]=0x0a;
  3456. synuw[4]=0x0a;
  3457. }
  3458. }
  3459. tmport = wkport + 0x1b;
  3460. j = 0;
  3461. if ((m & dev->wide_id[c]) != 0) {
  3462. j |= 0x01;
  3463. }
  3464. outb(j, tmport);
  3465. tmport = wkport + 0x03;
  3466. outb(satn[0], tmport++);
  3467. outb(satn[1], tmport++);
  3468. outb(satn[2], tmport++);
  3469. outb(satn[3], tmport++);
  3470. outb(satn[4], tmport++);
  3471. outb(satn[5], tmport++);
  3472. tmport += 0x06;
  3473. outb(0, tmport);
  3474. tmport += 0x02;
  3475. outb(dev->id[c][i].devsp, tmport++);
  3476. outb(0, tmport++);
  3477. outb(satn[6], tmport++);
  3478. outb(satn[7], tmport++);
  3479. tmport += 0x03;
  3480. outb(satn[8], tmport);
  3481. tmport += 0x07;
  3482. while ((inb(tmport) & 0x80) == 0x00)
  3483. cpu_relax();
  3484. tmport -= 0x08;
  3485. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3486. continue;
  3487. }
  3488. while (inb(tmport) != 0x8e)
  3489. cpu_relax();
  3490. try_sync:
  3491. j = 0;
  3492. tmport = wkport + 0x14;
  3493. outb(0x06, tmport);
  3494. tmport += 0x04;
  3495. outb(0x20, tmport);
  3496. tmport += 0x07;
  3497. while ((inb(tmport) & 0x80) == 0) {
  3498. if ((inb(tmport) & 0x01) != 0) {
  3499. tmport -= 0x06;
  3500. if ((m & dev->wide_id[c]) != 0) {
  3501. if ((m & dev->ultra_map[c]) != 0) {
  3502. outb(synuw[j++], tmport);
  3503. } else {
  3504. outb(synw[j++], tmport);
  3505. }
  3506. } else {
  3507. if ((m & dev->ultra_map[c]) != 0) {
  3508. outb(synu[j++], tmport);
  3509. } else {
  3510. outb(synn[j++], tmport);
  3511. }
  3512. }
  3513. tmport += 0x06;
  3514. }
  3515. }
  3516. tmport -= 0x08;
  3517. while ((inb(tmport) & 0x80) == 0x00)
  3518. cpu_relax();
  3519. j = inb(tmport) & 0x0f;
  3520. if (j == 0x0f) {
  3521. goto phase_ins;
  3522. }
  3523. if (j == 0x0a) {
  3524. goto phase_cmds;
  3525. }
  3526. if (j == 0x0e) {
  3527. goto try_sync;
  3528. }
  3529. continue;
  3530. phase_outs:
  3531. tmport = wkport + 0x18;
  3532. outb(0x20, tmport);
  3533. tmport += 0x07;
  3534. while ((inb(tmport) & 0x80) == 0x00) {
  3535. if ((inb(tmport) & 0x01) != 0x00) {
  3536. tmport -= 0x06;
  3537. outb(0x00, tmport);
  3538. tmport += 0x06;
  3539. }
  3540. cpu_relax();
  3541. }
  3542. tmport -= 0x08;
  3543. j = inb(tmport);
  3544. if (j == 0x85) {
  3545. goto tar_dcons;
  3546. }
  3547. j &= 0x0f;
  3548. if (j == 0x0f) {
  3549. goto phase_ins;
  3550. }
  3551. if (j == 0x0a) {
  3552. goto phase_cmds;
  3553. }
  3554. if (j == 0x0e) {
  3555. goto phase_outs;
  3556. }
  3557. continue;
  3558. phase_ins:
  3559. tmport = wkport + 0x14;
  3560. outb(0x06, tmport);
  3561. tmport += 0x04;
  3562. outb(0x20, tmport);
  3563. tmport += 0x07;
  3564. k = 0;
  3565. phase_ins1:
  3566. j = inb(tmport);
  3567. if ((j & 0x01) != 0x00) {
  3568. tmport -= 0x06;
  3569. mbuf[k++] = inb(tmport);
  3570. tmport += 0x06;
  3571. goto phase_ins1;
  3572. }
  3573. if ((j & 0x80) == 0x00) {
  3574. goto phase_ins1;
  3575. }
  3576. tmport -= 0x08;
  3577. while ((inb(tmport) & 0x80) == 0x00);
  3578. j = inb(tmport);
  3579. if (j == 0x85) {
  3580. goto tar_dcons;
  3581. }
  3582. j &= 0x0f;
  3583. if (j == 0x0f) {
  3584. goto phase_ins;
  3585. }
  3586. if (j == 0x0a) {
  3587. goto phase_cmds;
  3588. }
  3589. if (j == 0x0e) {
  3590. goto phase_outs;
  3591. }
  3592. continue;
  3593. phase_cmds:
  3594. tmport = wkport + 0x10;
  3595. outb(0x30, tmport);
  3596. tar_dcons:
  3597. tmport = wkport + 0x14;
  3598. outb(0x00, tmport);
  3599. tmport += 0x04;
  3600. outb(0x08, tmport);
  3601. tmport += 0x07;
  3602. while ((inb(tmport) & 0x80) == 0x00)
  3603. cpu_relax();
  3604. tmport -= 0x08;
  3605. j = inb(tmport);
  3606. if (j != 0x16) {
  3607. continue;
  3608. }
  3609. if (mbuf[0] != 0x01) {
  3610. continue;
  3611. }
  3612. if (mbuf[1] != 0x03) {
  3613. continue;
  3614. }
  3615. if (mbuf[4] == 0x00) {
  3616. continue;
  3617. }
  3618. if (mbuf[3] > 0x64) {
  3619. continue;
  3620. }
  3621. if (mbuf[4] > 0x0e) {
  3622. mbuf[4] = 0x0e;
  3623. }
  3624. dev->id[c][i].devsp = mbuf[4];
  3625. if (mbuf[3] < 0x0c){
  3626. j = 0xb0;
  3627. goto set_syn_ok;
  3628. }
  3629. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  3630. j = 0xa0;
  3631. goto set_syn_ok;
  3632. }
  3633. if (mbuf[3] < 0x1a) {
  3634. j = 0x20;
  3635. goto set_syn_ok;
  3636. }
  3637. if (mbuf[3] < 0x33) {
  3638. j = 0x40;
  3639. goto set_syn_ok;
  3640. }
  3641. if (mbuf[3] < 0x4c) {
  3642. j = 0x50;
  3643. goto set_syn_ok;
  3644. }
  3645. j = 0x60;
  3646. set_syn_ok:
  3647. dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
  3648. #ifdef ED_DBGP
  3649. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3650. #endif
  3651. }
  3652. tmport = wkport + 0x16;
  3653. outb(0x80, tmport);
  3654. }
  3655. module_init(atp870u_init);
  3656. module_exit(atp870u_exit);