atp870u.c 85 KB

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