atp870u.c 85 KB

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