atp870u.c 87 KB

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