atp870u.c 87 KB

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