atp870u.c 85 KB

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