atp870u.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972
  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, struct pt_regs *regs)
  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->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 atp_dev, *p;
  2478. unsigned char setupdata[2][16];
  2479. int count = 0;
  2480. if (pci_enable_device(pdev))
  2481. return -EIO;
  2482. if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  2483. printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
  2484. } else {
  2485. printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
  2486. return -EIO;
  2487. }
  2488. memset(&atp_dev, 0, sizeof atp_dev);
  2489. /*
  2490. * It's probably easier to weed out some revisions like
  2491. * this than via the PCI device table
  2492. */
  2493. if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
  2494. error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atp_dev.chip_ver);
  2495. if (atp_dev.chip_ver < 2)
  2496. return -EIO;
  2497. }
  2498. switch (ent->device) {
  2499. case PCI_DEVICE_ID_ARTOP_AEC7612UW:
  2500. case PCI_DEVICE_ID_ARTOP_AEC7612SUW:
  2501. case ATP880_DEVID1:
  2502. case ATP880_DEVID2:
  2503. case ATP885_DEVID:
  2504. atp_dev.chip_ver = 0x04;
  2505. default:
  2506. break;
  2507. }
  2508. base_io = pci_resource_start(pdev, 0);
  2509. base_io &= 0xfffffff8;
  2510. if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
  2511. error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atp_dev.chip_ver);
  2512. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
  2513. host_id = inb(base_io + 0x39);
  2514. host_id >>= 0x04;
  2515. printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
  2516. " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2517. atp_dev.ioport[0] = base_io + 0x40;
  2518. atp_dev.pciport[0] = base_io + 0x28;
  2519. atp_dev.dev_id = ent->device;
  2520. atp_dev.host_id[0] = host_id;
  2521. tmport = base_io + 0x22;
  2522. atp_dev.scam_on = inb(tmport);
  2523. tmport += 0x13;
  2524. atp_dev.global_map[0] = inb(tmport);
  2525. tmport += 0x07;
  2526. atp_dev.ultra_map[0] = inw(tmport);
  2527. n = 0x3f09;
  2528. next_fblk_880:
  2529. if (n >= 0x4000)
  2530. goto flash_ok_880;
  2531. m = 0;
  2532. outw(n, base_io + 0x34);
  2533. n += 0x0002;
  2534. if (inb(base_io + 0x30) == 0xff)
  2535. goto flash_ok_880;
  2536. atp_dev.sp[0][m++] = inb(base_io + 0x30);
  2537. atp_dev.sp[0][m++] = inb(base_io + 0x31);
  2538. atp_dev.sp[0][m++] = inb(base_io + 0x32);
  2539. atp_dev.sp[0][m++] = inb(base_io + 0x33);
  2540. outw(n, base_io + 0x34);
  2541. n += 0x0002;
  2542. atp_dev.sp[0][m++] = inb(base_io + 0x30);
  2543. atp_dev.sp[0][m++] = inb(base_io + 0x31);
  2544. atp_dev.sp[0][m++] = inb(base_io + 0x32);
  2545. atp_dev.sp[0][m++] = inb(base_io + 0x33);
  2546. outw(n, base_io + 0x34);
  2547. n += 0x0002;
  2548. atp_dev.sp[0][m++] = inb(base_io + 0x30);
  2549. atp_dev.sp[0][m++] = inb(base_io + 0x31);
  2550. atp_dev.sp[0][m++] = inb(base_io + 0x32);
  2551. atp_dev.sp[0][m++] = inb(base_io + 0x33);
  2552. outw(n, base_io + 0x34);
  2553. n += 0x0002;
  2554. atp_dev.sp[0][m++] = inb(base_io + 0x30);
  2555. atp_dev.sp[0][m++] = inb(base_io + 0x31);
  2556. atp_dev.sp[0][m++] = inb(base_io + 0x32);
  2557. atp_dev.sp[0][m++] = inb(base_io + 0x33);
  2558. n += 0x0018;
  2559. goto next_fblk_880;
  2560. flash_ok_880:
  2561. outw(0, base_io + 0x34);
  2562. atp_dev.ultra_map[0] = 0;
  2563. atp_dev.async[0] = 0;
  2564. for (k = 0; k < 16; k++) {
  2565. n = 1;
  2566. n = n << k;
  2567. if (atp_dev.sp[0][k] > 1) {
  2568. atp_dev.ultra_map[0] |= n;
  2569. } else {
  2570. if (atp_dev.sp[0][k] == 0)
  2571. atp_dev.async[0] |= n;
  2572. }
  2573. }
  2574. atp_dev.async[0] = ~(atp_dev.async[0]);
  2575. outb(atp_dev.global_map[0], base_io + 0x35);
  2576. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2577. if (!shpnt)
  2578. return -ENOMEM;
  2579. p = (struct atp_unit *)&shpnt->hostdata;
  2580. atp_dev.host = shpnt;
  2581. atp_dev.pdev = pdev;
  2582. pci_set_drvdata(pdev, p);
  2583. memcpy(p, &atp_dev, sizeof atp_dev);
  2584. if (atp870u_init_tables(shpnt) < 0) {
  2585. printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
  2586. goto unregister;
  2587. }
  2588. if (request_irq(pdev->irq, atp870u_intr_handle, SA_SHIRQ, "atp880i", shpnt)) {
  2589. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2590. goto free_tables;
  2591. }
  2592. spin_lock_irqsave(shpnt->host_lock, flags);
  2593. tmport = base_io + 0x38;
  2594. k = inb(tmport) & 0x80;
  2595. outb(k, tmport);
  2596. tmport += 0x03;
  2597. outb(0x20, tmport);
  2598. mdelay(32);
  2599. outb(0, tmport);
  2600. mdelay(32);
  2601. tmport = base_io + 0x5b;
  2602. inb(tmport);
  2603. tmport -= 0x04;
  2604. inb(tmport);
  2605. tmport = base_io + 0x40;
  2606. outb((host_id | 0x08), tmport);
  2607. tmport += 0x18;
  2608. outb(0, tmport);
  2609. tmport += 0x07;
  2610. while ((inb(tmport) & 0x80) == 0)
  2611. mdelay(1);
  2612. tmport -= 0x08;
  2613. inb(tmport);
  2614. tmport = base_io + 0x41;
  2615. outb(8, tmport++);
  2616. outb(0x7f, tmport);
  2617. tmport = base_io + 0x51;
  2618. outb(0x20, tmport);
  2619. tscam(shpnt);
  2620. is880(p, base_io);
  2621. tmport = base_io + 0x38;
  2622. outb(0xb0, tmport);
  2623. shpnt->max_id = 16;
  2624. shpnt->this_id = host_id;
  2625. shpnt->unique_id = base_io;
  2626. shpnt->io_port = base_io;
  2627. shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */
  2628. shpnt->irq = pdev->irq;
  2629. } else if (ent->device == ATP885_DEVID) {
  2630. printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
  2631. , base_io, pdev->irq);
  2632. atp_dev.pdev = pdev;
  2633. atp_dev.dev_id = ent->device;
  2634. atp_dev.baseport = base_io;
  2635. atp_dev.ioport[0] = base_io + 0x80;
  2636. atp_dev.ioport[1] = base_io + 0xc0;
  2637. atp_dev.pciport[0] = base_io + 0x40;
  2638. atp_dev.pciport[1] = base_io + 0x50;
  2639. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2640. if (!shpnt)
  2641. return -ENOMEM;
  2642. p = (struct atp_unit *)&shpnt->hostdata;
  2643. atp_dev.host = shpnt;
  2644. atp_dev.pdev = pdev;
  2645. pci_set_drvdata(pdev, p);
  2646. memcpy(p, &atp_dev, sizeof(struct atp_unit));
  2647. if (atp870u_init_tables(shpnt) < 0)
  2648. goto unregister;
  2649. #ifdef ED_DBGP
  2650. printk("request_irq() shpnt %p hostdata %p\n", shpnt, p);
  2651. #endif
  2652. if (request_irq(pdev->irq, atp870u_intr_handle, SA_SHIRQ, "atp870u", shpnt)) {
  2653. printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
  2654. goto free_tables;
  2655. }
  2656. spin_lock_irqsave(shpnt->host_lock, flags);
  2657. c=inb(base_io + 0x29);
  2658. outb((c | 0x04),base_io + 0x29);
  2659. n=0x1f80;
  2660. next_fblk_885:
  2661. if (n >= 0x2000) {
  2662. goto flash_ok_885;
  2663. }
  2664. outw(n,base_io + 0x3c);
  2665. if (inl(base_io + 0x38) == 0xffffffff) {
  2666. goto flash_ok_885;
  2667. }
  2668. for (m=0; m < 2; m++) {
  2669. p->global_map[m]= 0;
  2670. for (k=0; k < 4; k++) {
  2671. outw(n++,base_io + 0x3c);
  2672. ((unsigned long *)&setupdata[m][0])[k]=inl(base_io + 0x38);
  2673. }
  2674. for (k=0; k < 4; k++) {
  2675. outw(n++,base_io + 0x3c);
  2676. ((unsigned long *)&p->sp[m][0])[k]=inl(base_io + 0x38);
  2677. }
  2678. n += 8;
  2679. }
  2680. goto next_fblk_885;
  2681. flash_ok_885:
  2682. #ifdef ED_DBGP
  2683. printk( "Flash Read OK\n");
  2684. #endif
  2685. c=inb(base_io + 0x29);
  2686. outb((c & 0xfb),base_io + 0x29);
  2687. for (c=0;c < 2;c++) {
  2688. p->ultra_map[c]=0;
  2689. p->async[c] = 0;
  2690. for (k=0; k < 16; k++) {
  2691. n=1;
  2692. n = n << k;
  2693. if (p->sp[c][k] > 1) {
  2694. p->ultra_map[c] |= n;
  2695. } else {
  2696. if (p->sp[c][k] == 0) {
  2697. p->async[c] |= n;
  2698. }
  2699. }
  2700. }
  2701. p->async[c] = ~(p->async[c]);
  2702. if (p->global_map[c] == 0) {
  2703. k=setupdata[c][1];
  2704. if ((k & 0x40) != 0)
  2705. p->global_map[c] |= 0x20;
  2706. k &= 0x07;
  2707. p->global_map[c] |= k;
  2708. if ((setupdata[c][2] & 0x04) != 0)
  2709. p->global_map[c] |= 0x08;
  2710. p->host_id[c] = setupdata[c][0] & 0x07;
  2711. }
  2712. }
  2713. k = inb(base_io + 0x28) & 0x8f;
  2714. k |= 0x10;
  2715. outb(k, base_io + 0x28);
  2716. outb(0x80, base_io + 0x41);
  2717. outb(0x80, base_io + 0x51);
  2718. mdelay(100);
  2719. outb(0, base_io + 0x41);
  2720. outb(0, base_io + 0x51);
  2721. mdelay(1000);
  2722. inb(base_io + 0x9b);
  2723. inb(base_io + 0x97);
  2724. inb(base_io + 0xdb);
  2725. inb(base_io + 0xd7);
  2726. tmport = base_io + 0x80;
  2727. k=p->host_id[0];
  2728. if (k > 7)
  2729. k = (k & 0x07) | 0x40;
  2730. k |= 0x08;
  2731. outb(k, tmport);
  2732. tmport += 0x18;
  2733. outb(0, tmport);
  2734. tmport += 0x07;
  2735. while ((inb(tmport) & 0x80) == 0)
  2736. cpu_relax();
  2737. tmport -= 0x08;
  2738. inb(tmport);
  2739. tmport = base_io + 0x81;
  2740. outb(8, tmport++);
  2741. outb(0x7f, tmport);
  2742. tmport = base_io + 0x91;
  2743. outb(0x20, tmport);
  2744. tmport = base_io + 0xc0;
  2745. k=p->host_id[1];
  2746. if (k > 7)
  2747. k = (k & 0x07) | 0x40;
  2748. k |= 0x08;
  2749. outb(k, tmport);
  2750. tmport += 0x18;
  2751. outb(0, tmport);
  2752. tmport += 0x07;
  2753. while ((inb(tmport) & 0x80) == 0)
  2754. cpu_relax();
  2755. tmport -= 0x08;
  2756. inb(tmport);
  2757. tmport = base_io + 0xc1;
  2758. outb(8, tmport++);
  2759. outb(0x7f, tmport);
  2760. tmport = base_io + 0xd1;
  2761. outb(0x20, tmport);
  2762. tscam_885();
  2763. printk(KERN_INFO " Scanning Channel A SCSI Device ...\n");
  2764. is885(p, base_io + 0x80, 0);
  2765. printk(KERN_INFO " Scanning Channel B SCSI Device ...\n");
  2766. is885(p, base_io + 0xc0, 1);
  2767. k = inb(base_io + 0x28) & 0xcf;
  2768. k |= 0xc0;
  2769. outb(k, base_io + 0x28);
  2770. k = inb(base_io + 0x1f) | 0x80;
  2771. outb(k, base_io + 0x1f);
  2772. k = inb(base_io + 0x29) | 0x01;
  2773. outb(k, base_io + 0x29);
  2774. #ifdef ED_DBGP
  2775. //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
  2776. #endif
  2777. shpnt->max_id = 16;
  2778. shpnt->max_lun = (p->global_map[0] & 0x07) + 1;
  2779. shpnt->max_channel = 1;
  2780. shpnt->this_id = p->host_id[0];
  2781. shpnt->unique_id = base_io;
  2782. shpnt->io_port = base_io;
  2783. shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */
  2784. shpnt->irq = pdev->irq;
  2785. } else {
  2786. error = pci_read_config_byte(pdev, 0x49, &host_id);
  2787. printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
  2788. "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
  2789. atp_dev.ioport[0] = base_io;
  2790. atp_dev.pciport[0] = base_io + 0x20;
  2791. atp_dev.dev_id = ent->device;
  2792. host_id &= 0x07;
  2793. atp_dev.host_id[0] = host_id;
  2794. tmport = base_io + 0x22;
  2795. atp_dev.scam_on = inb(tmport);
  2796. tmport += 0x0b;
  2797. atp_dev.global_map[0] = inb(tmport++);
  2798. atp_dev.ultra_map[0] = inw(tmport);
  2799. if (atp_dev.ultra_map[0] == 0) {
  2800. atp_dev.scam_on = 0x00;
  2801. atp_dev.global_map[0] = 0x20;
  2802. atp_dev.ultra_map[0] = 0xffff;
  2803. }
  2804. shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
  2805. if (!shpnt)
  2806. return -ENOMEM;
  2807. p = (struct atp_unit *)&shpnt->hostdata;
  2808. atp_dev.host = shpnt;
  2809. atp_dev.pdev = pdev;
  2810. pci_set_drvdata(pdev, p);
  2811. memcpy(p, &atp_dev, sizeof atp_dev);
  2812. if (atp870u_init_tables(shpnt) < 0)
  2813. goto unregister;
  2814. if (request_irq(pdev->irq, atp870u_intr_handle, SA_SHIRQ, "atp870i", shpnt)) {
  2815. printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
  2816. goto free_tables;
  2817. }
  2818. spin_lock_irqsave(shpnt->host_lock, flags);
  2819. if (atp_dev.chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
  2820. tmport = base_io + 0x3e;
  2821. outb(0x00, tmport);
  2822. }
  2823. tmport = base_io + 0x3a;
  2824. k = (inb(tmport) & 0xf3) | 0x10;
  2825. outb(k, tmport);
  2826. outb((k & 0xdf), tmport);
  2827. mdelay(32);
  2828. outb(k, tmport);
  2829. mdelay(32);
  2830. tmport = base_io;
  2831. outb((host_id | 0x08), tmport);
  2832. tmport += 0x18;
  2833. outb(0, tmport);
  2834. tmport += 0x07;
  2835. while ((inb(tmport) & 0x80) == 0)
  2836. mdelay(1);
  2837. tmport -= 0x08;
  2838. inb(tmport);
  2839. tmport = base_io + 1;
  2840. outb(8, tmport++);
  2841. outb(0x7f, tmport);
  2842. tmport = base_io + 0x11;
  2843. outb(0x20, tmport);
  2844. tscam(shpnt);
  2845. is870(p, base_io);
  2846. tmport = base_io + 0x3a;
  2847. outb((inb(tmport) & 0xef), tmport);
  2848. tmport++;
  2849. outb((inb(tmport) | 0x20), tmport);
  2850. if (atp_dev.chip_ver == 4)
  2851. shpnt->max_id = 16;
  2852. else
  2853. shpnt->max_id = 7;
  2854. shpnt->this_id = host_id;
  2855. shpnt->unique_id = base_io;
  2856. shpnt->io_port = base_io;
  2857. shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */
  2858. shpnt->irq = pdev->irq;
  2859. }
  2860. spin_unlock_irqrestore(shpnt->host_lock, flags);
  2861. if(ent->device==ATP885_DEVID) {
  2862. if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */
  2863. goto request_io_fail;
  2864. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2865. if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */
  2866. goto request_io_fail;
  2867. } else {
  2868. if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */
  2869. goto request_io_fail;
  2870. }
  2871. count++;
  2872. if (scsi_add_host(shpnt, &pdev->dev))
  2873. goto scsi_add_fail;
  2874. scsi_scan_host(shpnt);
  2875. #ifdef ED_DBGP
  2876. printk("atp870u_prob : exit\n");
  2877. #endif
  2878. return 0;
  2879. scsi_add_fail:
  2880. printk("atp870u_prob:scsi_add_fail\n");
  2881. if(ent->device==ATP885_DEVID) {
  2882. release_region(base_io, 0xff);
  2883. } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
  2884. release_region(base_io, 0x60);
  2885. } else {
  2886. release_region(base_io, 0x40);
  2887. }
  2888. request_io_fail:
  2889. printk("atp870u_prob:request_io_fail\n");
  2890. free_irq(pdev->irq, shpnt);
  2891. free_tables:
  2892. printk("atp870u_prob:free_table\n");
  2893. atp870u_free_tables(shpnt);
  2894. unregister:
  2895. printk("atp870u_prob:unregister\n");
  2896. scsi_host_put(shpnt);
  2897. return -1;
  2898. }
  2899. /* The abort command does not leave the device in a clean state where
  2900. it is available to be used again. Until this gets worked out, we will
  2901. leave it commented out. */
  2902. static int atp870u_abort(struct scsi_cmnd * SCpnt)
  2903. {
  2904. unsigned char j, k, c;
  2905. struct scsi_cmnd *workrequ;
  2906. unsigned int tmport;
  2907. struct atp_unit *dev;
  2908. struct Scsi_Host *host;
  2909. host = SCpnt->device->host;
  2910. dev = (struct atp_unit *)&host->hostdata;
  2911. c = scmd_channel(SCpnt);
  2912. printk(" atp870u: abort Channel = %x \n", c);
  2913. printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
  2914. printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
  2915. tmport = dev->ioport[c];
  2916. for (j = 0; j < 0x18; j++) {
  2917. printk(" r%2x=%2x", j, inb(tmport++));
  2918. }
  2919. tmport += 0x04;
  2920. printk(" r1c=%2x", inb(tmport));
  2921. tmport += 0x03;
  2922. printk(" r1f=%2x in_snd=%2x ", inb(tmport), dev->in_snd[c]);
  2923. tmport= dev->pciport[c];
  2924. printk(" d00=%2x", inb(tmport));
  2925. tmport += 0x02;
  2926. printk(" d02=%2x", inb(tmport));
  2927. for(j=0;j<16;j++) {
  2928. if (dev->id[c][j].curr_req != NULL) {
  2929. workrequ = dev->id[c][j].curr_req;
  2930. printk("\n que cdb= ");
  2931. for (k=0; k < workrequ->cmd_len; k++) {
  2932. printk(" %2x ",workrequ->cmnd[k]);
  2933. }
  2934. printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
  2935. }
  2936. }
  2937. return SUCCESS;
  2938. }
  2939. static const char *atp870u_info(struct Scsi_Host *notused)
  2940. {
  2941. static char buffer[128];
  2942. strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
  2943. return buffer;
  2944. }
  2945. #define BLS buffer + len + size
  2946. static int atp870u_proc_info(struct Scsi_Host *HBAptr, char *buffer,
  2947. char **start, off_t offset, int length, int inout)
  2948. {
  2949. static u8 buff[512];
  2950. int size = 0;
  2951. int len = 0;
  2952. off_t begin = 0;
  2953. off_t pos = 0;
  2954. if (inout)
  2955. return -EINVAL;
  2956. if (offset == 0)
  2957. memset(buff, 0, sizeof(buff));
  2958. size += sprintf(BLS, "ACARD AEC-671X Driver Version: 2.6+ac\n");
  2959. len += size;
  2960. pos = begin + len;
  2961. size = 0;
  2962. size += sprintf(BLS, "\n");
  2963. size += sprintf(BLS, "Adapter Configuration:\n");
  2964. size += sprintf(BLS, " Base IO: %#.4lx\n", HBAptr->io_port);
  2965. size += sprintf(BLS, " IRQ: %d\n", HBAptr->irq);
  2966. len += size;
  2967. pos = begin + len;
  2968. *start = buffer + (offset - begin); /* Start of wanted data */
  2969. len -= (offset - begin); /* Start slop */
  2970. if (len > length) {
  2971. len = length; /* Ending slop */
  2972. }
  2973. return (len);
  2974. }
  2975. static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
  2976. sector_t capacity, int *ip)
  2977. {
  2978. int heads, sectors, cylinders;
  2979. heads = 64;
  2980. sectors = 32;
  2981. cylinders = (unsigned long)capacity / (heads * sectors);
  2982. if (cylinders > 1024) {
  2983. heads = 255;
  2984. sectors = 63;
  2985. cylinders = (unsigned long)capacity / (heads * sectors);
  2986. }
  2987. ip[0] = heads;
  2988. ip[1] = sectors;
  2989. ip[2] = cylinders;
  2990. return 0;
  2991. }
  2992. static void atp870u_remove (struct pci_dev *pdev)
  2993. {
  2994. struct atp_unit *devext = pci_get_drvdata(pdev);
  2995. struct Scsi_Host *pshost = devext->host;
  2996. scsi_remove_host(pshost);
  2997. printk(KERN_INFO "free_irq : %d\n",pshost->irq);
  2998. free_irq(pshost->irq, pshost);
  2999. release_region(pshost->io_port, pshost->n_io_port);
  3000. printk(KERN_INFO "atp870u_free_tables : %p\n",pshost);
  3001. atp870u_free_tables(pshost);
  3002. printk(KERN_INFO "scsi_host_put : %p\n",pshost);
  3003. scsi_host_put(pshost);
  3004. printk(KERN_INFO "pci_set_drvdata : %p\n",pdev);
  3005. pci_set_drvdata(pdev, NULL);
  3006. }
  3007. MODULE_LICENSE("GPL");
  3008. static struct scsi_host_template atp870u_template = {
  3009. .module = THIS_MODULE,
  3010. .name = "atp870u" /* name */,
  3011. .proc_name = "atp870u",
  3012. .proc_info = atp870u_proc_info,
  3013. .info = atp870u_info /* info */,
  3014. .queuecommand = atp870u_queuecommand /* queuecommand */,
  3015. .eh_abort_handler = atp870u_abort /* abort */,
  3016. .bios_param = atp870u_biosparam /* biosparm */,
  3017. .can_queue = qcnt /* can_queue */,
  3018. .this_id = 7 /* SCSI ID */,
  3019. .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/,
  3020. .cmd_per_lun = ATP870U_CMDLUN /* commands per lun */,
  3021. .use_clustering = ENABLE_CLUSTERING,
  3022. .max_sectors = ATP870U_MAX_SECTORS,
  3023. };
  3024. static struct pci_device_id atp870u_id_table[] = {
  3025. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
  3026. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
  3027. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
  3028. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
  3029. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
  3030. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
  3031. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
  3032. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
  3033. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
  3034. { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
  3035. { 0, },
  3036. };
  3037. MODULE_DEVICE_TABLE(pci, atp870u_id_table);
  3038. static struct pci_driver atp870u_driver = {
  3039. .id_table = atp870u_id_table,
  3040. .name = "atp870u",
  3041. .probe = atp870u_probe,
  3042. .remove = __devexit_p(atp870u_remove),
  3043. };
  3044. static int __init atp870u_init(void)
  3045. {
  3046. #ifdef ED_DBGP
  3047. printk("atp870u_init: Entry\n");
  3048. #endif
  3049. return pci_register_driver(&atp870u_driver);
  3050. }
  3051. static void __exit atp870u_exit(void)
  3052. {
  3053. #ifdef ED_DBGP
  3054. printk("atp870u_exit: Entry\n");
  3055. #endif
  3056. pci_unregister_driver(&atp870u_driver);
  3057. }
  3058. static void tscam_885(void)
  3059. {
  3060. unsigned char i;
  3061. for (i = 0; i < 0x2; i++) {
  3062. mdelay(300);
  3063. }
  3064. return;
  3065. }
  3066. static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c)
  3067. {
  3068. unsigned int tmport;
  3069. unsigned char i, j, k, rmb, n, lvdmode;
  3070. unsigned short int m;
  3071. static unsigned char mbuf[512];
  3072. static unsigned char satn[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
  3073. static unsigned char inqd[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
  3074. static unsigned char synn[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3075. unsigned char synu[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3076. static unsigned char synw[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
  3077. unsigned char synuw[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
  3078. static unsigned char wide[6] = {0x80, 1, 2, 3, 1, 0};
  3079. static unsigned char u3[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
  3080. lvdmode=inb(wkport + 0x1b) >> 7;
  3081. for (i = 0; i < 16; i++) {
  3082. m = 1;
  3083. m = m << i;
  3084. if ((m & dev->active_id[c]) != 0) {
  3085. continue;
  3086. }
  3087. if (i == dev->host_id[c]) {
  3088. printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
  3089. continue;
  3090. }
  3091. tmport = wkport + 0x1b;
  3092. outb(0x01, tmport);
  3093. tmport = wkport + 0x01;
  3094. outb(0x08, tmport++);
  3095. outb(0x7f, tmport++);
  3096. outb(satn[0], tmport++);
  3097. outb(satn[1], tmport++);
  3098. outb(satn[2], tmport++);
  3099. outb(satn[3], tmport++);
  3100. outb(satn[4], tmport++);
  3101. outb(satn[5], tmport++);
  3102. tmport += 0x06;
  3103. outb(0, tmport);
  3104. tmport += 0x02;
  3105. outb(dev->id[c][i].devsp, tmport++);
  3106. outb(0, tmport++);
  3107. outb(satn[6], tmport++);
  3108. outb(satn[7], tmport++);
  3109. j = i;
  3110. if ((j & 0x08) != 0) {
  3111. j = (j & 0x07) | 0x40;
  3112. }
  3113. outb(j, tmport);
  3114. tmport += 0x03;
  3115. outb(satn[8], tmport);
  3116. tmport += 0x07;
  3117. while ((inb(tmport) & 0x80) == 0x00)
  3118. cpu_relax();
  3119. tmport -= 0x08;
  3120. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3121. continue;
  3122. }
  3123. while (inb(tmport) != 0x8e)
  3124. cpu_relax();
  3125. dev->active_id[c] |= m;
  3126. tmport = wkport + 0x10;
  3127. outb(0x30, tmport);
  3128. tmport = wkport + 0x14;
  3129. outb(0x00, tmport);
  3130. phase_cmd:
  3131. tmport = wkport + 0x18;
  3132. outb(0x08, tmport);
  3133. tmport += 0x07;
  3134. while ((inb(tmport) & 0x80) == 0x00)
  3135. cpu_relax();
  3136. tmport -= 0x08;
  3137. j = inb(tmport);
  3138. if (j != 0x16) {
  3139. tmport = wkport + 0x10;
  3140. outb(0x41, tmport);
  3141. goto phase_cmd;
  3142. }
  3143. sel_ok:
  3144. tmport = wkport + 0x03;
  3145. outb(inqd[0], tmport++);
  3146. outb(inqd[1], tmport++);
  3147. outb(inqd[2], tmport++);
  3148. outb(inqd[3], tmport++);
  3149. outb(inqd[4], tmport++);
  3150. outb(inqd[5], tmport);
  3151. tmport += 0x07;
  3152. outb(0, tmport);
  3153. tmport += 0x02;
  3154. outb(dev->id[c][i].devsp, tmport++);
  3155. outb(0, tmport++);
  3156. outb(inqd[6], tmport++);
  3157. outb(inqd[7], tmport++);
  3158. tmport += 0x03;
  3159. outb(inqd[8], tmport);
  3160. tmport += 0x07;
  3161. while ((inb(tmport) & 0x80) == 0x00)
  3162. cpu_relax();
  3163. tmport -= 0x08;
  3164. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3165. continue;
  3166. }
  3167. while (inb(tmport) != 0x8e)
  3168. cpu_relax();
  3169. tmport = wkport + 0x1b;
  3170. outb(0x00, tmport);
  3171. tmport = wkport + 0x18;
  3172. outb(0x08, tmport);
  3173. tmport += 0x07;
  3174. j = 0;
  3175. rd_inq_data:
  3176. k = inb(tmport);
  3177. if ((k & 0x01) != 0) {
  3178. tmport -= 0x06;
  3179. mbuf[j++] = inb(tmport);
  3180. tmport += 0x06;
  3181. goto rd_inq_data;
  3182. }
  3183. if ((k & 0x80) == 0) {
  3184. goto rd_inq_data;
  3185. }
  3186. tmport -= 0x08;
  3187. j = inb(tmport);
  3188. if (j == 0x16) {
  3189. goto inq_ok;
  3190. }
  3191. tmport = wkport + 0x10;
  3192. outb(0x46, tmport);
  3193. tmport += 0x02;
  3194. outb(0, tmport++);
  3195. outb(0, tmport++);
  3196. outb(0, tmport++);
  3197. tmport += 0x03;
  3198. outb(0x08, tmport);
  3199. tmport += 0x07;
  3200. while ((inb(tmport) & 0x80) == 0x00)
  3201. cpu_relax();
  3202. tmport -= 0x08;
  3203. if (inb(tmport) != 0x16) {
  3204. goto sel_ok;
  3205. }
  3206. inq_ok:
  3207. mbuf[36] = 0;
  3208. printk( KERN_INFO" ID: %2d %s\n", i, &mbuf[8]);
  3209. dev->id[c][i].devtype = mbuf[0];
  3210. rmb = mbuf[1];
  3211. n = mbuf[7];
  3212. if ((mbuf[7] & 0x60) == 0) {
  3213. goto not_wide;
  3214. }
  3215. if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) {
  3216. goto not_wide;
  3217. }
  3218. if (lvdmode == 0) {
  3219. goto chg_wide;
  3220. }
  3221. if (dev->sp[c][i] != 0x04) { // force u2
  3222. goto chg_wide;
  3223. }
  3224. tmport = wkport + 0x1b;
  3225. outb(0x01, tmport);
  3226. tmport = wkport + 0x03;
  3227. outb(satn[0], tmport++);
  3228. outb(satn[1], tmport++);
  3229. outb(satn[2], tmport++);
  3230. outb(satn[3], tmport++);
  3231. outb(satn[4], tmport++);
  3232. outb(satn[5], tmport++);
  3233. tmport += 0x06;
  3234. outb(0, tmport);
  3235. tmport += 0x02;
  3236. outb(dev->id[c][i].devsp, tmport++);
  3237. outb(0, tmport++);
  3238. outb(satn[6], tmport++);
  3239. outb(satn[7], tmport++);
  3240. tmport += 0x03;
  3241. outb(satn[8], tmport);
  3242. tmport += 0x07;
  3243. while ((inb(tmport) & 0x80) == 0x00)
  3244. cpu_relax();
  3245. tmport -= 0x08;
  3246. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3247. continue;
  3248. }
  3249. while (inb(tmport) != 0x8e)
  3250. cpu_relax();
  3251. try_u3:
  3252. j = 0;
  3253. tmport = wkport + 0x14;
  3254. outb(0x09, tmport);
  3255. tmport += 0x04;
  3256. outb(0x20, tmport);
  3257. tmport += 0x07;
  3258. while ((inb(tmport) & 0x80) == 0) {
  3259. if ((inb(tmport) & 0x01) != 0) {
  3260. tmport -= 0x06;
  3261. outb(u3[j++], tmport);
  3262. tmport += 0x06;
  3263. }
  3264. cpu_relax();
  3265. }
  3266. tmport -= 0x08;
  3267. while ((inb(tmport) & 0x80) == 0x00)
  3268. cpu_relax();
  3269. j = inb(tmport) & 0x0f;
  3270. if (j == 0x0f) {
  3271. goto u3p_in;
  3272. }
  3273. if (j == 0x0a) {
  3274. goto u3p_cmd;
  3275. }
  3276. if (j == 0x0e) {
  3277. goto try_u3;
  3278. }
  3279. continue;
  3280. u3p_out:
  3281. tmport = wkport + 0x18;
  3282. outb(0x20, tmport);
  3283. tmport += 0x07;
  3284. while ((inb(tmport) & 0x80) == 0) {
  3285. if ((inb(tmport) & 0x01) != 0) {
  3286. tmport -= 0x06;
  3287. outb(0, tmport);
  3288. tmport += 0x06;
  3289. }
  3290. cpu_relax();
  3291. }
  3292. tmport -= 0x08;
  3293. j = inb(tmport) & 0x0f;
  3294. if (j == 0x0f) {
  3295. goto u3p_in;
  3296. }
  3297. if (j == 0x0a) {
  3298. goto u3p_cmd;
  3299. }
  3300. if (j == 0x0e) {
  3301. goto u3p_out;
  3302. }
  3303. continue;
  3304. u3p_in:
  3305. tmport = wkport + 0x14;
  3306. outb(0x09, tmport);
  3307. tmport += 0x04;
  3308. outb(0x20, tmport);
  3309. tmport += 0x07;
  3310. k = 0;
  3311. u3p_in1:
  3312. j = inb(tmport);
  3313. if ((j & 0x01) != 0) {
  3314. tmport -= 0x06;
  3315. mbuf[k++] = inb(tmport);
  3316. tmport += 0x06;
  3317. goto u3p_in1;
  3318. }
  3319. if ((j & 0x80) == 0x00) {
  3320. goto u3p_in1;
  3321. }
  3322. tmport -= 0x08;
  3323. j = inb(tmport) & 0x0f;
  3324. if (j == 0x0f) {
  3325. goto u3p_in;
  3326. }
  3327. if (j == 0x0a) {
  3328. goto u3p_cmd;
  3329. }
  3330. if (j == 0x0e) {
  3331. goto u3p_out;
  3332. }
  3333. continue;
  3334. u3p_cmd:
  3335. tmport = wkport + 0x10;
  3336. outb(0x30, tmport);
  3337. tmport = wkport + 0x14;
  3338. outb(0x00, tmport);
  3339. tmport += 0x04;
  3340. outb(0x08, tmport);
  3341. tmport += 0x07;
  3342. while ((inb(tmport) & 0x80) == 0x00);
  3343. tmport -= 0x08;
  3344. j = inb(tmport);
  3345. if (j != 0x16) {
  3346. if (j == 0x4e) {
  3347. goto u3p_out;
  3348. }
  3349. continue;
  3350. }
  3351. if (mbuf[0] != 0x01) {
  3352. goto chg_wide;
  3353. }
  3354. if (mbuf[1] != 0x06) {
  3355. goto chg_wide;
  3356. }
  3357. if (mbuf[2] != 0x04) {
  3358. goto chg_wide;
  3359. }
  3360. if (mbuf[3] == 0x09) {
  3361. m = 1;
  3362. m = m << i;
  3363. dev->wide_id[c] |= m;
  3364. dev->id[c][i].devsp = 0xce;
  3365. #ifdef ED_DBGP
  3366. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3367. #endif
  3368. continue;
  3369. }
  3370. chg_wide:
  3371. tmport = wkport + 0x1b;
  3372. outb(0x01, tmport);
  3373. tmport = wkport + 0x03;
  3374. outb(satn[0], tmport++);
  3375. outb(satn[1], tmport++);
  3376. outb(satn[2], tmport++);
  3377. outb(satn[3], tmport++);
  3378. outb(satn[4], tmport++);
  3379. outb(satn[5], tmport++);
  3380. tmport += 0x06;
  3381. outb(0, tmport);
  3382. tmport += 0x02;
  3383. outb(dev->id[c][i].devsp, tmport++);
  3384. outb(0, tmport++);
  3385. outb(satn[6], tmport++);
  3386. outb(satn[7], tmport++);
  3387. tmport += 0x03;
  3388. outb(satn[8], tmport);
  3389. tmport += 0x07;
  3390. while ((inb(tmport) & 0x80) == 0x00)
  3391. cpu_relax();
  3392. tmport -= 0x08;
  3393. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3394. continue;
  3395. }
  3396. while (inb(tmport) != 0x8e)
  3397. cpu_relax();
  3398. try_wide:
  3399. j = 0;
  3400. tmport = wkport + 0x14;
  3401. outb(0x05, tmport);
  3402. tmport += 0x04;
  3403. outb(0x20, tmport);
  3404. tmport += 0x07;
  3405. while ((inb(tmport) & 0x80) == 0) {
  3406. if ((inb(tmport) & 0x01) != 0) {
  3407. tmport -= 0x06;
  3408. outb(wide[j++], tmport);
  3409. tmport += 0x06;
  3410. }
  3411. cpu_relax();
  3412. }
  3413. tmport -= 0x08;
  3414. while ((inb(tmport) & 0x80) == 0x00)
  3415. cpu_relax();
  3416. j = inb(tmport) & 0x0f;
  3417. if (j == 0x0f) {
  3418. goto widep_in;
  3419. }
  3420. if (j == 0x0a) {
  3421. goto widep_cmd;
  3422. }
  3423. if (j == 0x0e) {
  3424. goto try_wide;
  3425. }
  3426. continue;
  3427. widep_out:
  3428. tmport = wkport + 0x18;
  3429. outb(0x20, tmport);
  3430. tmport += 0x07;
  3431. while ((inb(tmport) & 0x80) == 0) {
  3432. if ((inb(tmport) & 0x01) != 0) {
  3433. tmport -= 0x06;
  3434. outb(0, tmport);
  3435. tmport += 0x06;
  3436. }
  3437. cpu_relax();
  3438. }
  3439. tmport -= 0x08;
  3440. j = inb(tmport) & 0x0f;
  3441. if (j == 0x0f) {
  3442. goto widep_in;
  3443. }
  3444. if (j == 0x0a) {
  3445. goto widep_cmd;
  3446. }
  3447. if (j == 0x0e) {
  3448. goto widep_out;
  3449. }
  3450. continue;
  3451. widep_in:
  3452. tmport = wkport + 0x14;
  3453. outb(0xff, tmport);
  3454. tmport += 0x04;
  3455. outb(0x20, tmport);
  3456. tmport += 0x07;
  3457. k = 0;
  3458. widep_in1:
  3459. j = inb(tmport);
  3460. if ((j & 0x01) != 0) {
  3461. tmport -= 0x06;
  3462. mbuf[k++] = inb(tmport);
  3463. tmport += 0x06;
  3464. goto widep_in1;
  3465. }
  3466. if ((j & 0x80) == 0x00) {
  3467. goto widep_in1;
  3468. }
  3469. tmport -= 0x08;
  3470. j = inb(tmport) & 0x0f;
  3471. if (j == 0x0f) {
  3472. goto widep_in;
  3473. }
  3474. if (j == 0x0a) {
  3475. goto widep_cmd;
  3476. }
  3477. if (j == 0x0e) {
  3478. goto widep_out;
  3479. }
  3480. continue;
  3481. widep_cmd:
  3482. tmport = wkport + 0x10;
  3483. outb(0x30, tmport);
  3484. tmport = wkport + 0x14;
  3485. outb(0x00, tmport);
  3486. tmport += 0x04;
  3487. outb(0x08, tmport);
  3488. tmport += 0x07;
  3489. while ((inb(tmport) & 0x80) == 0x00)
  3490. cpu_relax();
  3491. tmport -= 0x08;
  3492. j = inb(tmport);
  3493. if (j != 0x16) {
  3494. if (j == 0x4e) {
  3495. goto widep_out;
  3496. }
  3497. continue;
  3498. }
  3499. if (mbuf[0] != 0x01) {
  3500. goto not_wide;
  3501. }
  3502. if (mbuf[1] != 0x02) {
  3503. goto not_wide;
  3504. }
  3505. if (mbuf[2] != 0x03) {
  3506. goto not_wide;
  3507. }
  3508. if (mbuf[3] != 0x01) {
  3509. goto not_wide;
  3510. }
  3511. m = 1;
  3512. m = m << i;
  3513. dev->wide_id[c] |= m;
  3514. not_wide:
  3515. if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) ||
  3516. ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
  3517. m = 1;
  3518. m = m << i;
  3519. if ((dev->async[c] & m) != 0) {
  3520. goto set_sync;
  3521. }
  3522. }
  3523. continue;
  3524. set_sync:
  3525. if (dev->sp[c][i] == 0x02) {
  3526. synu[4]=0x0c;
  3527. synuw[4]=0x0c;
  3528. } else {
  3529. if (dev->sp[c][i] >= 0x03) {
  3530. synu[4]=0x0a;
  3531. synuw[4]=0x0a;
  3532. }
  3533. }
  3534. tmport = wkport + 0x1b;
  3535. j = 0;
  3536. if ((m & dev->wide_id[c]) != 0) {
  3537. j |= 0x01;
  3538. }
  3539. outb(j, tmport);
  3540. tmport = wkport + 0x03;
  3541. outb(satn[0], tmport++);
  3542. outb(satn[1], tmport++);
  3543. outb(satn[2], tmport++);
  3544. outb(satn[3], tmport++);
  3545. outb(satn[4], tmport++);
  3546. outb(satn[5], tmport++);
  3547. tmport += 0x06;
  3548. outb(0, tmport);
  3549. tmport += 0x02;
  3550. outb(dev->id[c][i].devsp, tmport++);
  3551. outb(0, tmport++);
  3552. outb(satn[6], tmport++);
  3553. outb(satn[7], tmport++);
  3554. tmport += 0x03;
  3555. outb(satn[8], tmport);
  3556. tmport += 0x07;
  3557. while ((inb(tmport) & 0x80) == 0x00)
  3558. cpu_relax();
  3559. tmport -= 0x08;
  3560. if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
  3561. continue;
  3562. }
  3563. while (inb(tmport) != 0x8e)
  3564. cpu_relax();
  3565. try_sync:
  3566. j = 0;
  3567. tmport = wkport + 0x14;
  3568. outb(0x06, tmport);
  3569. tmport += 0x04;
  3570. outb(0x20, tmport);
  3571. tmport += 0x07;
  3572. while ((inb(tmport) & 0x80) == 0) {
  3573. if ((inb(tmport) & 0x01) != 0) {
  3574. tmport -= 0x06;
  3575. if ((m & dev->wide_id[c]) != 0) {
  3576. if ((m & dev->ultra_map[c]) != 0) {
  3577. outb(synuw[j++], tmport);
  3578. } else {
  3579. outb(synw[j++], tmport);
  3580. }
  3581. } else {
  3582. if ((m & dev->ultra_map[c]) != 0) {
  3583. outb(synu[j++], tmport);
  3584. } else {
  3585. outb(synn[j++], tmport);
  3586. }
  3587. }
  3588. tmport += 0x06;
  3589. }
  3590. }
  3591. tmport -= 0x08;
  3592. while ((inb(tmport) & 0x80) == 0x00)
  3593. cpu_relax();
  3594. j = inb(tmport) & 0x0f;
  3595. if (j == 0x0f) {
  3596. goto phase_ins;
  3597. }
  3598. if (j == 0x0a) {
  3599. goto phase_cmds;
  3600. }
  3601. if (j == 0x0e) {
  3602. goto try_sync;
  3603. }
  3604. continue;
  3605. phase_outs:
  3606. tmport = wkport + 0x18;
  3607. outb(0x20, tmport);
  3608. tmport += 0x07;
  3609. while ((inb(tmport) & 0x80) == 0x00) {
  3610. if ((inb(tmport) & 0x01) != 0x00) {
  3611. tmport -= 0x06;
  3612. outb(0x00, tmport);
  3613. tmport += 0x06;
  3614. }
  3615. cpu_relax();
  3616. }
  3617. tmport -= 0x08;
  3618. j = inb(tmport);
  3619. if (j == 0x85) {
  3620. goto tar_dcons;
  3621. }
  3622. j &= 0x0f;
  3623. if (j == 0x0f) {
  3624. goto phase_ins;
  3625. }
  3626. if (j == 0x0a) {
  3627. goto phase_cmds;
  3628. }
  3629. if (j == 0x0e) {
  3630. goto phase_outs;
  3631. }
  3632. continue;
  3633. phase_ins:
  3634. tmport = wkport + 0x14;
  3635. outb(0x06, tmport);
  3636. tmport += 0x04;
  3637. outb(0x20, tmport);
  3638. tmport += 0x07;
  3639. k = 0;
  3640. phase_ins1:
  3641. j = inb(tmport);
  3642. if ((j & 0x01) != 0x00) {
  3643. tmport -= 0x06;
  3644. mbuf[k++] = inb(tmport);
  3645. tmport += 0x06;
  3646. goto phase_ins1;
  3647. }
  3648. if ((j & 0x80) == 0x00) {
  3649. goto phase_ins1;
  3650. }
  3651. tmport -= 0x08;
  3652. while ((inb(tmport) & 0x80) == 0x00);
  3653. j = inb(tmport);
  3654. if (j == 0x85) {
  3655. goto tar_dcons;
  3656. }
  3657. j &= 0x0f;
  3658. if (j == 0x0f) {
  3659. goto phase_ins;
  3660. }
  3661. if (j == 0x0a) {
  3662. goto phase_cmds;
  3663. }
  3664. if (j == 0x0e) {
  3665. goto phase_outs;
  3666. }
  3667. continue;
  3668. phase_cmds:
  3669. tmport = wkport + 0x10;
  3670. outb(0x30, tmport);
  3671. tar_dcons:
  3672. tmport = wkport + 0x14;
  3673. outb(0x00, tmport);
  3674. tmport += 0x04;
  3675. outb(0x08, tmport);
  3676. tmport += 0x07;
  3677. while ((inb(tmport) & 0x80) == 0x00)
  3678. cpu_relax();
  3679. tmport -= 0x08;
  3680. j = inb(tmport);
  3681. if (j != 0x16) {
  3682. continue;
  3683. }
  3684. if (mbuf[0] != 0x01) {
  3685. continue;
  3686. }
  3687. if (mbuf[1] != 0x03) {
  3688. continue;
  3689. }
  3690. if (mbuf[4] == 0x00) {
  3691. continue;
  3692. }
  3693. if (mbuf[3] > 0x64) {
  3694. continue;
  3695. }
  3696. if (mbuf[4] > 0x0e) {
  3697. mbuf[4] = 0x0e;
  3698. }
  3699. dev->id[c][i].devsp = mbuf[4];
  3700. if (mbuf[3] < 0x0c){
  3701. j = 0xb0;
  3702. goto set_syn_ok;
  3703. }
  3704. if ((mbuf[3] < 0x0d) && (rmb == 0)) {
  3705. j = 0xa0;
  3706. goto set_syn_ok;
  3707. }
  3708. if (mbuf[3] < 0x1a) {
  3709. j = 0x20;
  3710. goto set_syn_ok;
  3711. }
  3712. if (mbuf[3] < 0x33) {
  3713. j = 0x40;
  3714. goto set_syn_ok;
  3715. }
  3716. if (mbuf[3] < 0x4c) {
  3717. j = 0x50;
  3718. goto set_syn_ok;
  3719. }
  3720. j = 0x60;
  3721. set_syn_ok:
  3722. dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
  3723. #ifdef ED_DBGP
  3724. printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
  3725. #endif
  3726. }
  3727. tmport = wkport + 0x16;
  3728. outb(0x80, tmport);
  3729. }
  3730. module_init(atp870u_init);
  3731. module_exit(atp870u_exit);