atp870u.c 87 KB

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