atp870u.c 84 KB

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