atp870u.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915
  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. udelay(0x800);
  1116. if ((inb(tmport) & 0x80) == 0x00) { /* bsy ? */
  1117. outw(0, tmport--);
  1118. outb(0, tmport);
  1119. tmport = dev->ioport[0] + 0x15;
  1120. outb(0, tmport);
  1121. tmport += 0x03;
  1122. outb(0x09, tmport);
  1123. tmport += 0x07;
  1124. while ((inb(tmport) & 0x80) == 0)
  1125. cpu_relax();
  1126. tmport -= 0x08;
  1127. inb(tmport);
  1128. return;
  1129. }
  1130. val &= 0x00ff; /* synchronization */
  1131. val |= 0x3f00;
  1132. fun_scam(dev, &val);
  1133. outb(3, 0x80);
  1134. val &= 0x00ff; /* isolation */
  1135. val |= 0x2000;
  1136. fun_scam(dev, &val);
  1137. outb(4, 0x80);
  1138. i = 8;
  1139. j = 0;
  1140. TCM_ID:
  1141. if ((inw(tmport) & 0x2000) == 0) {
  1142. goto TCM_ID;
  1143. }
  1144. outb(5, 0x80);
  1145. val &= 0x00ff; /* get ID_STRING */
  1146. val |= 0x2000;
  1147. k = fun_scam(dev, &val);
  1148. if ((k & 0x03) == 0) {
  1149. goto TCM_5;
  1150. }
  1151. mbuf[j] <<= 0x01;
  1152. mbuf[j] &= 0xfe;
  1153. if ((k & 0x02) != 0) {
  1154. mbuf[j] |= 0x01;
  1155. }
  1156. i--;
  1157. if (i > 0) {
  1158. goto TCM_ID;
  1159. }
  1160. j++;
  1161. i = 8;
  1162. goto TCM_ID;
  1163. TCM_5: /* isolation complete.. */
  1164. /* mbuf[32]=0;
  1165. printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
  1166. i = 15;
  1167. j = mbuf[0];
  1168. if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */
  1169. i = 7;
  1170. }
  1171. if ((j & 0x06) == 0) { /* IDvalid? */
  1172. goto G2Q5;
  1173. }
  1174. k = mbuf[1];
  1175. small_id:
  1176. m = 1;
  1177. m <<= k;
  1178. if ((m & assignid_map) == 0) {
  1179. goto G2Q_QUIN;
  1180. }
  1181. if (k > 0) {
  1182. k--;
  1183. goto small_id;
  1184. }
  1185. G2Q5: /* srch from max acceptable ID# */
  1186. k = i; /* max acceptable ID# */
  1187. G2Q_LP:
  1188. m = 1;
  1189. m <<= k;
  1190. if ((m & assignid_map) == 0) {
  1191. goto G2Q_QUIN;
  1192. }
  1193. if (k > 0) {
  1194. k--;
  1195. goto G2Q_LP;
  1196. }
  1197. G2Q_QUIN: /* k=binID#, */
  1198. assignid_map |= m;
  1199. if (k < 8) {
  1200. quintet[0] = 0x38; /* 1st dft ID<8 */
  1201. } else {
  1202. quintet[0] = 0x31; /* 1st ID>=8 */
  1203. }
  1204. k &= 0x07;
  1205. quintet[1] = g2q_tab[k];
  1206. val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
  1207. m = quintet[0] << 8;
  1208. val |= m;
  1209. fun_scam(dev, &val);
  1210. val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
  1211. m = quintet[1] << 8;
  1212. val |= m;
  1213. fun_scam(dev, &val);
  1214. goto TCM_SYNC;
  1215. }
  1216. static void is870(struct atp_unit *dev, unsigned int wkport)
  1217. {
  1218. unsigned int tmport;
  1219. unsigned char i, j, k, rmb, n;
  1220. unsigned short int m;
  1221. static unsigned char mbuf[512];
  1222. static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
  1223. static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
  1224. static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1225. static unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
  1226. static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
  1227. static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
  1228. tmport = wkport + 0x3a;
  1229. outb((unsigned char) (inb(tmport) | 0x10), tmport);
  1230. for (i = 0; i < 16; i++) {
  1231. if ((dev->chip_ver != 4) && (i > 7)) {
  1232. break;
  1233. }
  1234. m = 1;
  1235. m = m << i;
  1236. if ((m & dev->active_id[0]) != 0) {
  1237. continue;
  1238. }
  1239. if (i == dev->host_id[0]) {
  1240. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
  1241. continue;
  1242. }
  1243. tmport = wkport + 0x1b;
  1244. if (dev->chip_ver == 4) {
  1245. outb(0x01, tmport);
  1246. } else {
  1247. outb(0x00, tmport);
  1248. }
  1249. tmport = wkport + 1;
  1250. outb(0x08, tmport++);
  1251. outb(0x7f, tmport++);
  1252. outb(satn[0], tmport++);
  1253. outb(satn[1], tmport++);
  1254. outb(satn[2], tmport++);
  1255. outb(satn[3], tmport++);
  1256. outb(satn[4], tmport++);
  1257. outb(satn[5], tmport++);
  1258. tmport += 0x06;
  1259. outb(0, tmport);
  1260. tmport += 0x02;
  1261. outb(dev->id[0][i].devsp, tmport++);
  1262. outb(0, tmport++);
  1263. outb(satn[6], tmport++);
  1264. outb(satn[7], tmport++);
  1265. j = i;
  1266. if ((j & 0x08) != 0) {
  1267. j = (j & 0x07) | 0x40;
  1268. }
  1269. outb(j, tmport);
  1270. tmport += 0x03;
  1271. outb(satn[8], tmport);
  1272. tmport += 0x07;
  1273. while ((inb(tmport) & 0x80) == 0x00)
  1274. cpu_relax();
  1275. tmport -= 0x08;
  1276. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1277. continue;
  1278. while (inb(tmport) != 0x8e)
  1279. cpu_relax();
  1280. dev->active_id[0] |= m;
  1281. tmport = wkport + 0x10;
  1282. outb(0x30, tmport);
  1283. tmport = wkport + 0x04;
  1284. outb(0x00, tmport);
  1285. phase_cmd:
  1286. tmport = wkport + 0x18;
  1287. outb(0x08, tmport);
  1288. tmport += 0x07;
  1289. while ((inb(tmport) & 0x80) == 0x00)
  1290. cpu_relax();
  1291. tmport -= 0x08;
  1292. j = inb(tmport);
  1293. if (j != 0x16) {
  1294. tmport = wkport + 0x10;
  1295. outb(0x41, tmport);
  1296. goto phase_cmd;
  1297. }
  1298. sel_ok:
  1299. tmport = wkport + 3;
  1300. outb(inqd[0], tmport++);
  1301. outb(inqd[1], tmport++);
  1302. outb(inqd[2], tmport++);
  1303. outb(inqd[3], tmport++);
  1304. outb(inqd[4], tmport++);
  1305. outb(inqd[5], tmport);
  1306. tmport += 0x07;
  1307. outb(0, tmport);
  1308. tmport += 0x02;
  1309. outb(dev->id[0][i].devsp, tmport++);
  1310. outb(0, tmport++);
  1311. outb(inqd[6], tmport++);
  1312. outb(inqd[7], tmport++);
  1313. tmport += 0x03;
  1314. outb(inqd[8], tmport);
  1315. tmport += 0x07;
  1316. while ((inb(tmport) & 0x80) == 0x00)
  1317. cpu_relax();
  1318. tmport -= 0x08;
  1319. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1320. continue;
  1321. while (inb(tmport) != 0x8e)
  1322. cpu_relax();
  1323. tmport = wkport + 0x1b;
  1324. if (dev->chip_ver == 4)
  1325. outb(0x00, tmport);
  1326. tmport = wkport + 0x18;
  1327. outb(0x08, tmport);
  1328. tmport += 0x07;
  1329. j = 0;
  1330. rd_inq_data:
  1331. k = inb(tmport);
  1332. if ((k & 0x01) != 0) {
  1333. tmport -= 0x06;
  1334. mbuf[j++] = inb(tmport);
  1335. tmport += 0x06;
  1336. goto rd_inq_data;
  1337. }
  1338. if ((k & 0x80) == 0) {
  1339. goto rd_inq_data;
  1340. }
  1341. tmport -= 0x08;
  1342. j = inb(tmport);
  1343. if (j == 0x16) {
  1344. goto inq_ok;
  1345. }
  1346. tmport = wkport + 0x10;
  1347. outb(0x46, tmport);
  1348. tmport += 0x02;
  1349. outb(0, tmport++);
  1350. outb(0, tmport++);
  1351. outb(0, tmport++);
  1352. tmport += 0x03;
  1353. outb(0x08, tmport);
  1354. tmport += 0x07;
  1355. while ((inb(tmport) & 0x80) == 0x00)
  1356. cpu_relax();
  1357. tmport -= 0x08;
  1358. if (inb(tmport) != 0x16) {
  1359. goto sel_ok;
  1360. }
  1361. inq_ok:
  1362. mbuf[36] = 0;
  1363. printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
  1364. dev->id[0][i].devtype = mbuf[0];
  1365. rmb = mbuf[1];
  1366. n = mbuf[7];
  1367. if (dev->chip_ver != 4) {
  1368. goto not_wide;
  1369. }
  1370. if ((mbuf[7] & 0x60) == 0) {
  1371. goto not_wide;
  1372. }
  1373. if ((dev->global_map[0] & 0x20) == 0) {
  1374. goto not_wide;
  1375. }
  1376. tmport = wkport + 0x1b;
  1377. outb(0x01, tmport);
  1378. tmport = wkport + 3;
  1379. outb(satn[0], tmport++);
  1380. outb(satn[1], tmport++);
  1381. outb(satn[2], tmport++);
  1382. outb(satn[3], tmport++);
  1383. outb(satn[4], tmport++);
  1384. outb(satn[5], tmport++);
  1385. tmport += 0x06;
  1386. outb(0, tmport);
  1387. tmport += 0x02;
  1388. outb(dev->id[0][i].devsp, tmport++);
  1389. outb(0, tmport++);
  1390. outb(satn[6], tmport++);
  1391. outb(satn[7], tmport++);
  1392. tmport += 0x03;
  1393. outb(satn[8], tmport);
  1394. tmport += 0x07;
  1395. while ((inb(tmport) & 0x80) == 0x00)
  1396. cpu_relax();
  1397. tmport -= 0x08;
  1398. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1399. continue;
  1400. while (inb(tmport) != 0x8e)
  1401. cpu_relax();
  1402. try_wide:
  1403. j = 0;
  1404. tmport = wkport + 0x14;
  1405. outb(0x05, tmport);
  1406. tmport += 0x04;
  1407. outb(0x20, tmport);
  1408. tmport += 0x07;
  1409. while ((inb(tmport) & 0x80) == 0) {
  1410. if ((inb(tmport) & 0x01) != 0) {
  1411. tmport -= 0x06;
  1412. outb(wide[j++], tmport);
  1413. tmport += 0x06;
  1414. }
  1415. }
  1416. tmport -= 0x08;
  1417. while ((inb(tmport) & 0x80) == 0x00)
  1418. cpu_relax();
  1419. j = inb(tmport) & 0x0f;
  1420. if (j == 0x0f) {
  1421. goto widep_in;
  1422. }
  1423. if (j == 0x0a) {
  1424. goto widep_cmd;
  1425. }
  1426. if (j == 0x0e) {
  1427. goto try_wide;
  1428. }
  1429. continue;
  1430. widep_out:
  1431. tmport = wkport + 0x18;
  1432. outb(0x20, tmport);
  1433. tmport += 0x07;
  1434. while ((inb(tmport) & 0x80) == 0) {
  1435. if ((inb(tmport) & 0x01) != 0) {
  1436. tmport -= 0x06;
  1437. outb(0, tmport);
  1438. tmport += 0x06;
  1439. }
  1440. }
  1441. tmport -= 0x08;
  1442. j = inb(tmport) & 0x0f;
  1443. if (j == 0x0f) {
  1444. goto widep_in;
  1445. }
  1446. if (j == 0x0a) {
  1447. goto widep_cmd;
  1448. }
  1449. if (j == 0x0e) {
  1450. goto widep_out;
  1451. }
  1452. continue;
  1453. widep_in:
  1454. tmport = wkport + 0x14;
  1455. outb(0xff, tmport);
  1456. tmport += 0x04;
  1457. outb(0x20, tmport);
  1458. tmport += 0x07;
  1459. k = 0;
  1460. widep_in1:
  1461. j = inb(tmport);
  1462. if ((j & 0x01) != 0) {
  1463. tmport -= 0x06;
  1464. mbuf[k++] = inb(tmport);
  1465. tmport += 0x06;
  1466. goto widep_in1;
  1467. }
  1468. if ((j & 0x80) == 0x00) {
  1469. goto widep_in1;
  1470. }
  1471. tmport -= 0x08;
  1472. j = inb(tmport) & 0x0f;
  1473. if (j == 0x0f) {
  1474. goto widep_in;
  1475. }
  1476. if (j == 0x0a) {
  1477. goto widep_cmd;
  1478. }
  1479. if (j == 0x0e) {
  1480. goto widep_out;
  1481. }
  1482. continue;
  1483. widep_cmd:
  1484. tmport = wkport + 0x10;
  1485. outb(0x30, tmport);
  1486. tmport = wkport + 0x14;
  1487. outb(0x00, tmport);
  1488. tmport += 0x04;
  1489. outb(0x08, tmport);
  1490. tmport += 0x07;
  1491. while ((inb(tmport) & 0x80) == 0x00)
  1492. cpu_relax();
  1493. tmport -= 0x08;
  1494. j = inb(tmport);
  1495. if (j != 0x16) {
  1496. if (j == 0x4e) {
  1497. goto widep_out;
  1498. }
  1499. continue;
  1500. }
  1501. if (mbuf[0] != 0x01) {
  1502. goto not_wide;
  1503. }
  1504. if (mbuf[1] != 0x02) {
  1505. goto not_wide;
  1506. }
  1507. if (mbuf[2] != 0x03) {
  1508. goto not_wide;
  1509. }
  1510. if (mbuf[3] != 0x01) {
  1511. goto not_wide;
  1512. }
  1513. m = 1;
  1514. m = m << i;
  1515. dev->wide_id[0] |= m;
  1516. not_wide:
  1517. if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  1518. goto set_sync;
  1519. }
  1520. continue;
  1521. set_sync:
  1522. tmport = wkport + 0x1b;
  1523. j = 0;
  1524. if ((m & dev->wide_id[0]) != 0) {
  1525. j |= 0x01;
  1526. }
  1527. outb(j, tmport);
  1528. tmport = wkport + 3;
  1529. outb(satn[0], tmport++);
  1530. outb(satn[1], tmport++);
  1531. outb(satn[2], tmport++);
  1532. outb(satn[3], tmport++);
  1533. outb(satn[4], tmport++);
  1534. outb(satn[5], tmport++);
  1535. tmport += 0x06;
  1536. outb(0, tmport);
  1537. tmport += 0x02;
  1538. outb(dev->id[0][i].devsp, tmport++);
  1539. outb(0, tmport++);
  1540. outb(satn[6], tmport++);
  1541. outb(satn[7], tmport++);
  1542. tmport += 0x03;
  1543. outb(satn[8], tmport);
  1544. tmport += 0x07;
  1545. while ((inb(tmport) & 0x80) == 0x00)
  1546. cpu_relax();
  1547. tmport -= 0x08;
  1548. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1549. continue;
  1550. while (inb(tmport) != 0x8e)
  1551. cpu_relax();
  1552. try_sync:
  1553. j = 0;
  1554. tmport = wkport + 0x14;
  1555. outb(0x06, tmport);
  1556. tmport += 0x04;
  1557. outb(0x20, tmport);
  1558. tmport += 0x07;
  1559. while ((inb(tmport) & 0x80) == 0) {
  1560. if ((inb(tmport) & 0x01) != 0) {
  1561. tmport -= 0x06;
  1562. if ((m & dev->wide_id[0]) != 0) {
  1563. outb(synw[j++], tmport);
  1564. } else {
  1565. if ((m & dev->ultra_map[0]) != 0) {
  1566. outb(synu[j++], tmport);
  1567. } else {
  1568. outb(synn[j++], tmport);
  1569. }
  1570. }
  1571. tmport += 0x06;
  1572. }
  1573. }
  1574. tmport -= 0x08;
  1575. while ((inb(tmport) & 0x80) == 0x00)
  1576. cpu_relax();
  1577. j = inb(tmport) & 0x0f;
  1578. if (j == 0x0f) {
  1579. goto phase_ins;
  1580. }
  1581. if (j == 0x0a) {
  1582. goto phase_cmds;
  1583. }
  1584. if (j == 0x0e) {
  1585. goto try_sync;
  1586. }
  1587. continue;
  1588. phase_outs:
  1589. tmport = wkport + 0x18;
  1590. outb(0x20, tmport);
  1591. tmport += 0x07;
  1592. while ((inb(tmport) & 0x80) == 0x00) {
  1593. if ((inb(tmport) & 0x01) != 0x00) {
  1594. tmport -= 0x06;
  1595. outb(0x00, tmport);
  1596. tmport += 0x06;
  1597. }
  1598. }
  1599. tmport -= 0x08;
  1600. j = inb(tmport);
  1601. if (j == 0x85) {
  1602. goto tar_dcons;
  1603. }
  1604. j &= 0x0f;
  1605. if (j == 0x0f) {
  1606. goto phase_ins;
  1607. }
  1608. if (j == 0x0a) {
  1609. goto phase_cmds;
  1610. }
  1611. if (j == 0x0e) {
  1612. goto phase_outs;
  1613. }
  1614. continue;
  1615. phase_ins:
  1616. tmport = wkport + 0x14;
  1617. outb(0xff, tmport);
  1618. tmport += 0x04;
  1619. outb(0x20, tmport);
  1620. tmport += 0x07;
  1621. k = 0;
  1622. phase_ins1:
  1623. j = inb(tmport);
  1624. if ((j & 0x01) != 0x00) {
  1625. tmport -= 0x06;
  1626. mbuf[k++] = inb(tmport);
  1627. tmport += 0x06;
  1628. goto phase_ins1;
  1629. }
  1630. if ((j & 0x80) == 0x00) {
  1631. goto phase_ins1;
  1632. }
  1633. tmport -= 0x08;
  1634. while ((inb(tmport) & 0x80) == 0x00)
  1635. cpu_relax();
  1636. j = inb(tmport);
  1637. if (j == 0x85) {
  1638. goto tar_dcons;
  1639. }
  1640. j &= 0x0f;
  1641. if (j == 0x0f) {
  1642. goto phase_ins;
  1643. }
  1644. if (j == 0x0a) {
  1645. goto phase_cmds;
  1646. }
  1647. if (j == 0x0e) {
  1648. goto phase_outs;
  1649. }
  1650. continue;
  1651. phase_cmds:
  1652. tmport = wkport + 0x10;
  1653. outb(0x30, tmport);
  1654. tar_dcons:
  1655. tmport = wkport + 0x14;
  1656. outb(0x00, tmport);
  1657. tmport += 0x04;
  1658. outb(0x08, tmport);
  1659. tmport += 0x07;
  1660. while ((inb(tmport) & 0x80) == 0x00)
  1661. cpu_relax();
  1662. tmport -= 0x08;
  1663. j = inb(tmport);
  1664. if (j != 0x16) {
  1665. continue;
  1666. }
  1667. if (mbuf[0] != 0x01) {
  1668. continue;
  1669. }
  1670. if (mbuf[1] != 0x03) {
  1671. continue;
  1672. }
  1673. if (mbuf[4] == 0x00) {
  1674. continue;
  1675. }
  1676. if (mbuf[3] > 0x64) {
  1677. continue;
  1678. }
  1679. if (mbuf[4] > 0x0c) {
  1680. mbuf[4] = 0x0c;
  1681. }
  1682. dev->id[0][i].devsp = mbuf[4];
  1683. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  1684. j = 0xa0;
  1685. goto set_syn_ok;
  1686. }
  1687. if (mbuf[3] < 0x1a) {
  1688. j = 0x20;
  1689. goto set_syn_ok;
  1690. }
  1691. if (mbuf[3] < 0x33) {
  1692. j = 0x40;
  1693. goto set_syn_ok;
  1694. }
  1695. if (mbuf[3] < 0x4c) {
  1696. j = 0x50;
  1697. goto set_syn_ok;
  1698. }
  1699. j = 0x60;
  1700. set_syn_ok:
  1701. dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
  1702. }
  1703. tmport = wkport + 0x3a;
  1704. outb((unsigned char) (inb(tmport) & 0xef), tmport);
  1705. }
  1706. static void is880(struct atp_unit *dev, unsigned int wkport)
  1707. {
  1708. unsigned int tmport;
  1709. unsigned char i, j, k, rmb, n, lvdmode;
  1710. unsigned short int m;
  1711. static unsigned char mbuf[512];
  1712. static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
  1713. static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
  1714. static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1715. unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
  1716. static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
  1717. unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
  1718. static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
  1719. static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
  1720. lvdmode = inb(wkport + 0x3f) & 0x40;
  1721. for (i = 0; i < 16; i++) {
  1722. m = 1;
  1723. m = m << i;
  1724. if ((m & dev->active_id[0]) != 0) {
  1725. continue;
  1726. }
  1727. if (i == dev->host_id[0]) {
  1728. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
  1729. continue;
  1730. }
  1731. tmport = wkport + 0x5b;
  1732. outb(0x01, tmport);
  1733. tmport = wkport + 0x41;
  1734. outb(0x08, tmport++);
  1735. outb(0x7f, tmport++);
  1736. outb(satn[0], tmport++);
  1737. outb(satn[1], tmport++);
  1738. outb(satn[2], tmport++);
  1739. outb(satn[3], tmport++);
  1740. outb(satn[4], tmport++);
  1741. outb(satn[5], tmport++);
  1742. tmport += 0x06;
  1743. outb(0, tmport);
  1744. tmport += 0x02;
  1745. outb(dev->id[0][i].devsp, tmport++);
  1746. outb(0, tmport++);
  1747. outb(satn[6], tmport++);
  1748. outb(satn[7], tmport++);
  1749. j = i;
  1750. if ((j & 0x08) != 0) {
  1751. j = (j & 0x07) | 0x40;
  1752. }
  1753. outb(j, tmport);
  1754. tmport += 0x03;
  1755. outb(satn[8], tmport);
  1756. tmport += 0x07;
  1757. while ((inb(tmport) & 0x80) == 0x00)
  1758. cpu_relax();
  1759. tmport -= 0x08;
  1760. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1761. continue;
  1762. while (inb(tmport) != 0x8e)
  1763. cpu_relax();
  1764. dev->active_id[0] |= m;
  1765. tmport = wkport + 0x50;
  1766. outb(0x30, tmport);
  1767. tmport = wkport + 0x54;
  1768. outb(0x00, tmport);
  1769. phase_cmd:
  1770. tmport = wkport + 0x58;
  1771. outb(0x08, tmport);
  1772. tmport += 0x07;
  1773. while ((inb(tmport) & 0x80) == 0x00)
  1774. cpu_relax();
  1775. tmport -= 0x08;
  1776. j = inb(tmport);
  1777. if (j != 0x16) {
  1778. tmport = wkport + 0x50;
  1779. outb(0x41, tmport);
  1780. goto phase_cmd;
  1781. }
  1782. sel_ok:
  1783. tmport = wkport + 0x43;
  1784. outb(inqd[0], tmport++);
  1785. outb(inqd[1], tmport++);
  1786. outb(inqd[2], tmport++);
  1787. outb(inqd[3], tmport++);
  1788. outb(inqd[4], tmport++);
  1789. outb(inqd[5], tmport);
  1790. tmport += 0x07;
  1791. outb(0, tmport);
  1792. tmport += 0x02;
  1793. outb(dev->id[0][i].devsp, tmport++);
  1794. outb(0, tmport++);
  1795. outb(inqd[6], tmport++);
  1796. outb(inqd[7], tmport++);
  1797. tmport += 0x03;
  1798. outb(inqd[8], tmport);
  1799. tmport += 0x07;
  1800. while ((inb(tmport) & 0x80) == 0x00)
  1801. cpu_relax();
  1802. tmport -= 0x08;
  1803. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1804. continue;
  1805. while (inb(tmport) != 0x8e)
  1806. cpu_relax();
  1807. tmport = wkport + 0x5b;
  1808. outb(0x00, tmport);
  1809. tmport = wkport + 0x58;
  1810. outb(0x08, tmport);
  1811. tmport += 0x07;
  1812. j = 0;
  1813. rd_inq_data:
  1814. k = inb(tmport);
  1815. if ((k & 0x01) != 0) {
  1816. tmport -= 0x06;
  1817. mbuf[j++] = inb(tmport);
  1818. tmport += 0x06;
  1819. goto rd_inq_data;
  1820. }
  1821. if ((k & 0x80) == 0) {
  1822. goto rd_inq_data;
  1823. }
  1824. tmport -= 0x08;
  1825. j = inb(tmport);
  1826. if (j == 0x16) {
  1827. goto inq_ok;
  1828. }
  1829. tmport = wkport + 0x50;
  1830. outb(0x46, tmport);
  1831. tmport += 0x02;
  1832. outb(0, tmport++);
  1833. outb(0, tmport++);
  1834. outb(0, tmport++);
  1835. tmport += 0x03;
  1836. outb(0x08, tmport);
  1837. tmport += 0x07;
  1838. while ((inb(tmport) & 0x80) == 0x00)
  1839. cpu_relax();
  1840. tmport -= 0x08;
  1841. if (inb(tmport) != 0x16)
  1842. goto sel_ok;
  1843. inq_ok:
  1844. mbuf[36] = 0;
  1845. printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
  1846. dev->id[0][i].devtype = mbuf[0];
  1847. rmb = mbuf[1];
  1848. n = mbuf[7];
  1849. if ((mbuf[7] & 0x60) == 0) {
  1850. goto not_wide;
  1851. }
  1852. if ((i < 8) && ((dev->global_map[0] & 0x20) == 0)) {
  1853. goto not_wide;
  1854. }
  1855. if (lvdmode == 0) {
  1856. goto chg_wide;
  1857. }
  1858. if (dev->sp[0][i] != 0x04) // force u2
  1859. {
  1860. goto chg_wide;
  1861. }
  1862. tmport = wkport + 0x5b;
  1863. outb(0x01, tmport);
  1864. tmport = wkport + 0x43;
  1865. outb(satn[0], tmport++);
  1866. outb(satn[1], tmport++);
  1867. outb(satn[2], tmport++);
  1868. outb(satn[3], tmport++);
  1869. outb(satn[4], tmport++);
  1870. outb(satn[5], tmport++);
  1871. tmport += 0x06;
  1872. outb(0, tmport);
  1873. tmport += 0x02;
  1874. outb(dev->id[0][i].devsp, tmport++);
  1875. outb(0, tmport++);
  1876. outb(satn[6], tmport++);
  1877. outb(satn[7], tmport++);
  1878. tmport += 0x03;
  1879. outb(satn[8], tmport);
  1880. tmport += 0x07;
  1881. while ((inb(tmport) & 0x80) == 0x00)
  1882. cpu_relax();
  1883. tmport -= 0x08;
  1884. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  1885. continue;
  1886. while (inb(tmport) != 0x8e)
  1887. cpu_relax();
  1888. try_u3:
  1889. j = 0;
  1890. tmport = wkport + 0x54;
  1891. outb(0x09, tmport);
  1892. tmport += 0x04;
  1893. outb(0x20, tmport);
  1894. tmport += 0x07;
  1895. while ((inb(tmport) & 0x80) == 0) {
  1896. if ((inb(tmport) & 0x01) != 0) {
  1897. tmport -= 0x06;
  1898. outb(u3[j++], tmport);
  1899. tmport += 0x06;
  1900. }
  1901. }
  1902. tmport -= 0x08;
  1903. while ((inb(tmport) & 0x80) == 0x00)
  1904. cpu_relax();
  1905. j = inb(tmport) & 0x0f;
  1906. if (j == 0x0f) {
  1907. goto u3p_in;
  1908. }
  1909. if (j == 0x0a) {
  1910. goto u3p_cmd;
  1911. }
  1912. if (j == 0x0e) {
  1913. goto try_u3;
  1914. }
  1915. continue;
  1916. u3p_out:
  1917. tmport = wkport + 0x58;
  1918. outb(0x20, tmport);
  1919. tmport += 0x07;
  1920. while ((inb(tmport) & 0x80) == 0) {
  1921. if ((inb(tmport) & 0x01) != 0) {
  1922. tmport -= 0x06;
  1923. outb(0, tmport);
  1924. tmport += 0x06;
  1925. }
  1926. }
  1927. tmport -= 0x08;
  1928. j = inb(tmport) & 0x0f;
  1929. if (j == 0x0f) {
  1930. goto u3p_in;
  1931. }
  1932. if (j == 0x0a) {
  1933. goto u3p_cmd;
  1934. }
  1935. if (j == 0x0e) {
  1936. goto u3p_out;
  1937. }
  1938. continue;
  1939. u3p_in:
  1940. tmport = wkport + 0x54;
  1941. outb(0x09, tmport);
  1942. tmport += 0x04;
  1943. outb(0x20, tmport);
  1944. tmport += 0x07;
  1945. k = 0;
  1946. u3p_in1:
  1947. j = inb(tmport);
  1948. if ((j & 0x01) != 0) {
  1949. tmport -= 0x06;
  1950. mbuf[k++] = inb(tmport);
  1951. tmport += 0x06;
  1952. goto u3p_in1;
  1953. }
  1954. if ((j & 0x80) == 0x00) {
  1955. goto u3p_in1;
  1956. }
  1957. tmport -= 0x08;
  1958. j = inb(tmport) & 0x0f;
  1959. if (j == 0x0f) {
  1960. goto u3p_in;
  1961. }
  1962. if (j == 0x0a) {
  1963. goto u3p_cmd;
  1964. }
  1965. if (j == 0x0e) {
  1966. goto u3p_out;
  1967. }
  1968. continue;
  1969. u3p_cmd:
  1970. tmport = wkport + 0x50;
  1971. outb(0x30, tmport);
  1972. tmport = wkport + 0x54;
  1973. outb(0x00, tmport);
  1974. tmport += 0x04;
  1975. outb(0x08, tmport);
  1976. tmport += 0x07;
  1977. while ((inb(tmport) & 0x80) == 0x00)
  1978. cpu_relax();
  1979. tmport -= 0x08;
  1980. j = inb(tmport);
  1981. if (j != 0x16) {
  1982. if (j == 0x4e) {
  1983. goto u3p_out;
  1984. }
  1985. continue;
  1986. }
  1987. if (mbuf[0] != 0x01) {
  1988. goto chg_wide;
  1989. }
  1990. if (mbuf[1] != 0x06) {
  1991. goto chg_wide;
  1992. }
  1993. if (mbuf[2] != 0x04) {
  1994. goto chg_wide;
  1995. }
  1996. if (mbuf[3] == 0x09) {
  1997. m = 1;
  1998. m = m << i;
  1999. dev->wide_id[0] |= m;
  2000. dev->id[0][i].devsp = 0xce;
  2001. continue;
  2002. }
  2003. chg_wide:
  2004. tmport = wkport + 0x5b;
  2005. outb(0x01, tmport);
  2006. tmport = wkport + 0x43;
  2007. outb(satn[0], tmport++);
  2008. outb(satn[1], tmport++);
  2009. outb(satn[2], tmport++);
  2010. outb(satn[3], tmport++);
  2011. outb(satn[4], tmport++);
  2012. outb(satn[5], tmport++);
  2013. tmport += 0x06;
  2014. outb(0, tmport);
  2015. tmport += 0x02;
  2016. outb(dev->id[0][i].devsp, tmport++);
  2017. outb(0, tmport++);
  2018. outb(satn[6], tmport++);
  2019. outb(satn[7], tmport++);
  2020. tmport += 0x03;
  2021. outb(satn[8], tmport);
  2022. tmport += 0x07;
  2023. while ((inb(tmport) & 0x80) == 0x00)
  2024. cpu_relax();
  2025. tmport -= 0x08;
  2026. if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
  2027. continue;
  2028. while (inb(tmport) != 0x8e)
  2029. cpu_relax();
  2030. try_wide:
  2031. j = 0;
  2032. tmport = wkport + 0x54;
  2033. outb(0x05, tmport);
  2034. tmport += 0x04;
  2035. outb(0x20, tmport);
  2036. tmport += 0x07;
  2037. while ((inb(tmport) & 0x80) == 0) {
  2038. if ((inb(tmport) & 0x01) != 0) {
  2039. tmport -= 0x06;
  2040. outb(wide[j++], tmport);
  2041. tmport += 0x06;
  2042. }
  2043. }
  2044. tmport -= 0x08;
  2045. while ((inb(tmport) & 0x80) == 0x00)
  2046. cpu_relax();
  2047. j = inb(tmport) & 0x0f;
  2048. if (j == 0x0f) {
  2049. goto widep_in;
  2050. }
  2051. if (j == 0x0a) {
  2052. goto widep_cmd;
  2053. }
  2054. if (j == 0x0e) {
  2055. goto try_wide;
  2056. }
  2057. continue;
  2058. widep_out:
  2059. tmport = wkport + 0x58;
  2060. outb(0x20, tmport);
  2061. tmport += 0x07;
  2062. while ((inb(tmport) & 0x80) == 0) {
  2063. if ((inb(tmport) & 0x01) != 0) {
  2064. tmport -= 0x06;
  2065. outb(0, tmport);
  2066. tmport += 0x06;
  2067. }
  2068. }
  2069. tmport -= 0x08;
  2070. j = inb(tmport) & 0x0f;
  2071. if (j == 0x0f) {
  2072. goto widep_in;
  2073. }
  2074. if (j == 0x0a) {
  2075. goto widep_cmd;
  2076. }
  2077. if (j == 0x0e) {
  2078. goto widep_out;
  2079. }
  2080. continue;
  2081. widep_in:
  2082. tmport = wkport + 0x54;
  2083. outb(0xff, tmport);
  2084. tmport += 0x04;
  2085. outb(0x20, tmport);
  2086. tmport += 0x07;
  2087. k = 0;
  2088. widep_in1:
  2089. j = inb(tmport);
  2090. if ((j & 0x01) != 0) {
  2091. tmport -= 0x06;
  2092. mbuf[k++] = inb(tmport);
  2093. tmport += 0x06;
  2094. goto widep_in1;
  2095. }
  2096. if ((j & 0x80) == 0x00) {
  2097. goto widep_in1;
  2098. }
  2099. tmport -= 0x08;
  2100. j = inb(tmport) & 0x0f;
  2101. if (j == 0x0f) {
  2102. goto widep_in;
  2103. }
  2104. if (j == 0x0a) {
  2105. goto widep_cmd;
  2106. }
  2107. if (j == 0x0e) {
  2108. goto widep_out;
  2109. }
  2110. continue;
  2111. widep_cmd:
  2112. tmport = wkport + 0x50;
  2113. outb(0x30, tmport);
  2114. tmport = wkport + 0x54;
  2115. outb(0x00, tmport);
  2116. tmport += 0x04;
  2117. outb(0x08, tmport);
  2118. tmport += 0x07;
  2119. while ((inb(tmport) & 0x80) == 0x00)
  2120. cpu_relax();
  2121. tmport -= 0x08;
  2122. j = inb(tmport);
  2123. if (j != 0x16) {
  2124. if (j == 0x4e) {
  2125. goto widep_out;
  2126. }
  2127. continue;
  2128. }
  2129. if (mbuf[0] != 0x01) {
  2130. goto not_wide;
  2131. }
  2132. if (mbuf[1] != 0x02) {
  2133. goto not_wide;
  2134. }
  2135. if (mbuf[2] != 0x03) {
  2136. goto not_wide;
  2137. }
  2138. if (mbuf[3] != 0x01) {
  2139. goto not_wide;
  2140. }
  2141. m = 1;
  2142. m = m << i;
  2143. dev->wide_id[0] |= m;
  2144. not_wide:
  2145. if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  2146. m = 1;
  2147. m = m << i;
  2148. if ((dev->async[0] & m) != 0) {
  2149. goto set_sync;
  2150. }
  2151. }
  2152. continue;
  2153. set_sync:
  2154. if (dev->sp[0][i] == 0x02) {
  2155. synu[4] = 0x0c;
  2156. synuw[4] = 0x0c;
  2157. } else {
  2158. if (dev->sp[0][i] >= 0x03) {
  2159. synu[4] = 0x0a;
  2160. synuw[4] = 0x0a;
  2161. }
  2162. }
  2163. tmport = wkport + 0x5b;
  2164. j = 0;
  2165. if ((m & dev->wide_id[0]) != 0) {
  2166. j |= 0x01;
  2167. }
  2168. outb(j, tmport);
  2169. tmport = wkport + 0x43;
  2170. outb(satn[0], tmport++);
  2171. outb(satn[1], tmport++);
  2172. outb(satn[2], tmport++);
  2173. outb(satn[3], tmport++);
  2174. outb(satn[4], tmport++);
  2175. outb(satn[5], tmport++);
  2176. tmport += 0x06;
  2177. outb(0, tmport);
  2178. tmport += 0x02;
  2179. outb(dev->id[0][i].devsp, tmport++);
  2180. outb(0, tmport++);
  2181. outb(satn[6], tmport++);
  2182. outb(satn[7], tmport++);
  2183. tmport += 0x03;
  2184. outb(satn[8], tmport);
  2185. tmport += 0x07;
  2186. while ((inb(tmport) & 0x80) == 0x00)
  2187. cpu_relax();
  2188. tmport -= 0x08;
  2189. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  2190. continue;
  2191. }
  2192. while (inb(tmport) != 0x8e)
  2193. cpu_relax();
  2194. try_sync:
  2195. j = 0;
  2196. tmport = wkport + 0x54;
  2197. outb(0x06, tmport);
  2198. tmport += 0x04;
  2199. outb(0x20, tmport);
  2200. tmport += 0x07;
  2201. while ((inb(tmport) & 0x80) == 0) {
  2202. if ((inb(tmport) & 0x01) != 0) {
  2203. tmport -= 0x06;
  2204. if ((m & dev->wide_id[0]) != 0) {
  2205. if ((m & dev->ultra_map[0]) != 0) {
  2206. outb(synuw[j++], tmport);
  2207. } else {
  2208. outb(synw[j++], tmport);
  2209. }
  2210. } else {
  2211. if ((m & dev->ultra_map[0]) != 0) {
  2212. outb(synu[j++], tmport);
  2213. } else {
  2214. outb(synn[j++], tmport);
  2215. }
  2216. }
  2217. tmport += 0x06;
  2218. }
  2219. }
  2220. tmport -= 0x08;
  2221. while ((inb(tmport) & 0x80) == 0x00)
  2222. cpu_relax();
  2223. j = inb(tmport) & 0x0f;
  2224. if (j == 0x0f) {
  2225. goto phase_ins;
  2226. }
  2227. if (j == 0x0a) {
  2228. goto phase_cmds;
  2229. }
  2230. if (j == 0x0e) {
  2231. goto try_sync;
  2232. }
  2233. continue;
  2234. phase_outs:
  2235. tmport = wkport + 0x58;
  2236. outb(0x20, tmport);
  2237. tmport += 0x07;
  2238. while ((inb(tmport) & 0x80) == 0x00) {
  2239. if ((inb(tmport) & 0x01) != 0x00) {
  2240. tmport -= 0x06;
  2241. outb(0x00, tmport);
  2242. tmport += 0x06;
  2243. }
  2244. }
  2245. tmport -= 0x08;
  2246. j = inb(tmport);
  2247. if (j == 0x85) {
  2248. goto tar_dcons;
  2249. }
  2250. j &= 0x0f;
  2251. if (j == 0x0f) {
  2252. goto phase_ins;
  2253. }
  2254. if (j == 0x0a) {
  2255. goto phase_cmds;
  2256. }
  2257. if (j == 0x0e) {
  2258. goto phase_outs;
  2259. }
  2260. continue;
  2261. phase_ins:
  2262. tmport = wkport + 0x54;
  2263. outb(0x06, tmport);
  2264. tmport += 0x04;
  2265. outb(0x20, tmport);
  2266. tmport += 0x07;
  2267. k = 0;
  2268. phase_ins1:
  2269. j = inb(tmport);
  2270. if ((j & 0x01) != 0x00) {
  2271. tmport -= 0x06;
  2272. mbuf[k++] = inb(tmport);
  2273. tmport += 0x06;
  2274. goto phase_ins1;
  2275. }
  2276. if ((j & 0x80) == 0x00) {
  2277. goto phase_ins1;
  2278. }
  2279. tmport -= 0x08;
  2280. while ((inb(tmport) & 0x80) == 0x00)
  2281. cpu_relax();
  2282. j = inb(tmport);
  2283. if (j == 0x85) {
  2284. goto tar_dcons;
  2285. }
  2286. j &= 0x0f;
  2287. if (j == 0x0f) {
  2288. goto phase_ins;
  2289. }
  2290. if (j == 0x0a) {
  2291. goto phase_cmds;
  2292. }
  2293. if (j == 0x0e) {
  2294. goto phase_outs;
  2295. }
  2296. continue;
  2297. phase_cmds:
  2298. tmport = wkport + 0x50;
  2299. outb(0x30, tmport);
  2300. tar_dcons:
  2301. tmport = wkport + 0x54;
  2302. outb(0x00, tmport);
  2303. tmport += 0x04;
  2304. outb(0x08, tmport);
  2305. tmport += 0x07;
  2306. while ((inb(tmport) & 0x80) == 0x00)
  2307. cpu_relax();
  2308. tmport -= 0x08;
  2309. j = inb(tmport);
  2310. if (j != 0x16) {
  2311. continue;
  2312. }
  2313. if (mbuf[0] != 0x01) {
  2314. continue;
  2315. }
  2316. if (mbuf[1] != 0x03) {
  2317. continue;
  2318. }
  2319. if (mbuf[4] == 0x00) {
  2320. continue;
  2321. }
  2322. if (mbuf[3] > 0x64) {
  2323. continue;
  2324. }
  2325. if (mbuf[4] > 0x0e) {
  2326. mbuf[4] = 0x0e;
  2327. }
  2328. dev->id[0][i].devsp = mbuf[4];
  2329. if (mbuf[3] < 0x0c) {
  2330. j = 0xb0;
  2331. goto set_syn_ok;
  2332. }
  2333. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  2334. j = 0xa0;
  2335. goto set_syn_ok;
  2336. }
  2337. if (mbuf[3] < 0x1a) {
  2338. j = 0x20;
  2339. goto set_syn_ok;
  2340. }
  2341. if (mbuf[3] < 0x33) {
  2342. j = 0x40;
  2343. goto set_syn_ok;
  2344. }
  2345. if (mbuf[3] < 0x4c) {
  2346. j = 0x50;
  2347. goto set_syn_ok;
  2348. }
  2349. j = 0x60;
  2350. set_syn_ok:
  2351. dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
  2352. }
  2353. }
  2354. static void atp870u_free_tables(struct Scsi_Host *host)
  2355. {
  2356. struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
  2357. int j, k;
  2358. for (j=0; j < 2; j++) {
  2359. for (k = 0; k < 16; k++) {
  2360. if (!atp_dev->id[j][k].prd_table)
  2361. continue;
  2362. pci_free_consistent(atp_dev->pdev, 1024, atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
  2363. atp_dev->id[j][k].prd_table = NULL;
  2364. }
  2365. }
  2366. }
  2367. static int atp870u_init_tables(struct Scsi_Host *host)
  2368. {
  2369. struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
  2370. int c,k;
  2371. for(c=0;c < 2;c++) {
  2372. for(k=0;k<16;k++) {
  2373. atp_dev->id[c][k].prd_table = pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus));
  2374. if (!atp_dev->id[c][k].prd_table) {
  2375. printk("atp870u_init_tables fail\n");
  2376. atp870u_free_tables(host);
  2377. return -ENOMEM;
  2378. }
  2379. atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus;
  2380. atp_dev->id[c][k].devsp=0x20;
  2381. atp_dev->id[c][k].devtype = 0x7f;
  2382. atp_dev->id[c][k].curr_req = NULL;
  2383. }
  2384. atp_dev->active_id[c] = 0;
  2385. atp_dev->wide_id[c] = 0;
  2386. atp_dev->host_id[c] = 0x07;
  2387. atp_dev->quhd[c] = 0;
  2388. atp_dev->quend[c] = 0;
  2389. atp_dev->last_cmd[c] = 0xff;
  2390. atp_dev->in_snd[c] = 0;
  2391. atp_dev->in_int[c] = 0;
  2392. for (k = 0; k < qcnt; k++) {
  2393. atp_dev->quereq[c][k] = NULL;
  2394. }
  2395. for (k = 0; k < 16; k++) {
  2396. atp_dev->id[c][k].curr_req = NULL;
  2397. atp_dev->sp[c][k] = 0x04;
  2398. }
  2399. }
  2400. return 0;
  2401. }
  2402. /* return non-zero on detection */
  2403. static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2404. {
  2405. unsigned char k, m, c;
  2406. unsigned long flags;
  2407. unsigned int base_io, tmport, error,n;
  2408. unsigned char host_id;
  2409. struct Scsi_Host *shpnt = NULL;
  2410. struct atp_unit *atpdev, *p;
  2411. unsigned char setupdata[2][16];
  2412. int count = 0;
  2413. atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL);
  2414. if (!atpdev)
  2415. return -ENOMEM;
  2416. if (pci_enable_device(pdev))
  2417. goto err_eio;
  2418. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  2419. printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
  2420. } else {
  2421. printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
  2422. goto err_eio;
  2423. }
  2424. /*
  2425. * It's probably easier to weed out some revisions like
  2426. * this than via the PCI device table
  2427. */
  2428. if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
  2429. atpdev->chip_ver = pdev->revision;
  2430. if (atpdev->chip_ver < 2)
  2431. goto err_eio;
  2432. }
  2433. switch (ent->device) {
  2434. case PCI_DEVICE_ID_ARTOP_AEC7612UW:
  2435. case PCI_DEVICE_ID_ARTOP_AEC7612SUW:
  2436. case ATP880_DEVID1:
  2437. case ATP880_DEVID2:
  2438. case ATP885_DEVID:
  2439. atpdev->chip_ver = 0x04;
  2440. default:
  2441. break;
  2442. }
  2443. base_io = pci_resource_start(pdev, 0);
  2444. base_io &= 0xfffffff8;
  2445. if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
  2446. atpdev->chip_ver = pdev->revision;
  2447. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
  2448. host_id = inb(base_io + 0x39);
  2449. host_id >>= 0x04;
  2450. printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
  2451. " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2452. atpdev->ioport[0] = base_io + 0x40;
  2453. atpdev->pciport[0] = base_io + 0x28;
  2454. atpdev->dev_id = ent->device;
  2455. atpdev->host_id[0] = host_id;
  2456. tmport = base_io + 0x22;
  2457. atpdev->scam_on = inb(tmport);
  2458. tmport += 0x13;
  2459. atpdev->global_map[0] = inb(tmport);
  2460. tmport += 0x07;
  2461. atpdev->ultra_map[0] = inw(tmport);
  2462. n = 0x3f09;
  2463. next_fblk_880:
  2464. if (n >= 0x4000)
  2465. goto flash_ok_880;
  2466. m = 0;
  2467. outw(n, base_io + 0x34);
  2468. n += 0x0002;
  2469. if (inb(base_io + 0x30) == 0xff)
  2470. goto flash_ok_880;
  2471. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2472. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2473. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2474. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2475. outw(n, base_io + 0x34);
  2476. n += 0x0002;
  2477. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2478. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2479. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2480. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2481. outw(n, base_io + 0x34);
  2482. n += 0x0002;
  2483. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2484. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2485. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2486. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2487. outw(n, base_io + 0x34);
  2488. n += 0x0002;
  2489. atpdev->sp[0][m++] = inb(base_io + 0x30);
  2490. atpdev->sp[0][m++] = inb(base_io + 0x31);
  2491. atpdev->sp[0][m++] = inb(base_io + 0x32);
  2492. atpdev->sp[0][m++] = inb(base_io + 0x33);
  2493. n += 0x0018;
  2494. goto next_fblk_880;
  2495. flash_ok_880:
  2496. outw(0, base_io + 0x34);
  2497. atpdev->ultra_map[0] = 0;
  2498. atpdev->async[0] = 0;
  2499. for (k = 0; k < 16; k++) {
  2500. n = 1;
  2501. n = n << k;
  2502. if (atpdev->sp[0][k] > 1) {
  2503. atpdev->ultra_map[0] |= n;
  2504. } else {
  2505. if (atpdev->sp[0][k] == 0)
  2506. atpdev->async[0] |= n;
  2507. }
  2508. }
  2509. atpdev->async[0] = ~(atpdev->async[0]);
  2510. outb(atpdev->global_map[0], base_io + 0x35);
  2511. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2512. if (!shpnt)
  2513. goto err_nomem;
  2514. p = (struct atp_unit *)&shpnt->hostdata;
  2515. atpdev->host = shpnt;
  2516. atpdev->pdev = pdev;
  2517. pci_set_drvdata(pdev, p);
  2518. memcpy(p, atpdev, sizeof(*atpdev));
  2519. if (atp870u_init_tables(shpnt) < 0) {
  2520. printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
  2521. goto unregister;
  2522. }
  2523. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp880i", shpnt)) {
  2524. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2525. goto free_tables;
  2526. }
  2527. spin_lock_irqsave(shpnt->host_lock, flags);
  2528. tmport = base_io + 0x38;
  2529. k = inb(tmport) & 0x80;
  2530. outb(k, tmport);
  2531. tmport += 0x03;
  2532. outb(0x20, tmport);
  2533. mdelay(32);
  2534. outb(0, tmport);
  2535. mdelay(32);
  2536. tmport = base_io + 0x5b;
  2537. inb(tmport);
  2538. tmport -= 0x04;
  2539. inb(tmport);
  2540. tmport = base_io + 0x40;
  2541. outb((host_id | 0x08), tmport);
  2542. tmport += 0x18;
  2543. outb(0, tmport);
  2544. tmport += 0x07;
  2545. while ((inb(tmport) & 0x80) == 0)
  2546. mdelay(1);
  2547. tmport -= 0x08;
  2548. inb(tmport);
  2549. tmport = base_io + 0x41;
  2550. outb(8, tmport++);
  2551. outb(0x7f, tmport);
  2552. tmport = base_io + 0x51;
  2553. outb(0x20, tmport);
  2554. tscam(shpnt);
  2555. is880(p, base_io);
  2556. tmport = base_io + 0x38;
  2557. outb(0xb0, tmport);
  2558. shpnt->max_id = 16;
  2559. shpnt->this_id = host_id;
  2560. shpnt->unique_id = base_io;
  2561. shpnt->io_port = base_io;
  2562. shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */
  2563. shpnt->irq = pdev->irq;
  2564. } else if (ent->device == ATP885_DEVID) {
  2565. printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
  2566. , base_io, pdev->irq);
  2567. atpdev->pdev = pdev;
  2568. atpdev->dev_id = ent->device;
  2569. atpdev->baseport = base_io;
  2570. atpdev->ioport[0] = base_io + 0x80;
  2571. atpdev->ioport[1] = base_io + 0xc0;
  2572. atpdev->pciport[0] = base_io + 0x40;
  2573. atpdev->pciport[1] = base_io + 0x50;
  2574. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2575. if (!shpnt)
  2576. goto err_nomem;
  2577. p = (struct atp_unit *)&shpnt->hostdata;
  2578. atpdev->host = shpnt;
  2579. atpdev->pdev = pdev;
  2580. pci_set_drvdata(pdev, p);
  2581. memcpy(p, atpdev, sizeof(struct atp_unit));
  2582. if (atp870u_init_tables(shpnt) < 0)
  2583. goto unregister;
  2584. #ifdef ED_DBGP
  2585. printk("request_irq() shpnt %p hostdata %p\n", shpnt, p);
  2586. #endif
  2587. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt)) {
  2588. printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
  2589. goto free_tables;
  2590. }
  2591. spin_lock_irqsave(shpnt->host_lock, flags);
  2592. c=inb(base_io + 0x29);
  2593. outb((c | 0x04),base_io + 0x29);
  2594. n=0x1f80;
  2595. next_fblk_885:
  2596. if (n >= 0x2000) {
  2597. goto flash_ok_885;
  2598. }
  2599. outw(n,base_io + 0x3c);
  2600. if (inl(base_io + 0x38) == 0xffffffff) {
  2601. goto flash_ok_885;
  2602. }
  2603. for (m=0; m < 2; m++) {
  2604. p->global_map[m]= 0;
  2605. for (k=0; k < 4; k++) {
  2606. outw(n++,base_io + 0x3c);
  2607. ((unsigned long *)&setupdata[m][0])[k]=inl(base_io + 0x38);
  2608. }
  2609. for (k=0; k < 4; k++) {
  2610. outw(n++,base_io + 0x3c);
  2611. ((unsigned long *)&p->sp[m][0])[k]=inl(base_io + 0x38);
  2612. }
  2613. n += 8;
  2614. }
  2615. goto next_fblk_885;
  2616. flash_ok_885:
  2617. #ifdef ED_DBGP
  2618. printk( "Flash Read OK\n");
  2619. #endif
  2620. c=inb(base_io + 0x29);
  2621. outb((c & 0xfb),base_io + 0x29);
  2622. for (c=0;c < 2;c++) {
  2623. p->ultra_map[c]=0;
  2624. p->async[c] = 0;
  2625. for (k=0; k < 16; k++) {
  2626. n=1;
  2627. n = n << k;
  2628. if (p->sp[c][k] > 1) {
  2629. p->ultra_map[c] |= n;
  2630. } else {
  2631. if (p->sp[c][k] == 0) {
  2632. p->async[c] |= n;
  2633. }
  2634. }
  2635. }
  2636. p->async[c] = ~(p->async[c]);
  2637. if (p->global_map[c] == 0) {
  2638. k=setupdata[c][1];
  2639. if ((k & 0x40) != 0)
  2640. p->global_map[c] |= 0x20;
  2641. k &= 0x07;
  2642. p->global_map[c] |= k;
  2643. if ((setupdata[c][2] & 0x04) != 0)
  2644. p->global_map[c] |= 0x08;
  2645. p->host_id[c] = setupdata[c][0] & 0x07;
  2646. }
  2647. }
  2648. k = inb(base_io + 0x28) & 0x8f;
  2649. k |= 0x10;
  2650. outb(k, base_io + 0x28);
  2651. outb(0x80, base_io + 0x41);
  2652. outb(0x80, base_io + 0x51);
  2653. mdelay(100);
  2654. outb(0, base_io + 0x41);
  2655. outb(0, base_io + 0x51);
  2656. mdelay(1000);
  2657. inb(base_io + 0x9b);
  2658. inb(base_io + 0x97);
  2659. inb(base_io + 0xdb);
  2660. inb(base_io + 0xd7);
  2661. tmport = base_io + 0x80;
  2662. k=p->host_id[0];
  2663. if (k > 7)
  2664. k = (k & 0x07) | 0x40;
  2665. k |= 0x08;
  2666. outb(k, tmport);
  2667. tmport += 0x18;
  2668. outb(0, tmport);
  2669. tmport += 0x07;
  2670. while ((inb(tmport) & 0x80) == 0)
  2671. cpu_relax();
  2672. tmport -= 0x08;
  2673. inb(tmport);
  2674. tmport = base_io + 0x81;
  2675. outb(8, tmport++);
  2676. outb(0x7f, tmport);
  2677. tmport = base_io + 0x91;
  2678. outb(0x20, tmport);
  2679. tmport = base_io + 0xc0;
  2680. k=p->host_id[1];
  2681. if (k > 7)
  2682. k = (k & 0x07) | 0x40;
  2683. k |= 0x08;
  2684. outb(k, tmport);
  2685. tmport += 0x18;
  2686. outb(0, tmport);
  2687. tmport += 0x07;
  2688. while ((inb(tmport) & 0x80) == 0)
  2689. cpu_relax();
  2690. tmport -= 0x08;
  2691. inb(tmport);
  2692. tmport = base_io + 0xc1;
  2693. outb(8, tmport++);
  2694. outb(0x7f, tmport);
  2695. tmport = base_io + 0xd1;
  2696. outb(0x20, tmport);
  2697. tscam_885();
  2698. printk(KERN_INFO " Scanning Channel A SCSI Device ...\n");
  2699. is885(p, base_io + 0x80, 0);
  2700. printk(KERN_INFO " Scanning Channel B SCSI Device ...\n");
  2701. is885(p, base_io + 0xc0, 1);
  2702. k = inb(base_io + 0x28) & 0xcf;
  2703. k |= 0xc0;
  2704. outb(k, base_io + 0x28);
  2705. k = inb(base_io + 0x1f) | 0x80;
  2706. outb(k, base_io + 0x1f);
  2707. k = inb(base_io + 0x29) | 0x01;
  2708. outb(k, base_io + 0x29);
  2709. #ifdef ED_DBGP
  2710. //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
  2711. #endif
  2712. shpnt->max_id = 16;
  2713. shpnt->max_lun = (p->global_map[0] & 0x07) + 1;
  2714. shpnt->max_channel = 1;
  2715. shpnt->this_id = p->host_id[0];
  2716. shpnt->unique_id = base_io;
  2717. shpnt->io_port = base_io;
  2718. shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */
  2719. shpnt->irq = pdev->irq;
  2720. } else {
  2721. error = pci_read_config_byte(pdev, 0x49, &host_id);
  2722. printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
  2723. "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2724. atpdev->ioport[0] = base_io;
  2725. atpdev->pciport[0] = base_io + 0x20;
  2726. atpdev->dev_id = ent->device;
  2727. host_id &= 0x07;
  2728. atpdev->host_id[0] = host_id;
  2729. tmport = base_io + 0x22;
  2730. atpdev->scam_on = inb(tmport);
  2731. tmport += 0x0b;
  2732. atpdev->global_map[0] = inb(tmport++);
  2733. atpdev->ultra_map[0] = inw(tmport);
  2734. if (atpdev->ultra_map[0] == 0) {
  2735. atpdev->scam_on = 0x00;
  2736. atpdev->global_map[0] = 0x20;
  2737. atpdev->ultra_map[0] = 0xffff;
  2738. }
  2739. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2740. if (!shpnt)
  2741. goto err_nomem;
  2742. p = (struct atp_unit *)&shpnt->hostdata;
  2743. atpdev->host = shpnt;
  2744. atpdev->pdev = pdev;
  2745. pci_set_drvdata(pdev, p);
  2746. memcpy(p, atpdev, sizeof(*atpdev));
  2747. if (atp870u_init_tables(shpnt) < 0)
  2748. goto unregister;
  2749. if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870i", shpnt)) {
  2750. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2751. goto free_tables;
  2752. }
  2753. spin_lock_irqsave(shpnt->host_lock, flags);
  2754. if (atpdev->chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
  2755. tmport = base_io + 0x3e;
  2756. outb(0x00, tmport);
  2757. }
  2758. tmport = base_io + 0x3a;
  2759. k = (inb(tmport) & 0xf3) | 0x10;
  2760. outb(k, tmport);
  2761. outb((k & 0xdf), tmport);
  2762. mdelay(32);
  2763. outb(k, tmport);
  2764. mdelay(32);
  2765. tmport = base_io;
  2766. outb((host_id | 0x08), tmport);
  2767. tmport += 0x18;
  2768. outb(0, tmport);
  2769. tmport += 0x07;
  2770. while ((inb(tmport) & 0x80) == 0)
  2771. mdelay(1);
  2772. tmport -= 0x08;
  2773. inb(tmport);
  2774. tmport = base_io + 1;
  2775. outb(8, tmport++);
  2776. outb(0x7f, tmport);
  2777. tmport = base_io + 0x11;
  2778. outb(0x20, tmport);
  2779. tscam(shpnt);
  2780. is870(p, base_io);
  2781. tmport = base_io + 0x3a;
  2782. outb((inb(tmport) & 0xef), tmport);
  2783. tmport++;
  2784. outb((inb(tmport) | 0x20), tmport);
  2785. if (atpdev->chip_ver == 4)
  2786. shpnt->max_id = 16;
  2787. else
  2788. shpnt->max_id = 8;
  2789. shpnt->this_id = host_id;
  2790. shpnt->unique_id = base_io;
  2791. shpnt->io_port = base_io;
  2792. shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */
  2793. shpnt->irq = pdev->irq;
  2794. }
  2795. spin_unlock_irqrestore(shpnt->host_lock, flags);
  2796. if(ent->device==ATP885_DEVID) {
  2797. if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */
  2798. goto request_io_fail;
  2799. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2800. if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */
  2801. goto request_io_fail;
  2802. } else {
  2803. if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */
  2804. goto request_io_fail;
  2805. }
  2806. count++;
  2807. if (scsi_add_host(shpnt, &pdev->dev))
  2808. goto scsi_add_fail;
  2809. scsi_scan_host(shpnt);
  2810. #ifdef ED_DBGP
  2811. printk("atp870u_prob : exit\n");
  2812. #endif
  2813. return 0;
  2814. scsi_add_fail:
  2815. printk("atp870u_prob:scsi_add_fail\n");
  2816. if(ent->device==ATP885_DEVID) {
  2817. release_region(base_io, 0xff);
  2818. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2819. release_region(base_io, 0x60);
  2820. } else {
  2821. release_region(base_io, 0x40);
  2822. }
  2823. request_io_fail:
  2824. printk("atp870u_prob:request_io_fail\n");
  2825. free_irq(pdev->irq, shpnt);
  2826. free_tables:
  2827. printk("atp870u_prob:free_table\n");
  2828. atp870u_free_tables(shpnt);
  2829. unregister:
  2830. printk("atp870u_prob:unregister\n");
  2831. scsi_host_put(shpnt);
  2832. return -1;
  2833. err_eio:
  2834. kfree(atpdev);
  2835. return -EIO;
  2836. err_nomem:
  2837. kfree(atpdev);
  2838. return -ENOMEM;
  2839. }
  2840. /* The abort command does not leave the device in a clean state where
  2841. it is available to be used again. Until this gets worked out, we will
  2842. leave it commented out. */
  2843. static int atp870u_abort(struct scsi_cmnd * SCpnt)
  2844. {
  2845. unsigned char j, k, c;
  2846. struct scsi_cmnd *workrequ;
  2847. unsigned int tmport;
  2848. struct atp_unit *dev;
  2849. struct Scsi_Host *host;
  2850. host = SCpnt->device->host;
  2851. dev = (struct atp_unit *)&host->hostdata;
  2852. c = scmd_channel(SCpnt);
  2853. printk(" atp870u: abort Channel = %x \n", c);
  2854. printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
  2855. printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
  2856. tmport = dev->ioport[c];
  2857. for (j = 0; j < 0x18; j++) {
  2858. printk(" r%2x=%2x", j, inb(tmport++));
  2859. }
  2860. tmport += 0x04;
  2861. printk(" r1c=%2x", inb(tmport));
  2862. tmport += 0x03;
  2863. printk(" r1f=%2x in_snd=%2x ", inb(tmport), dev->in_snd[c]);
  2864. tmport= dev->pciport[c];
  2865. printk(" d00=%2x", inb(tmport));
  2866. tmport += 0x02;
  2867. printk(" d02=%2x", inb(tmport));
  2868. for(j=0;j<16;j++) {
  2869. if (dev->id[c][j].curr_req != NULL) {
  2870. workrequ = dev->id[c][j].curr_req;
  2871. printk("\n que cdb= ");
  2872. for (k=0; k < workrequ->cmd_len; k++) {
  2873. printk(" %2x ",workrequ->cmnd[k]);
  2874. }
  2875. printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
  2876. }
  2877. }
  2878. return SUCCESS;
  2879. }
  2880. static const char *atp870u_info(struct Scsi_Host *notused)
  2881. {
  2882. static char buffer[128];
  2883. strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
  2884. return buffer;
  2885. }
  2886. #define BLS buffer + len + size
  2887. static int atp870u_proc_info(struct Scsi_Host *HBAptr, char *buffer,
  2888. char **start, off_t offset, int length, int inout)
  2889. {
  2890. static u8 buff[512];
  2891. int size = 0;
  2892. int len = 0;
  2893. off_t begin = 0;
  2894. off_t pos = 0;
  2895. if (inout)
  2896. return -EINVAL;
  2897. if (offset == 0)
  2898. memset(buff, 0, sizeof(buff));
  2899. size += sprintf(BLS, "ACARD AEC-671X Driver Version: 2.6+ac\n");
  2900. len += size;
  2901. pos = begin + len;
  2902. size = 0;
  2903. size += sprintf(BLS, "\n");
  2904. size += sprintf(BLS, "Adapter Configuration:\n");
  2905. size += sprintf(BLS, " Base IO: %#.4lx\n", HBAptr->io_port);
  2906. size += sprintf(BLS, " IRQ: %d\n", HBAptr->irq);
  2907. len += size;
  2908. pos = begin + len;
  2909. *start = buffer + (offset - begin); /* Start of wanted data */
  2910. len -= (offset - begin); /* Start slop */
  2911. if (len > length) {
  2912. len = length; /* Ending slop */
  2913. }
  2914. return (len);
  2915. }
  2916. static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
  2917. sector_t capacity, int *ip)
  2918. {
  2919. int heads, sectors, cylinders;
  2920. heads = 64;
  2921. sectors = 32;
  2922. cylinders = (unsigned long)capacity / (heads * sectors);
  2923. if (cylinders > 1024) {
  2924. heads = 255;
  2925. sectors = 63;
  2926. cylinders = (unsigned long)capacity / (heads * sectors);
  2927. }
  2928. ip[0] = heads;
  2929. ip[1] = sectors;
  2930. ip[2] = cylinders;
  2931. return 0;
  2932. }
  2933. static void atp870u_remove (struct pci_dev *pdev)
  2934. {
  2935. struct atp_unit *devext = pci_get_drvdata(pdev);
  2936. struct Scsi_Host *pshost = devext->host;
  2937. scsi_remove_host(pshost);
  2938. printk(KERN_INFO "free_irq : %d\n",pshost->irq);
  2939. free_irq(pshost->irq, pshost);
  2940. release_region(pshost->io_port, pshost->n_io_port);
  2941. printk(KERN_INFO "atp870u_free_tables : %p\n",pshost);
  2942. atp870u_free_tables(pshost);
  2943. printk(KERN_INFO "scsi_host_put : %p\n",pshost);
  2944. scsi_host_put(pshost);
  2945. printk(KERN_INFO "pci_set_drvdata : %p\n",pdev);
  2946. pci_set_drvdata(pdev, NULL);
  2947. }
  2948. MODULE_LICENSE("GPL");
  2949. static struct scsi_host_template atp870u_template = {
  2950. .module = THIS_MODULE,
  2951. .name = "atp870u" /* name */,
  2952. .proc_name = "atp870u",
  2953. .proc_info = atp870u_proc_info,
  2954. .info = atp870u_info /* info */,
  2955. .queuecommand = atp870u_queuecommand /* queuecommand */,
  2956. .eh_abort_handler = atp870u_abort /* abort */,
  2957. .bios_param = atp870u_biosparam /* biosparm */,
  2958. .can_queue = qcnt /* can_queue */,
  2959. .this_id = 7 /* SCSI ID */,
  2960. .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/,
  2961. .cmd_per_lun = ATP870U_CMDLUN /* commands per lun */,
  2962. .use_clustering = ENABLE_CLUSTERING,
  2963. .max_sectors = ATP870U_MAX_SECTORS,
  2964. };
  2965. static struct pci_device_id atp870u_id_table[] = {
  2966. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
  2967. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
  2968. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
  2969. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
  2970. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
  2971. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
  2972. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
  2973. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
  2974. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
  2975. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
  2976. { 0, },
  2977. };
  2978. MODULE_DEVICE_TABLE(pci, atp870u_id_table);
  2979. static struct pci_driver atp870u_driver = {
  2980. .id_table = atp870u_id_table,
  2981. .name = "atp870u",
  2982. .probe = atp870u_probe,
  2983. .remove = __devexit_p(atp870u_remove),
  2984. };
  2985. static int __init atp870u_init(void)
  2986. {
  2987. #ifdef ED_DBGP
  2988. printk("atp870u_init: Entry\n");
  2989. #endif
  2990. return pci_register_driver(&atp870u_driver);
  2991. }
  2992. static void __exit atp870u_exit(void)
  2993. {
  2994. #ifdef ED_DBGP
  2995. printk("atp870u_exit: Entry\n");
  2996. #endif
  2997. pci_unregister_driver(&atp870u_driver);
  2998. }
  2999. static void tscam_885(void)
  3000. {
  3001. unsigned char i;
  3002. for (i = 0; i < 0x2; i++) {
  3003. mdelay(300);
  3004. }
  3005. return;
  3006. }
  3007. static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c)
  3008. {
  3009. unsigned int tmport;
  3010. unsigned char i, j, k, rmb, n, lvdmode;
  3011. unsigned short int m;
  3012. static unsigned char mbuf[512];
  3013. static unsigned char satn[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
  3014. static unsigned char inqd[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
  3015. static unsigned char synn[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3016. unsigned char synu[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3017. static unsigned char synw[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3018. unsigned char synuw[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3019. static unsigned char wide[6] = {0x80, 1, 2, 3, 1, 0};
  3020. static unsigned char u3[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
  3021. lvdmode=inb(wkport + 0x1b) >> 7;
  3022. for (i = 0; i < 16; i++) {
  3023. m = 1;
  3024. m = m << i;
  3025. if ((m & dev->active_id[c]) != 0) {
  3026. continue;
  3027. }
  3028. if (i == dev->host_id[c]) {
  3029. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
  3030. continue;
  3031. }
  3032. tmport = wkport + 0x1b;
  3033. outb(0x01, tmport);
  3034. tmport = wkport + 0x01;
  3035. outb(0x08, tmport++);
  3036. outb(0x7f, tmport++);
  3037. outb(satn[0], tmport++);
  3038. outb(satn[1], tmport++);
  3039. outb(satn[2], tmport++);
  3040. outb(satn[3], tmport++);
  3041. outb(satn[4], tmport++);
  3042. outb(satn[5], tmport++);
  3043. tmport += 0x06;
  3044. outb(0, tmport);
  3045. tmport += 0x02;
  3046. outb(dev->id[c][i].devsp, tmport++);
  3047. outb(0, tmport++);
  3048. outb(satn[6], tmport++);
  3049. outb(satn[7], tmport++);
  3050. j = i;
  3051. if ((j & 0x08) != 0) {
  3052. j = (j & 0x07) | 0x40;
  3053. }
  3054. outb(j, tmport);
  3055. tmport += 0x03;
  3056. outb(satn[8], tmport);
  3057. tmport += 0x07;
  3058. while ((inb(tmport) & 0x80) == 0x00)
  3059. cpu_relax();
  3060. tmport -= 0x08;
  3061. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3062. continue;
  3063. }
  3064. while (inb(tmport) != 0x8e)
  3065. cpu_relax();
  3066. dev->active_id[c] |= m;
  3067. tmport = wkport + 0x10;
  3068. outb(0x30, tmport);
  3069. tmport = wkport + 0x14;
  3070. outb(0x00, tmport);
  3071. phase_cmd:
  3072. tmport = wkport + 0x18;
  3073. outb(0x08, tmport);
  3074. tmport += 0x07;
  3075. while ((inb(tmport) & 0x80) == 0x00)
  3076. cpu_relax();
  3077. tmport -= 0x08;
  3078. j = inb(tmport);
  3079. if (j != 0x16) {
  3080. tmport = wkport + 0x10;
  3081. outb(0x41, tmport);
  3082. goto phase_cmd;
  3083. }
  3084. sel_ok:
  3085. tmport = wkport + 0x03;
  3086. outb(inqd[0], tmport++);
  3087. outb(inqd[1], tmport++);
  3088. outb(inqd[2], tmport++);
  3089. outb(inqd[3], tmport++);
  3090. outb(inqd[4], tmport++);
  3091. outb(inqd[5], tmport);
  3092. tmport += 0x07;
  3093. outb(0, tmport);
  3094. tmport += 0x02;
  3095. outb(dev->id[c][i].devsp, tmport++);
  3096. outb(0, tmport++);
  3097. outb(inqd[6], tmport++);
  3098. outb(inqd[7], tmport++);
  3099. tmport += 0x03;
  3100. outb(inqd[8], tmport);
  3101. tmport += 0x07;
  3102. while ((inb(tmport) & 0x80) == 0x00)
  3103. cpu_relax();
  3104. tmport -= 0x08;
  3105. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3106. continue;
  3107. }
  3108. while (inb(tmport) != 0x8e)
  3109. cpu_relax();
  3110. tmport = wkport + 0x1b;
  3111. outb(0x00, tmport);
  3112. tmport = wkport + 0x18;
  3113. outb(0x08, tmport);
  3114. tmport += 0x07;
  3115. j = 0;
  3116. rd_inq_data:
  3117. k = inb(tmport);
  3118. if ((k & 0x01) != 0) {
  3119. tmport -= 0x06;
  3120. mbuf[j++] = inb(tmport);
  3121. tmport += 0x06;
  3122. goto rd_inq_data;
  3123. }
  3124. if ((k & 0x80) == 0) {
  3125. goto rd_inq_data;
  3126. }
  3127. tmport -= 0x08;
  3128. j = inb(tmport);
  3129. if (j == 0x16) {
  3130. goto inq_ok;
  3131. }
  3132. tmport = wkport + 0x10;
  3133. outb(0x46, tmport);
  3134. tmport += 0x02;
  3135. outb(0, tmport++);
  3136. outb(0, tmport++);
  3137. outb(0, tmport++);
  3138. tmport += 0x03;
  3139. outb(0x08, tmport);
  3140. tmport += 0x07;
  3141. while ((inb(tmport) & 0x80) == 0x00)
  3142. cpu_relax();
  3143. tmport -= 0x08;
  3144. if (inb(tmport) != 0x16) {
  3145. goto sel_ok;
  3146. }
  3147. inq_ok:
  3148. mbuf[36] = 0;
  3149. printk( KERN_INFO" ID: %2d %s\n", i, &mbuf[8]);
  3150. dev->id[c][i].devtype = mbuf[0];
  3151. rmb = mbuf[1];
  3152. n = mbuf[7];
  3153. if ((mbuf[7] & 0x60) == 0) {
  3154. goto not_wide;
  3155. }
  3156. if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) {
  3157. goto not_wide;
  3158. }
  3159. if (lvdmode == 0) {
  3160. goto chg_wide;
  3161. }
  3162. if (dev->sp[c][i] != 0x04) { // force u2
  3163. goto chg_wide;
  3164. }
  3165. tmport = wkport + 0x1b;
  3166. outb(0x01, tmport);
  3167. tmport = wkport + 0x03;
  3168. outb(satn[0], tmport++);
  3169. outb(satn[1], tmport++);
  3170. outb(satn[2], tmport++);
  3171. outb(satn[3], tmport++);
  3172. outb(satn[4], tmport++);
  3173. outb(satn[5], tmport++);
  3174. tmport += 0x06;
  3175. outb(0, tmport);
  3176. tmport += 0x02;
  3177. outb(dev->id[c][i].devsp, tmport++);
  3178. outb(0, tmport++);
  3179. outb(satn[6], tmport++);
  3180. outb(satn[7], tmport++);
  3181. tmport += 0x03;
  3182. outb(satn[8], tmport);
  3183. tmport += 0x07;
  3184. while ((inb(tmport) & 0x80) == 0x00)
  3185. cpu_relax();
  3186. tmport -= 0x08;
  3187. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3188. continue;
  3189. }
  3190. while (inb(tmport) != 0x8e)
  3191. cpu_relax();
  3192. try_u3:
  3193. j = 0;
  3194. tmport = wkport + 0x14;
  3195. outb(0x09, tmport);
  3196. tmport += 0x04;
  3197. outb(0x20, tmport);
  3198. tmport += 0x07;
  3199. while ((inb(tmport) & 0x80) == 0) {
  3200. if ((inb(tmport) & 0x01) != 0) {
  3201. tmport -= 0x06;
  3202. outb(u3[j++], tmport);
  3203. tmport += 0x06;
  3204. }
  3205. cpu_relax();
  3206. }
  3207. tmport -= 0x08;
  3208. while ((inb(tmport) & 0x80) == 0x00)
  3209. cpu_relax();
  3210. j = inb(tmport) & 0x0f;
  3211. if (j == 0x0f) {
  3212. goto u3p_in;
  3213. }
  3214. if (j == 0x0a) {
  3215. goto u3p_cmd;
  3216. }
  3217. if (j == 0x0e) {
  3218. goto try_u3;
  3219. }
  3220. continue;
  3221. u3p_out:
  3222. tmport = wkport + 0x18;
  3223. outb(0x20, tmport);
  3224. tmport += 0x07;
  3225. while ((inb(tmport) & 0x80) == 0) {
  3226. if ((inb(tmport) & 0x01) != 0) {
  3227. tmport -= 0x06;
  3228. outb(0, tmport);
  3229. tmport += 0x06;
  3230. }
  3231. cpu_relax();
  3232. }
  3233. tmport -= 0x08;
  3234. j = inb(tmport) & 0x0f;
  3235. if (j == 0x0f) {
  3236. goto u3p_in;
  3237. }
  3238. if (j == 0x0a) {
  3239. goto u3p_cmd;
  3240. }
  3241. if (j == 0x0e) {
  3242. goto u3p_out;
  3243. }
  3244. continue;
  3245. u3p_in:
  3246. tmport = wkport + 0x14;
  3247. outb(0x09, tmport);
  3248. tmport += 0x04;
  3249. outb(0x20, tmport);
  3250. tmport += 0x07;
  3251. k = 0;
  3252. u3p_in1:
  3253. j = inb(tmport);
  3254. if ((j & 0x01) != 0) {
  3255. tmport -= 0x06;
  3256. mbuf[k++] = inb(tmport);
  3257. tmport += 0x06;
  3258. goto u3p_in1;
  3259. }
  3260. if ((j & 0x80) == 0x00) {
  3261. goto u3p_in1;
  3262. }
  3263. tmport -= 0x08;
  3264. j = inb(tmport) & 0x0f;
  3265. if (j == 0x0f) {
  3266. goto u3p_in;
  3267. }
  3268. if (j == 0x0a) {
  3269. goto u3p_cmd;
  3270. }
  3271. if (j == 0x0e) {
  3272. goto u3p_out;
  3273. }
  3274. continue;
  3275. u3p_cmd:
  3276. tmport = wkport + 0x10;
  3277. outb(0x30, tmport);
  3278. tmport = wkport + 0x14;
  3279. outb(0x00, tmport);
  3280. tmport += 0x04;
  3281. outb(0x08, tmport);
  3282. tmport += 0x07;
  3283. while ((inb(tmport) & 0x80) == 0x00);
  3284. tmport -= 0x08;
  3285. j = inb(tmport);
  3286. if (j != 0x16) {
  3287. if (j == 0x4e) {
  3288. goto u3p_out;
  3289. }
  3290. continue;
  3291. }
  3292. if (mbuf[0] != 0x01) {
  3293. goto chg_wide;
  3294. }
  3295. if (mbuf[1] != 0x06) {
  3296. goto chg_wide;
  3297. }
  3298. if (mbuf[2] != 0x04) {
  3299. goto chg_wide;
  3300. }
  3301. if (mbuf[3] == 0x09) {
  3302. m = 1;
  3303. m = m << i;
  3304. dev->wide_id[c] |= m;
  3305. dev->id[c][i].devsp = 0xce;
  3306. #ifdef ED_DBGP
  3307. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3308. #endif
  3309. continue;
  3310. }
  3311. chg_wide:
  3312. tmport = wkport + 0x1b;
  3313. outb(0x01, tmport);
  3314. tmport = wkport + 0x03;
  3315. outb(satn[0], tmport++);
  3316. outb(satn[1], tmport++);
  3317. outb(satn[2], tmport++);
  3318. outb(satn[3], tmport++);
  3319. outb(satn[4], tmport++);
  3320. outb(satn[5], tmport++);
  3321. tmport += 0x06;
  3322. outb(0, tmport);
  3323. tmport += 0x02;
  3324. outb(dev->id[c][i].devsp, tmport++);
  3325. outb(0, tmport++);
  3326. outb(satn[6], tmport++);
  3327. outb(satn[7], tmport++);
  3328. tmport += 0x03;
  3329. outb(satn[8], tmport);
  3330. tmport += 0x07;
  3331. while ((inb(tmport) & 0x80) == 0x00)
  3332. cpu_relax();
  3333. tmport -= 0x08;
  3334. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3335. continue;
  3336. }
  3337. while (inb(tmport) != 0x8e)
  3338. cpu_relax();
  3339. try_wide:
  3340. j = 0;
  3341. tmport = wkport + 0x14;
  3342. outb(0x05, tmport);
  3343. tmport += 0x04;
  3344. outb(0x20, tmport);
  3345. tmport += 0x07;
  3346. while ((inb(tmport) & 0x80) == 0) {
  3347. if ((inb(tmport) & 0x01) != 0) {
  3348. tmport -= 0x06;
  3349. outb(wide[j++], tmport);
  3350. tmport += 0x06;
  3351. }
  3352. cpu_relax();
  3353. }
  3354. tmport -= 0x08;
  3355. while ((inb(tmport) & 0x80) == 0x00)
  3356. cpu_relax();
  3357. j = inb(tmport) & 0x0f;
  3358. if (j == 0x0f) {
  3359. goto widep_in;
  3360. }
  3361. if (j == 0x0a) {
  3362. goto widep_cmd;
  3363. }
  3364. if (j == 0x0e) {
  3365. goto try_wide;
  3366. }
  3367. continue;
  3368. widep_out:
  3369. tmport = wkport + 0x18;
  3370. outb(0x20, tmport);
  3371. tmport += 0x07;
  3372. while ((inb(tmport) & 0x80) == 0) {
  3373. if ((inb(tmport) & 0x01) != 0) {
  3374. tmport -= 0x06;
  3375. outb(0, tmport);
  3376. tmport += 0x06;
  3377. }
  3378. cpu_relax();
  3379. }
  3380. tmport -= 0x08;
  3381. j = inb(tmport) & 0x0f;
  3382. if (j == 0x0f) {
  3383. goto widep_in;
  3384. }
  3385. if (j == 0x0a) {
  3386. goto widep_cmd;
  3387. }
  3388. if (j == 0x0e) {
  3389. goto widep_out;
  3390. }
  3391. continue;
  3392. widep_in:
  3393. tmport = wkport + 0x14;
  3394. outb(0xff, tmport);
  3395. tmport += 0x04;
  3396. outb(0x20, tmport);
  3397. tmport += 0x07;
  3398. k = 0;
  3399. widep_in1:
  3400. j = inb(tmport);
  3401. if ((j & 0x01) != 0) {
  3402. tmport -= 0x06;
  3403. mbuf[k++] = inb(tmport);
  3404. tmport += 0x06;
  3405. goto widep_in1;
  3406. }
  3407. if ((j & 0x80) == 0x00) {
  3408. goto widep_in1;
  3409. }
  3410. tmport -= 0x08;
  3411. j = inb(tmport) & 0x0f;
  3412. if (j == 0x0f) {
  3413. goto widep_in;
  3414. }
  3415. if (j == 0x0a) {
  3416. goto widep_cmd;
  3417. }
  3418. if (j == 0x0e) {
  3419. goto widep_out;
  3420. }
  3421. continue;
  3422. widep_cmd:
  3423. tmport = wkport + 0x10;
  3424. outb(0x30, tmport);
  3425. tmport = wkport + 0x14;
  3426. outb(0x00, tmport);
  3427. tmport += 0x04;
  3428. outb(0x08, tmport);
  3429. tmport += 0x07;
  3430. while ((inb(tmport) & 0x80) == 0x00)
  3431. cpu_relax();
  3432. tmport -= 0x08;
  3433. j = inb(tmport);
  3434. if (j != 0x16) {
  3435. if (j == 0x4e) {
  3436. goto widep_out;
  3437. }
  3438. continue;
  3439. }
  3440. if (mbuf[0] != 0x01) {
  3441. goto not_wide;
  3442. }
  3443. if (mbuf[1] != 0x02) {
  3444. goto not_wide;
  3445. }
  3446. if (mbuf[2] != 0x03) {
  3447. goto not_wide;
  3448. }
  3449. if (mbuf[3] != 0x01) {
  3450. goto not_wide;
  3451. }
  3452. m = 1;
  3453. m = m << i;
  3454. dev->wide_id[c] |= m;
  3455. not_wide:
  3456. if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) ||
  3457. ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  3458. m = 1;
  3459. m = m << i;
  3460. if ((dev->async[c] & m) != 0) {
  3461. goto set_sync;
  3462. }
  3463. }
  3464. continue;
  3465. set_sync:
  3466. if (dev->sp[c][i] == 0x02) {
  3467. synu[4]=0x0c;
  3468. synuw[4]=0x0c;
  3469. } else {
  3470. if (dev->sp[c][i] >= 0x03) {
  3471. synu[4]=0x0a;
  3472. synuw[4]=0x0a;
  3473. }
  3474. }
  3475. tmport = wkport + 0x1b;
  3476. j = 0;
  3477. if ((m & dev->wide_id[c]) != 0) {
  3478. j |= 0x01;
  3479. }
  3480. outb(j, tmport);
  3481. tmport = wkport + 0x03;
  3482. outb(satn[0], tmport++);
  3483. outb(satn[1], tmport++);
  3484. outb(satn[2], tmport++);
  3485. outb(satn[3], tmport++);
  3486. outb(satn[4], tmport++);
  3487. outb(satn[5], tmport++);
  3488. tmport += 0x06;
  3489. outb(0, tmport);
  3490. tmport += 0x02;
  3491. outb(dev->id[c][i].devsp, tmport++);
  3492. outb(0, tmport++);
  3493. outb(satn[6], tmport++);
  3494. outb(satn[7], tmport++);
  3495. tmport += 0x03;
  3496. outb(satn[8], tmport);
  3497. tmport += 0x07;
  3498. while ((inb(tmport) & 0x80) == 0x00)
  3499. cpu_relax();
  3500. tmport -= 0x08;
  3501. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3502. continue;
  3503. }
  3504. while (inb(tmport) != 0x8e)
  3505. cpu_relax();
  3506. try_sync:
  3507. j = 0;
  3508. tmport = wkport + 0x14;
  3509. outb(0x06, tmport);
  3510. tmport += 0x04;
  3511. outb(0x20, tmport);
  3512. tmport += 0x07;
  3513. while ((inb(tmport) & 0x80) == 0) {
  3514. if ((inb(tmport) & 0x01) != 0) {
  3515. tmport -= 0x06;
  3516. if ((m & dev->wide_id[c]) != 0) {
  3517. if ((m & dev->ultra_map[c]) != 0) {
  3518. outb(synuw[j++], tmport);
  3519. } else {
  3520. outb(synw[j++], tmport);
  3521. }
  3522. } else {
  3523. if ((m & dev->ultra_map[c]) != 0) {
  3524. outb(synu[j++], tmport);
  3525. } else {
  3526. outb(synn[j++], tmport);
  3527. }
  3528. }
  3529. tmport += 0x06;
  3530. }
  3531. }
  3532. tmport -= 0x08;
  3533. while ((inb(tmport) & 0x80) == 0x00)
  3534. cpu_relax();
  3535. j = inb(tmport) & 0x0f;
  3536. if (j == 0x0f) {
  3537. goto phase_ins;
  3538. }
  3539. if (j == 0x0a) {
  3540. goto phase_cmds;
  3541. }
  3542. if (j == 0x0e) {
  3543. goto try_sync;
  3544. }
  3545. continue;
  3546. phase_outs:
  3547. tmport = wkport + 0x18;
  3548. outb(0x20, tmport);
  3549. tmport += 0x07;
  3550. while ((inb(tmport) & 0x80) == 0x00) {
  3551. if ((inb(tmport) & 0x01) != 0x00) {
  3552. tmport -= 0x06;
  3553. outb(0x00, tmport);
  3554. tmport += 0x06;
  3555. }
  3556. cpu_relax();
  3557. }
  3558. tmport -= 0x08;
  3559. j = inb(tmport);
  3560. if (j == 0x85) {
  3561. goto tar_dcons;
  3562. }
  3563. j &= 0x0f;
  3564. if (j == 0x0f) {
  3565. goto phase_ins;
  3566. }
  3567. if (j == 0x0a) {
  3568. goto phase_cmds;
  3569. }
  3570. if (j == 0x0e) {
  3571. goto phase_outs;
  3572. }
  3573. continue;
  3574. phase_ins:
  3575. tmport = wkport + 0x14;
  3576. outb(0x06, tmport);
  3577. tmport += 0x04;
  3578. outb(0x20, tmport);
  3579. tmport += 0x07;
  3580. k = 0;
  3581. phase_ins1:
  3582. j = inb(tmport);
  3583. if ((j & 0x01) != 0x00) {
  3584. tmport -= 0x06;
  3585. mbuf[k++] = inb(tmport);
  3586. tmport += 0x06;
  3587. goto phase_ins1;
  3588. }
  3589. if ((j & 0x80) == 0x00) {
  3590. goto phase_ins1;
  3591. }
  3592. tmport -= 0x08;
  3593. while ((inb(tmport) & 0x80) == 0x00);
  3594. j = inb(tmport);
  3595. if (j == 0x85) {
  3596. goto tar_dcons;
  3597. }
  3598. j &= 0x0f;
  3599. if (j == 0x0f) {
  3600. goto phase_ins;
  3601. }
  3602. if (j == 0x0a) {
  3603. goto phase_cmds;
  3604. }
  3605. if (j == 0x0e) {
  3606. goto phase_outs;
  3607. }
  3608. continue;
  3609. phase_cmds:
  3610. tmport = wkport + 0x10;
  3611. outb(0x30, tmport);
  3612. tar_dcons:
  3613. tmport = wkport + 0x14;
  3614. outb(0x00, tmport);
  3615. tmport += 0x04;
  3616. outb(0x08, tmport);
  3617. tmport += 0x07;
  3618. while ((inb(tmport) & 0x80) == 0x00)
  3619. cpu_relax();
  3620. tmport -= 0x08;
  3621. j = inb(tmport);
  3622. if (j != 0x16) {
  3623. continue;
  3624. }
  3625. if (mbuf[0] != 0x01) {
  3626. continue;
  3627. }
  3628. if (mbuf[1] != 0x03) {
  3629. continue;
  3630. }
  3631. if (mbuf[4] == 0x00) {
  3632. continue;
  3633. }
  3634. if (mbuf[3] > 0x64) {
  3635. continue;
  3636. }
  3637. if (mbuf[4] > 0x0e) {
  3638. mbuf[4] = 0x0e;
  3639. }
  3640. dev->id[c][i].devsp = mbuf[4];
  3641. if (mbuf[3] < 0x0c){
  3642. j = 0xb0;
  3643. goto set_syn_ok;
  3644. }
  3645. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  3646. j = 0xa0;
  3647. goto set_syn_ok;
  3648. }
  3649. if (mbuf[3] < 0x1a) {
  3650. j = 0x20;
  3651. goto set_syn_ok;
  3652. }
  3653. if (mbuf[3] < 0x33) {
  3654. j = 0x40;
  3655. goto set_syn_ok;
  3656. }
  3657. if (mbuf[3] < 0x4c) {
  3658. j = 0x50;
  3659. goto set_syn_ok;
  3660. }
  3661. j = 0x60;
  3662. set_syn_ok:
  3663. dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
  3664. #ifdef ED_DBGP
  3665. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3666. #endif
  3667. }
  3668. tmport = wkport + 0x16;
  3669. outb(0x80, tmport);
  3670. }
  3671. module_init(atp870u_init);
  3672. module_exit(atp870u_exit);