atp870u.c 84 KB

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