cpqfcTSinit.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  1. /* Copyright(c) 2000, Compaq Computer Corporation
  2. * Fibre Channel Host Bus Adapter
  3. * 64-bit, 66MHz PCI
  4. * Originally developed and tested on:
  5. * (front): [chip] Tachyon TS HPFC-5166A/1.2 L2C1090 ...
  6. * SP# P225CXCBFIEL6T, Rev XC
  7. * SP# 161290-001, Rev XD
  8. * (back): Board No. 010008-001 A/W Rev X5, FAB REV X5
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2, or (at your option) any
  13. * later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. * Written by Don Zimmerman
  20. * IOCTL and procfs added by Jouke Numan
  21. * SMP testing by Chel Van Gennip
  22. *
  23. * portions copied from:
  24. * QLogic CPQFCTS SCSI-FCP
  25. * Written by Erik H. Moe, ehm@cris.com
  26. * Copyright 1995, Erik H. Moe
  27. * Renamed and updated to 1.3.x by Michael Griffith <grif@cs.ucr.edu>
  28. * Chris Loveland <cwl@iol.unh.edu> to support the isp2100 and isp2200
  29. */
  30. #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
  31. #include <linux/config.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/module.h>
  34. #include <linux/version.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/kernel.h>
  37. #include <linux/string.h>
  38. #include <linux/types.h>
  39. #include <linux/pci.h>
  40. #include <linux/delay.h>
  41. #include <linux/timer.h>
  42. #include <linux/init.h>
  43. #include <linux/ioport.h> // request_region() prototype
  44. #include <linux/completion.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h> // ioctl related
  47. #include <asm/irq.h>
  48. #include <linux/spinlock.h>
  49. #include "scsi.h"
  50. #include <scsi/scsi_host.h>
  51. #include <scsi/scsi_ioctl.h>
  52. #include "cpqfcTSchip.h"
  53. #include "cpqfcTSstructs.h"
  54. #include "cpqfcTStrigger.h"
  55. #include "cpqfcTS.h"
  56. /* Embedded module documentation macros - see module.h */
  57. MODULE_AUTHOR("Compaq Computer Corporation");
  58. MODULE_DESCRIPTION("Driver for Compaq 64-bit/66Mhz PCI Fibre Channel HBA v. 2.5.4");
  59. MODULE_LICENSE("GPL");
  60. int cpqfcTS_TargetDeviceReset( Scsi_Device *ScsiDev, unsigned int reset_flags);
  61. // This struct was originally defined in
  62. // /usr/src/linux/include/linux/proc_fs.h
  63. // since it's only partially implemented, we only use first
  64. // few fields...
  65. // NOTE: proc_fs changes in 2.4 kernel
  66. #if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
  67. static struct proc_dir_entry proc_scsi_cpqfcTS =
  68. {
  69. PROC_SCSI_CPQFCTS, // ushort low_ino (enumerated list)
  70. 7, // ushort namelen
  71. DEV_NAME, // const char* name
  72. S_IFDIR | S_IRUGO | S_IXUGO, // mode_t mode
  73. 2 // nlink_t nlink
  74. // etc. ...
  75. };
  76. #endif
  77. #if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,7)
  78. # define CPQFC_DECLARE_COMPLETION(x) DECLARE_COMPLETION(x)
  79. # define CPQFC_WAITING waiting
  80. # define CPQFC_COMPLETE(x) complete(x)
  81. # define CPQFC_WAIT_FOR_COMPLETION(x) wait_for_completion(x);
  82. #else
  83. # define CPQFC_DECLARE_COMPLETION(x) DECLARE_MUTEX_LOCKED(x)
  84. # define CPQFC_WAITING sem
  85. # define CPQFC_COMPLETE(x) up(x)
  86. # define CPQFC_WAIT_FOR_COMPLETION(x) down(x)
  87. #endif
  88. static int cpqfc_alloc_private_data_pool(CPQFCHBA *hba);
  89. /* local function to load our per-HBA (local) data for chip
  90. registers, FC link state, all FC exchanges, etc.
  91. We allocate space and compute address offsets for the
  92. most frequently accessed addresses; others (like World Wide
  93. Name) are not necessary.
  94. */
  95. static void Cpqfc_initHBAdata(CPQFCHBA *cpqfcHBAdata, struct pci_dev *PciDev )
  96. {
  97. cpqfcHBAdata->PciDev = PciDev; // copy PCI info ptr
  98. // since x86 port space is 64k, we only need the lower 16 bits
  99. cpqfcHBAdata->fcChip.Registers.IOBaseL =
  100. PciDev->resource[1].start & PCI_BASE_ADDRESS_IO_MASK;
  101. cpqfcHBAdata->fcChip.Registers.IOBaseU =
  102. PciDev->resource[2].start & PCI_BASE_ADDRESS_IO_MASK;
  103. // 32-bit memory addresses
  104. cpqfcHBAdata->fcChip.Registers.MemBase =
  105. PciDev->resource[3].start & PCI_BASE_ADDRESS_MEM_MASK;
  106. cpqfcHBAdata->fcChip.Registers.ReMapMemBase =
  107. ioremap( PciDev->resource[3].start & PCI_BASE_ADDRESS_MEM_MASK,
  108. 0x200);
  109. cpqfcHBAdata->fcChip.Registers.RAMBase =
  110. PciDev->resource[4].start;
  111. cpqfcHBAdata->fcChip.Registers.SROMBase = // NULL for HP TS adapter
  112. PciDev->resource[5].start;
  113. // now the Tachlite chip registers
  114. // the REGISTER struct holds both the physical address & last
  115. // written value (some TL registers are WRITE ONLY)
  116. cpqfcHBAdata->fcChip.Registers.SFQconsumerIndex.address =
  117. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_SFQ_CONSUMER_INDEX;
  118. cpqfcHBAdata->fcChip.Registers.ERQproducerIndex.address =
  119. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_ERQ_PRODUCER_INDEX;
  120. // TL Frame Manager
  121. cpqfcHBAdata->fcChip.Registers.FMconfig.address =
  122. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_CONFIG;
  123. cpqfcHBAdata->fcChip.Registers.FMcontrol.address =
  124. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_CONTROL;
  125. cpqfcHBAdata->fcChip.Registers.FMstatus.address =
  126. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_STATUS;
  127. cpqfcHBAdata->fcChip.Registers.FMLinkStatus1.address =
  128. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_LINK_STAT1;
  129. cpqfcHBAdata->fcChip.Registers.FMLinkStatus2.address =
  130. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_LINK_STAT2;
  131. cpqfcHBAdata->fcChip.Registers.FMBB_CreditZero.address =
  132. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_BB_CREDIT0;
  133. // TL Control Regs
  134. cpqfcHBAdata->fcChip.Registers.TYconfig.address =
  135. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_TACH_CONFIG;
  136. cpqfcHBAdata->fcChip.Registers.TYcontrol.address =
  137. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_TACH_CONTROL;
  138. cpqfcHBAdata->fcChip.Registers.TYstatus.address =
  139. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_TACH_STATUS;
  140. cpqfcHBAdata->fcChip.Registers.rcv_al_pa.address =
  141. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_RCV_AL_PA;
  142. cpqfcHBAdata->fcChip.Registers.ed_tov.address =
  143. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + TL_MEM_FM_ED_TOV;
  144. cpqfcHBAdata->fcChip.Registers.INTEN.address =
  145. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + IINTEN;
  146. cpqfcHBAdata->fcChip.Registers.INTPEND.address =
  147. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + IINTPEND;
  148. cpqfcHBAdata->fcChip.Registers.INTSTAT.address =
  149. cpqfcHBAdata->fcChip.Registers.ReMapMemBase + IINTSTAT;
  150. DEBUG_PCI(printk(" cpqfcHBAdata->fcChip.Registers. :\n"));
  151. DEBUG_PCI(printk(" IOBaseL = %x\n",
  152. cpqfcHBAdata->fcChip.Registers.IOBaseL));
  153. DEBUG_PCI(printk(" IOBaseU = %x\n",
  154. cpqfcHBAdata->fcChip.Registers.IOBaseU));
  155. /* printk(" ioremap'd Membase: %p\n", cpqfcHBAdata->fcChip.Registers.ReMapMemBase); */
  156. DEBUG_PCI(printk(" SFQconsumerIndex.address = %p\n",
  157. cpqfcHBAdata->fcChip.Registers.SFQconsumerIndex.address));
  158. DEBUG_PCI(printk(" ERQproducerIndex.address = %p\n",
  159. cpqfcHBAdata->fcChip.Registers.ERQproducerIndex.address));
  160. DEBUG_PCI(printk(" TYconfig.address = %p\n",
  161. cpqfcHBAdata->fcChip.Registers.TYconfig.address));
  162. DEBUG_PCI(printk(" FMconfig.address = %p\n",
  163. cpqfcHBAdata->fcChip.Registers.FMconfig.address));
  164. DEBUG_PCI(printk(" FMcontrol.address = %p\n",
  165. cpqfcHBAdata->fcChip.Registers.FMcontrol.address));
  166. // set default options for FC controller (chip)
  167. cpqfcHBAdata->fcChip.Options.initiator = 1; // default: SCSI initiator
  168. cpqfcHBAdata->fcChip.Options.target = 0; // default: SCSI target
  169. cpqfcHBAdata->fcChip.Options.extLoopback = 0;// default: no loopback @GBIC
  170. cpqfcHBAdata->fcChip.Options.intLoopback = 0;// default: no loopback inside chip
  171. // set highest and lowest FC-PH version the adapter/driver supports
  172. // (NOT strict compliance)
  173. cpqfcHBAdata->fcChip.highest_FCPH_ver = FC_PH3;
  174. cpqfcHBAdata->fcChip.lowest_FCPH_ver = FC_PH43;
  175. // set function points for this controller / adapter
  176. cpqfcHBAdata->fcChip.ResetTachyon = CpqTsResetTachLite;
  177. cpqfcHBAdata->fcChip.FreezeTachyon = CpqTsFreezeTachlite;
  178. cpqfcHBAdata->fcChip.UnFreezeTachyon = CpqTsUnFreezeTachlite;
  179. cpqfcHBAdata->fcChip.CreateTachyonQues = CpqTsCreateTachLiteQues;
  180. cpqfcHBAdata->fcChip.DestroyTachyonQues = CpqTsDestroyTachLiteQues;
  181. cpqfcHBAdata->fcChip.InitializeTachyon = CpqTsInitializeTachLite;
  182. cpqfcHBAdata->fcChip.LaserControl = CpqTsLaserControl;
  183. cpqfcHBAdata->fcChip.ProcessIMQEntry = CpqTsProcessIMQEntry;
  184. cpqfcHBAdata->fcChip.InitializeFrameManager = CpqTsInitializeFrameManager;
  185. cpqfcHBAdata->fcChip.ReadWriteWWN = CpqTsReadWriteWWN;
  186. cpqfcHBAdata->fcChip.ReadWriteNVRAM = CpqTsReadWriteNVRAM;
  187. if (cpqfc_alloc_private_data_pool(cpqfcHBAdata) != 0) {
  188. printk(KERN_WARNING
  189. "cpqfc: unable to allocate pool for passthru ioctls. "
  190. "Passthru ioctls disabled.\n");
  191. }
  192. }
  193. /* (borrowed from linux/drivers/scsi/hosts.c) */
  194. static void launch_FCworker_thread(struct Scsi_Host *HostAdapter)
  195. {
  196. DECLARE_MUTEX_LOCKED(sem);
  197. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  198. ENTER("launch_FC_worker_thread");
  199. cpqfcHBAdata->notify_wt = &sem;
  200. /* must unlock before kernel_thread(), for it may cause a reschedule. */
  201. spin_unlock_irq(HostAdapter->host_lock);
  202. kernel_thread((int (*)(void *))cpqfcTSWorkerThread,
  203. (void *) HostAdapter, 0);
  204. /*
  205. * Now wait for the kernel error thread to initialize itself
  206. */
  207. down (&sem);
  208. spin_lock_irq(HostAdapter->host_lock);
  209. cpqfcHBAdata->notify_wt = NULL;
  210. LEAVE("launch_FC_worker_thread");
  211. }
  212. /* "Entry" point to discover if any supported PCI
  213. bus adapter can be found
  214. */
  215. /* We're supporting:
  216. * Compaq 64-bit, 66MHz HBA with Tachyon TS
  217. * Agilent XL2
  218. * HP Tachyon
  219. */
  220. #define HBA_TYPES 3
  221. #ifndef PCI_DEVICE_ID_COMPAQ_
  222. #define PCI_DEVICE_ID_COMPAQ_TACHYON 0xa0fc
  223. #endif
  224. static struct SupportedPCIcards cpqfc_boards[] __initdata = {
  225. {PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TACHYON},
  226. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_TACHLITE},
  227. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_TACHYON},
  228. };
  229. int cpqfcTS_detect(Scsi_Host_Template *ScsiHostTemplate)
  230. {
  231. int NumberOfAdapters=0; // how many of our PCI adapters are found?
  232. struct pci_dev *PciDev = NULL;
  233. struct Scsi_Host *HostAdapter = NULL;
  234. CPQFCHBA *cpqfcHBAdata = NULL;
  235. struct timer_list *cpqfcTStimer = NULL;
  236. int i;
  237. ENTER("cpqfcTS_detect");
  238. #if LINUX_VERSION_CODE < LinuxVersionCode(2,3,27)
  239. ScsiHostTemplate->proc_dir = &proc_scsi_cpqfcTS;
  240. #else
  241. ScsiHostTemplate->proc_name = "cpqfcTS";
  242. #endif
  243. for( i=0; i < HBA_TYPES; i++)
  244. {
  245. // look for all HBAs of each type
  246. while((PciDev = pci_find_device(cpqfc_boards[i].vendor_id,
  247. cpqfc_boards[i].device_id, PciDev)))
  248. {
  249. if (pci_enable_device(PciDev)) {
  250. printk(KERN_ERR
  251. "cpqfc: can't enable PCI device at %s\n", pci_name(PciDev));
  252. goto err_continue;
  253. }
  254. if (pci_set_dma_mask(PciDev, CPQFCTS_DMA_MASK) != 0) {
  255. printk(KERN_WARNING
  256. "cpqfc: HBA cannot support required DMA mask, skipping.\n");
  257. goto err_disable_dev;
  258. }
  259. // NOTE: (kernel 2.2.12-32) limits allocation to 128k bytes...
  260. /* printk(" scsi_register allocating %d bytes for FC HBA\n",
  261. (ULONG)sizeof(CPQFCHBA)); */
  262. HostAdapter = scsi_register( ScsiHostTemplate, sizeof( CPQFCHBA ) );
  263. if(HostAdapter == NULL) {
  264. printk(KERN_WARNING
  265. "cpqfc: can't register SCSI HBA, skipping.\n");
  266. goto err_disable_dev;
  267. }
  268. DEBUG_PCI( printk(" HBA found!\n"));
  269. DEBUG_PCI( printk(" HostAdapter->PciDev->irq = %u\n", PciDev->irq) );
  270. DEBUG_PCI(printk(" PciDev->baseaddress[0]= %lx\n",
  271. PciDev->resource[0].start));
  272. DEBUG_PCI(printk(" PciDev->baseaddress[1]= %lx\n",
  273. PciDev->resource[1].start));
  274. DEBUG_PCI(printk(" PciDev->baseaddress[2]= %lx\n",
  275. PciDev->resource[2].start));
  276. DEBUG_PCI(printk(" PciDev->baseaddress[3]= %lx\n",
  277. PciDev->resource[3].start));
  278. HostAdapter->irq = PciDev->irq; // copy for Scsi layers
  279. // HP Tachlite uses two (255-byte) ranges of Port I/O (lower & upper),
  280. // for a total I/O port address space of 512 bytes.
  281. // mask out the I/O port address (lower) & record
  282. HostAdapter->io_port = (unsigned int)
  283. PciDev->resource[1].start & PCI_BASE_ADDRESS_IO_MASK;
  284. HostAdapter->n_io_port = 0xff;
  285. // i.e., expect 128 targets (arbitrary number), while the
  286. // RA-4000 supports 32 LUNs
  287. HostAdapter->max_id = 0; // incremented as devices log in
  288. HostAdapter->max_lun = CPQFCTS_MAX_LUN; // LUNs per FC device
  289. HostAdapter->max_channel = CPQFCTS_MAX_CHANNEL; // multiple busses?
  290. // get the pointer to our HBA specific data... (one for
  291. // each HBA on the PCI bus(ses)).
  292. cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  293. // make certain our data struct is clear
  294. memset( cpqfcHBAdata, 0, sizeof( CPQFCHBA ) );
  295. // initialize our HBA info
  296. cpqfcHBAdata->HBAnum = NumberOfAdapters;
  297. cpqfcHBAdata->HostAdapter = HostAdapter; // back ptr
  298. Cpqfc_initHBAdata( cpqfcHBAdata, PciDev ); // fill MOST fields
  299. cpqfcHBAdata->HBAnum = NumberOfAdapters;
  300. spin_lock_init(&cpqfcHBAdata->hba_spinlock);
  301. // request necessary resources and check for conflicts
  302. if( request_irq( HostAdapter->irq,
  303. cpqfcTS_intr_handler,
  304. SA_INTERRUPT | SA_SHIRQ,
  305. DEV_NAME,
  306. HostAdapter) )
  307. {
  308. printk(KERN_WARNING "cpqfc: IRQ %u already used\n", HostAdapter->irq);
  309. goto err_unregister;
  310. }
  311. // Since we have two 256-byte I/O port ranges (upper
  312. // and lower), check them both
  313. if( !request_region( cpqfcHBAdata->fcChip.Registers.IOBaseU,
  314. 0xff, DEV_NAME ) )
  315. {
  316. printk(KERN_WARNING "cpqfc: address in use: %x\n",
  317. cpqfcHBAdata->fcChip.Registers.IOBaseU);
  318. goto err_free_irq;
  319. }
  320. if( !request_region( cpqfcHBAdata->fcChip.Registers.IOBaseL,
  321. 0xff, DEV_NAME ) )
  322. {
  323. printk(KERN_WARNING "cpqfc: address in use: %x\n",
  324. cpqfcHBAdata->fcChip.Registers.IOBaseL);
  325. goto err_release_region_U;
  326. }
  327. // OK, we have grabbed everything we need now.
  328. DEBUG_PCI(printk(" Reserved 255 I/O addresses @ %x\n",
  329. cpqfcHBAdata->fcChip.Registers.IOBaseL ));
  330. DEBUG_PCI(printk(" Reserved 255 I/O addresses @ %x\n",
  331. cpqfcHBAdata->fcChip.Registers.IOBaseU ));
  332. // start our kernel worker thread
  333. spin_lock_irq(HostAdapter->host_lock);
  334. launch_FCworker_thread(HostAdapter);
  335. // start our TimerTask...
  336. cpqfcTStimer = &cpqfcHBAdata->cpqfcTStimer;
  337. init_timer( cpqfcTStimer); // Linux clears next/prev values
  338. cpqfcTStimer->expires = jiffies + HZ; // one second
  339. cpqfcTStimer->data = (unsigned long)cpqfcHBAdata; // this adapter
  340. cpqfcTStimer->function = cpqfcTSheartbeat; // handles timeouts, housekeeping
  341. add_timer( cpqfcTStimer); // give it to Linux
  342. // now initialize our hardware...
  343. if (cpqfcHBAdata->fcChip.InitializeTachyon( cpqfcHBAdata, 1,1)) {
  344. printk(KERN_WARNING "cpqfc: initialization of HBA hardware failed.\n");
  345. goto err_release_region_L;
  346. }
  347. cpqfcHBAdata->fcStatsTime = jiffies; // (for FC Statistics delta)
  348. // give our HBA time to initialize and login current devices...
  349. {
  350. // The Brocade switch (e.g. 2400, 2010, etc.) as of March 2000,
  351. // has the following algorithm for FL_Port startup:
  352. // Time(sec) Action
  353. // 0: Device Plugin and LIP(F7,F7) transmission
  354. // 1.0 LIP incoming
  355. // 1.027 LISA incoming, no CLS! (link not up)
  356. // 1.028 NOS incoming (switch test for N_Port)
  357. // 1.577 ED_TOV expired, transmit LIPs again
  358. // 3.0 LIP(F8,F7) incoming (switch passes Tach Prim.Sig)
  359. // 3.028 LILP received, link up, FLOGI starts
  360. // slowest(worst) case, measured on 1Gb Finisar GT analyzer
  361. unsigned long stop_time;
  362. spin_unlock_irq(HostAdapter->host_lock);
  363. stop_time = jiffies + 4*HZ;
  364. while ( time_before(jiffies, stop_time) )
  365. schedule(); // (our worker task needs to run)
  366. }
  367. spin_lock_irq(HostAdapter->host_lock);
  368. NumberOfAdapters++;
  369. spin_unlock_irq(HostAdapter->host_lock);
  370. continue;
  371. err_release_region_L:
  372. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseL, 0xff );
  373. err_release_region_U:
  374. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseU, 0xff );
  375. err_free_irq:
  376. free_irq( HostAdapter->irq, HostAdapter);
  377. err_unregister:
  378. scsi_unregister( HostAdapter);
  379. err_disable_dev:
  380. pci_disable_device( PciDev );
  381. err_continue:
  382. continue;
  383. } // end of while()
  384. }
  385. LEAVE("cpqfcTS_detect");
  386. return NumberOfAdapters;
  387. }
  388. #ifdef SUPPORT_RESET
  389. static void my_ioctl_done (Scsi_Cmnd * SCpnt)
  390. {
  391. struct request * req;
  392. req = SCpnt->request;
  393. req->rq_status = RQ_SCSI_DONE; /* Busy, but indicate request done */
  394. if (req->CPQFC_WAITING != NULL)
  395. CPQFC_COMPLETE(req->CPQFC_WAITING);
  396. }
  397. #endif
  398. static int cpqfc_alloc_private_data_pool(CPQFCHBA *hba)
  399. {
  400. hba->private_data_bits = NULL;
  401. hba->private_data_pool = NULL;
  402. hba->private_data_bits =
  403. kmalloc(((CPQFC_MAX_PASSTHRU_CMDS+BITS_PER_LONG-1) /
  404. BITS_PER_LONG)*sizeof(unsigned long),
  405. GFP_KERNEL);
  406. if (hba->private_data_bits == NULL)
  407. return -1;
  408. memset(hba->private_data_bits, 0,
  409. ((CPQFC_MAX_PASSTHRU_CMDS+BITS_PER_LONG-1) /
  410. BITS_PER_LONG)*sizeof(unsigned long));
  411. hba->private_data_pool = kmalloc(sizeof(cpqfc_passthru_private_t) *
  412. CPQFC_MAX_PASSTHRU_CMDS, GFP_KERNEL);
  413. if (hba->private_data_pool == NULL) {
  414. kfree(hba->private_data_bits);
  415. hba->private_data_bits = NULL;
  416. return -1;
  417. }
  418. return 0;
  419. }
  420. static void cpqfc_free_private_data_pool(CPQFCHBA *hba)
  421. {
  422. kfree(hba->private_data_bits);
  423. kfree(hba->private_data_pool);
  424. }
  425. int is_private_data_of_cpqfc(CPQFCHBA *hba, void *pointer)
  426. {
  427. /* Is pointer within our private data pool?
  428. We use Scsi_Request->upper_private_data (normally
  429. reserved for upper layer drivers, e.g. the sg driver)
  430. We check to see if the pointer is ours by looking at
  431. its address. Is this ok? Hmm, it occurs to me that
  432. a user app might do something bad by using sg to send
  433. a cpqfc passthrough ioctl with upper_data_private
  434. forged to be somewhere in our pool..., though they'd
  435. normally have to be root already to do this. */
  436. return (pointer != NULL &&
  437. pointer >= (void *) hba->private_data_pool &&
  438. pointer < (void *) hba->private_data_pool +
  439. sizeof(*hba->private_data_pool) *
  440. CPQFC_MAX_PASSTHRU_CMDS);
  441. }
  442. cpqfc_passthru_private_t *cpqfc_alloc_private_data(CPQFCHBA *hba)
  443. {
  444. int i;
  445. do {
  446. i = find_first_zero_bit(hba->private_data_bits,
  447. CPQFC_MAX_PASSTHRU_CMDS);
  448. if (i == CPQFC_MAX_PASSTHRU_CMDS)
  449. return NULL;
  450. } while ( test_and_set_bit(i & (BITS_PER_LONG - 1),
  451. hba->private_data_bits+(i/BITS_PER_LONG)) != 0);
  452. return &hba->private_data_pool[i];
  453. }
  454. void cpqfc_free_private_data(CPQFCHBA *hba, cpqfc_passthru_private_t *data)
  455. {
  456. int i;
  457. i = data - hba->private_data_pool;
  458. clear_bit(i&(BITS_PER_LONG-1),
  459. hba->private_data_bits+(i/BITS_PER_LONG));
  460. }
  461. int cpqfcTS_ioctl( struct scsi_device *ScsiDev, int Cmnd, void *arg)
  462. {
  463. int result = 0;
  464. struct Scsi_Host *HostAdapter = ScsiDev->host;
  465. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  466. PTACHYON fcChip = &cpqfcHBAdata->fcChip;
  467. PFC_LOGGEDIN_PORT pLoggedInPort = NULL;
  468. struct scsi_cmnd *DumCmnd;
  469. int i, j;
  470. VENDOR_IOCTL_REQ ioc;
  471. cpqfc_passthru_t *vendor_cmd;
  472. Scsi_Device *SDpnt;
  473. Scsi_Request *ScsiPassThruReq;
  474. cpqfc_passthru_private_t *privatedata;
  475. ENTER("cpqfcTS_ioctl ");
  476. // printk("ioctl CMND %d", Cmnd);
  477. switch (Cmnd) {
  478. // Passthrough provides a mechanism to bypass the RAID
  479. // or other controller and talk directly to the devices
  480. // (e.g. physical disk drive)
  481. // Passthrough commands, unfortunately, tend to be vendor
  482. // specific; this is tailored to COMPAQ's RAID (RA4x00)
  483. case CPQFCTS_SCSI_PASSTHRU:
  484. {
  485. void *buf = NULL; // for kernel space buffer for user data
  486. /* Check that our pool got allocated ok. */
  487. if (cpqfcHBAdata->private_data_pool == NULL)
  488. return -ENOMEM;
  489. if( !arg)
  490. return -EINVAL;
  491. // must be super user to send stuff directly to the
  492. // controller and/or physical drives...
  493. if( !capable(CAP_SYS_RAWIO) )
  494. return -EPERM;
  495. // copy the caller's struct to our space.
  496. if( copy_from_user( &ioc, arg, sizeof( VENDOR_IOCTL_REQ)))
  497. return( -EFAULT);
  498. vendor_cmd = ioc.argp; // i.e., CPQ specific command struct
  499. // If necessary, grab a kernel/DMA buffer
  500. if( vendor_cmd->len)
  501. {
  502. buf = kmalloc( vendor_cmd->len, GFP_KERNEL);
  503. if( !buf)
  504. return -ENOMEM;
  505. }
  506. // Now build a Scsi_Request to pass down...
  507. ScsiPassThruReq = scsi_allocate_request(ScsiDev, GFP_KERNEL);
  508. if (ScsiPassThruReq == NULL) {
  509. kfree(buf);
  510. return -ENOMEM;
  511. }
  512. ScsiPassThruReq->upper_private_data =
  513. cpqfc_alloc_private_data(cpqfcHBAdata);
  514. if (ScsiPassThruReq->upper_private_data == NULL) {
  515. kfree(buf);
  516. scsi_release_request(ScsiPassThruReq); // "de-allocate"
  517. return -ENOMEM;
  518. }
  519. if (vendor_cmd->rw_flag == VENDOR_WRITE_OPCODE) {
  520. if (vendor_cmd->len) { // Need data from user?
  521. if (copy_from_user(buf, vendor_cmd->bufp,
  522. vendor_cmd->len)) {
  523. kfree(buf);
  524. cpqfc_free_private_data(cpqfcHBAdata,
  525. ScsiPassThruReq->upper_private_data);
  526. scsi_release_request(ScsiPassThruReq);
  527. return( -EFAULT);
  528. }
  529. }
  530. ScsiPassThruReq->sr_data_direction = DMA_TO_DEVICE;
  531. } else if (vendor_cmd->rw_flag == VENDOR_READ_OPCODE) {
  532. ScsiPassThruReq->sr_data_direction = DMA_FROM_DEVICE;
  533. } else
  534. // maybe this means a bug in the user app
  535. ScsiPassThruReq->sr_data_direction = DMA_BIDIRECTIONAL;
  536. ScsiPassThruReq->sr_cmd_len = 0; // set correctly by scsi_do_req()
  537. ScsiPassThruReq->sr_sense_buffer[0] = 0;
  538. ScsiPassThruReq->sr_sense_buffer[2] = 0;
  539. // We copy the scheme used by sd.c:spinup_disk() to submit commands
  540. // to our own HBA. We do this in order to stall the
  541. // thread calling the IOCTL until it completes, and use
  542. // the same "_quecommand" function for synchronizing
  543. // FC Link events with our "worker thread".
  544. privatedata = ScsiPassThruReq->upper_private_data;
  545. privatedata->bus = vendor_cmd->bus;
  546. privatedata->pdrive = vendor_cmd->pdrive;
  547. // eventually gets us to our own _quecommand routine
  548. scsi_wait_req(ScsiPassThruReq,
  549. &vendor_cmd->cdb[0], buf, vendor_cmd->len,
  550. 10*HZ, // timeout
  551. 1); // retries
  552. result = ScsiPassThruReq->sr_result;
  553. // copy any sense data back to caller
  554. if( result != 0 )
  555. {
  556. memcpy( vendor_cmd->sense_data, // see struct def - size=40
  557. ScsiPassThruReq->sr_sense_buffer,
  558. sizeof(ScsiPassThruReq->sr_sense_buffer) <
  559. sizeof(vendor_cmd->sense_data) ?
  560. sizeof(ScsiPassThruReq->sr_sense_buffer) :
  561. sizeof(vendor_cmd->sense_data)
  562. );
  563. }
  564. SDpnt = ScsiPassThruReq->sr_device;
  565. /* upper_private_data is already freed in call_scsi_done() */
  566. scsi_release_request(ScsiPassThruReq); // "de-allocate"
  567. ScsiPassThruReq = NULL;
  568. // need to pass data back to user (space)?
  569. if( (vendor_cmd->rw_flag == VENDOR_READ_OPCODE) &&
  570. vendor_cmd->len )
  571. if( copy_to_user( vendor_cmd->bufp, buf, vendor_cmd->len))
  572. result = -EFAULT;
  573. if( buf)
  574. kfree( buf);
  575. return result;
  576. }
  577. case CPQFCTS_GETPCIINFO:
  578. {
  579. cpqfc_pci_info_struct pciinfo;
  580. if( !arg)
  581. return -EINVAL;
  582. pciinfo.bus = cpqfcHBAdata->PciDev->bus->number;
  583. pciinfo.dev_fn = cpqfcHBAdata->PciDev->devfn;
  584. pciinfo.board_id = cpqfcHBAdata->PciDev->device |
  585. (cpqfcHBAdata->PciDev->vendor <<16);
  586. if(copy_to_user( arg, &pciinfo, sizeof(cpqfc_pci_info_struct)))
  587. return( -EFAULT);
  588. return 0;
  589. }
  590. case CPQFCTS_GETDRIVVER:
  591. {
  592. DriverVer_type DriverVer =
  593. CPQFCTS_DRIVER_VER( VER_MAJOR,VER_MINOR,VER_SUBMINOR);
  594. if( !arg)
  595. return -EINVAL;
  596. if(copy_to_user( arg, &DriverVer, sizeof(DriverVer)))
  597. return( -EFAULT);
  598. return 0;
  599. }
  600. case CPQFC_IOCTL_FC_TARGET_ADDRESS:
  601. // can we find an FC device mapping to this SCSI target?
  602. /* DumCmnd.channel = ScsiDev->channel; */ // For searching
  603. /* DumCmnd.target = ScsiDev->id; */
  604. /* DumCmnd.lun = ScsiDev->lun; */
  605. DumCmnd = scsi_get_command (ScsiDev, GFP_KERNEL);
  606. if (!DumCmnd)
  607. return -ENOMEM;
  608. pLoggedInPort = fcFindLoggedInPort( fcChip,
  609. DumCmnd, // search Scsi Nexus
  610. 0, // DON'T search linked list for FC port id
  611. NULL, // DON'T search linked list for FC WWN
  612. NULL); // DON'T care about end of list
  613. scsi_put_command (DumCmnd);
  614. if (pLoggedInPort == NULL) {
  615. result = -ENXIO;
  616. break;
  617. }
  618. result = access_ok(VERIFY_WRITE, arg, sizeof(Scsi_FCTargAddress)) ? 0 : -EFAULT;
  619. if (result) break;
  620. put_user(pLoggedInPort->port_id,
  621. &((Scsi_FCTargAddress *) arg)->host_port_id);
  622. for( i=3,j=0; i>=0; i--) // copy the LOGIN port's WWN
  623. put_user(pLoggedInPort->u.ucWWN[i],
  624. &((Scsi_FCTargAddress *) arg)->host_wwn[j++]);
  625. for( i=7; i>3; i--) // copy the LOGIN port's WWN
  626. put_user(pLoggedInPort->u.ucWWN[i],
  627. &((Scsi_FCTargAddress *) arg)->host_wwn[j++]);
  628. break;
  629. case CPQFC_IOCTL_FC_TDR:
  630. result = cpqfcTS_TargetDeviceReset( ScsiDev, 0);
  631. break;
  632. default:
  633. result = -EINVAL;
  634. break;
  635. }
  636. LEAVE("cpqfcTS_ioctl");
  637. return result;
  638. }
  639. /* "Release" the Host Bus Adapter...
  640. disable interrupts, stop the HBA, release the interrupt,
  641. and free all resources */
  642. int cpqfcTS_release(struct Scsi_Host *HostAdapter)
  643. {
  644. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  645. ENTER("cpqfcTS_release");
  646. DEBUG_PCI( printk(" cpqfcTS: delete timer...\n"));
  647. del_timer( &cpqfcHBAdata->cpqfcTStimer);
  648. // disable the hardware...
  649. DEBUG_PCI( printk(" disable hardware, destroy queues, free mem\n"));
  650. cpqfcHBAdata->fcChip.ResetTachyon( cpqfcHBAdata, CLEAR_FCPORTS);
  651. // kill kernel thread
  652. if( cpqfcHBAdata->worker_thread ) // (only if exists)
  653. {
  654. DECLARE_MUTEX_LOCKED(sem); // synchronize thread kill
  655. cpqfcHBAdata->notify_wt = &sem;
  656. DEBUG_PCI( printk(" killing kernel thread\n"));
  657. send_sig( SIGKILL, cpqfcHBAdata->worker_thread, 1);
  658. down( &sem);
  659. cpqfcHBAdata->notify_wt = NULL;
  660. }
  661. cpqfc_free_private_data_pool(cpqfcHBAdata);
  662. // free Linux resources
  663. DEBUG_PCI( printk(" cpqfcTS: freeing resources...\n"));
  664. free_irq( HostAdapter->irq, HostAdapter);
  665. scsi_unregister( HostAdapter);
  666. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseL, 0xff);
  667. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseU, 0xff);
  668. /* we get "vfree: bad address" executing this - need to investigate...
  669. if( (void*)((unsigned long)cpqfcHBAdata->fcChip.Registers.MemBase) !=
  670. cpqfcHBAdata->fcChip.Registers.ReMapMemBase)
  671. vfree( cpqfcHBAdata->fcChip.Registers.ReMapMemBase);
  672. */
  673. pci_disable_device( cpqfcHBAdata->PciDev);
  674. LEAVE("cpqfcTS_release");
  675. return 0;
  676. }
  677. const char * cpqfcTS_info(struct Scsi_Host *HostAdapter)
  678. {
  679. static char buf[300];
  680. CPQFCHBA *cpqfcHBA;
  681. int BusSpeed, BusWidth;
  682. // get the pointer to our Scsi layer HBA buffer
  683. cpqfcHBA = (CPQFCHBA *)HostAdapter->hostdata;
  684. BusWidth = (cpqfcHBA->fcChip.Registers.PCIMCTR &0x4) > 0 ?
  685. 64 : 32;
  686. if( cpqfcHBA->fcChip.Registers.TYconfig.value & 0x80000000)
  687. BusSpeed = 66;
  688. else
  689. BusSpeed = 33;
  690. sprintf(buf,
  691. "%s: WWN %08X%08X\n on PCI bus %d device 0x%02x irq %d IObaseL 0x%x, MEMBASE 0x%x\nPCI bus width %d bits, bus speed %d MHz\nFCP-SCSI Driver v%d.%d.%d",
  692. cpqfcHBA->fcChip.Name,
  693. cpqfcHBA->fcChip.Registers.wwn_hi,
  694. cpqfcHBA->fcChip.Registers.wwn_lo,
  695. cpqfcHBA->PciDev->bus->number,
  696. cpqfcHBA->PciDev->device,
  697. HostAdapter->irq,
  698. cpqfcHBA->fcChip.Registers.IOBaseL,
  699. cpqfcHBA->fcChip.Registers.MemBase,
  700. BusWidth,
  701. BusSpeed,
  702. VER_MAJOR, VER_MINOR, VER_SUBMINOR
  703. );
  704. cpqfcTSDecodeGBICtype( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  705. cpqfcTSGetLPSM( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  706. return buf;
  707. }
  708. //
  709. // /proc/scsi support. The following routines allow us to do 'normal'
  710. // sprintf like calls to return the currently requested piece (buflenght
  711. // chars, starting at bufoffset) of the file. Although procfs allows for
  712. // a 1 Kb bytes overflow after te supplied buffer, I consider it bad
  713. // programming to use it to make programming a little simpler. This piece
  714. // of coding is borrowed from ncr53c8xx.c with some modifications
  715. //
  716. struct info_str
  717. {
  718. char *buffer; // Pointer to output buffer
  719. int buflength; // It's length
  720. int bufoffset; // File offset corresponding with buf[0]
  721. int buffillen; // Current filled length
  722. int filpos; // Current file offset
  723. };
  724. static void copy_mem_info(struct info_str *info, char *data, int datalen)
  725. {
  726. if (info->filpos < info->bufoffset) { // Current offset before buffer offset
  727. if (info->filpos + datalen <= info->bufoffset) {
  728. info->filpos += datalen; // Discard if completely before buffer
  729. return;
  730. } else { // Partial copy, set to begin
  731. data += (info->bufoffset - info->filpos);
  732. datalen -= (info->bufoffset - info->filpos);
  733. info->filpos = info->bufoffset;
  734. }
  735. }
  736. info->filpos += datalen; // Update current offset
  737. if (info->buffillen == info->buflength) // Buffer full, discard
  738. return;
  739. if (info->buflength - info->buffillen < datalen) // Overflows buffer ?
  740. datalen = info->buflength - info->buffillen;
  741. memcpy(info->buffer + info->buffillen, data, datalen);
  742. info->buffillen += datalen;
  743. }
  744. static int copy_info(struct info_str *info, char *fmt, ...)
  745. {
  746. va_list args;
  747. char buf[400];
  748. int len;
  749. va_start(args, fmt);
  750. len = vsprintf(buf, fmt, args);
  751. va_end(args);
  752. copy_mem_info(info, buf, len);
  753. return len;
  754. }
  755. // Routine to get data for /proc RAM filesystem
  756. //
  757. int cpqfcTS_proc_info (struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length,
  758. int inout)
  759. {
  760. struct scsi_cmnd *DumCmnd;
  761. struct scsi_device *ScsiDev;
  762. int Chan, Targ, i;
  763. struct info_str info;
  764. CPQFCHBA *cpqfcHBA;
  765. PTACHYON fcChip;
  766. PFC_LOGGEDIN_PORT pLoggedInPort;
  767. char buf[81];
  768. if (inout) return -EINVAL;
  769. // get the pointer to our Scsi layer HBA buffer
  770. cpqfcHBA = (CPQFCHBA *)host->hostdata;
  771. fcChip = &cpqfcHBA->fcChip;
  772. *start = buffer;
  773. info.buffer = buffer;
  774. info.buflength = length;
  775. info.bufoffset = offset;
  776. info.filpos = 0;
  777. info.buffillen = 0;
  778. copy_info(&info, "Driver version = %d.%d.%d", VER_MAJOR, VER_MINOR, VER_SUBMINOR);
  779. cpqfcTSDecodeGBICtype( &cpqfcHBA->fcChip, &buf[0]);
  780. cpqfcTSGetLPSM( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  781. copy_info(&info, "%s\n", buf);
  782. #define DISPLAY_WWN_INFO
  783. #ifdef DISPLAY_WWN_INFO
  784. ScsiDev = scsi_get_host_dev (host);
  785. if (!ScsiDev)
  786. return -ENOMEM;
  787. DumCmnd = scsi_get_command (ScsiDev, GFP_KERNEL);
  788. if (!DumCmnd) {
  789. scsi_free_host_dev (ScsiDev);
  790. return -ENOMEM;
  791. }
  792. copy_info(&info, "WWN database: (\"port_id: 000000\" means disconnected)\n");
  793. for ( Chan=0; Chan <= host->max_channel; Chan++) {
  794. DumCmnd->device->channel = Chan;
  795. for (Targ=0; Targ <= host->max_id; Targ++) {
  796. DumCmnd->device->id = Targ;
  797. if ((pLoggedInPort = fcFindLoggedInPort( fcChip,
  798. DumCmnd, // search Scsi Nexus
  799. 0, // DON'T search list for FC port id
  800. NULL, // DON'T search list for FC WWN
  801. NULL))){ // DON'T care about end of list
  802. copy_info(&info, "Host: scsi%d Channel: %02d TargetId: %02d -> WWN: ",
  803. host->host_no, Chan, Targ);
  804. for( i=3; i>=0; i--) // copy the LOGIN port's WWN
  805. copy_info(&info, "%02X", pLoggedInPort->u.ucWWN[i]);
  806. for( i=7; i>3; i--) // copy the LOGIN port's WWN
  807. copy_info(&info, "%02X", pLoggedInPort->u.ucWWN[i]);
  808. copy_info(&info, " port_id: %06X\n", pLoggedInPort->port_id);
  809. }
  810. }
  811. }
  812. scsi_put_command (DumCmnd);
  813. scsi_free_host_dev (ScsiDev);
  814. #endif
  815. // Unfortunately, the proc_info buffer isn't big enough
  816. // for everything we would like...
  817. // For FC stats, compile this and turn off WWN stuff above
  818. //#define DISPLAY_FC_STATS
  819. #ifdef DISPLAY_FC_STATS
  820. // get the Fibre Channel statistics
  821. {
  822. int DeltaSecs = (jiffies - cpqfcHBA->fcStatsTime) / HZ;
  823. int days,hours,minutes,secs;
  824. days = DeltaSecs / (3600*24); // days
  825. hours = (DeltaSecs% (3600*24)) / 3600; // hours
  826. minutes = (DeltaSecs%3600 /60); // minutes
  827. secs = DeltaSecs%60; // secs
  828. copy_info( &info, "Fibre Channel Stats (time dd:hh:mm:ss %02u:%02u:%02u:%02u\n",
  829. days, hours, minutes, secs);
  830. }
  831. cpqfcHBA->fcStatsTime = jiffies; // (for next delta)
  832. copy_info( &info, " LinkUp %9u LinkDown %u\n",
  833. fcChip->fcStats.linkUp, fcChip->fcStats.linkDown);
  834. copy_info( &info, " Loss of Signal %9u Loss of Sync %u\n",
  835. fcChip->fcStats.LossofSignal, fcChip->fcStats.LossofSync);
  836. copy_info( &info, " Discarded Frames %9u Bad CRC Frame %u\n",
  837. fcChip->fcStats.Dis_Frm, fcChip->fcStats.Bad_CRC);
  838. copy_info( &info, " TACH LinkFailTX %9u TACH LinkFailRX %u\n",
  839. fcChip->fcStats.linkFailTX, fcChip->fcStats.linkFailRX);
  840. copy_info( &info, " TACH RxEOFa %9u TACH Elastic Store %u\n",
  841. fcChip->fcStats.Rx_EOFa, fcChip->fcStats.e_stores);
  842. copy_info( &info, " BufferCreditWait %9uus TACH FM Inits %u\n",
  843. fcChip->fcStats.BB0_Timer*10, fcChip->fcStats.FMinits );
  844. copy_info( &info, " FC-2 Timeouts %9u FC-2 Logouts %u\n",
  845. fcChip->fcStats.timeouts, fcChip->fcStats.logouts);
  846. copy_info( &info, " FC-2 Aborts %9u FC-4 Aborts %u\n",
  847. fcChip->fcStats.FC2aborted, fcChip->fcStats.FC4aborted);
  848. // clear the counters
  849. cpqfcTSClearLinkStatusCounters( fcChip);
  850. #endif
  851. return info.buffillen;
  852. }
  853. #if DEBUG_CMND
  854. UCHAR *ScsiToAscii( UCHAR ScsiCommand)
  855. {
  856. /*++
  857. Routine Description:
  858. Converts a SCSI command to a text string for debugging purposes.
  859. Arguments:
  860. ScsiCommand -- hex value SCSI Command
  861. Return Value:
  862. An ASCII, null-terminated string if found, else returns NULL.
  863. Original code from M. McGowen, Compaq
  864. --*/
  865. switch (ScsiCommand)
  866. {
  867. case 0x00:
  868. return( "Test Unit Ready" );
  869. case 0x01:
  870. return( "Rezero Unit or Rewind" );
  871. case 0x02:
  872. return( "Request Block Address" );
  873. case 0x03:
  874. return( "Requese Sense" );
  875. case 0x04:
  876. return( "Format Unit" );
  877. case 0x05:
  878. return( "Read Block Limits" );
  879. case 0x07:
  880. return( "Reassign Blocks" );
  881. case 0x08:
  882. return( "Read (6)" );
  883. case 0x0a:
  884. return( "Write (6)" );
  885. case 0x0b:
  886. return( "Seek (6)" );
  887. case 0x12:
  888. return( "Inquiry" );
  889. case 0x15:
  890. return( "Mode Select (6)" );
  891. case 0x16:
  892. return( "Reserve" );
  893. case 0x17:
  894. return( "Release" );
  895. case 0x1a:
  896. return( "ModeSen(6)" );
  897. case 0x1b:
  898. return( "Start/Stop Unit" );
  899. case 0x1c:
  900. return( "Receive Diagnostic Results" );
  901. case 0x1d:
  902. return( "Send Diagnostic" );
  903. case 0x25:
  904. return( "Read Capacity" );
  905. case 0x28:
  906. return( "Read (10)" );
  907. case 0x2a:
  908. return( "Write (10)" );
  909. case 0x2b:
  910. return( "Seek (10)" );
  911. case 0x2e:
  912. return( "Write and Verify" );
  913. case 0x2f:
  914. return( "Verify" );
  915. case 0x34:
  916. return( "Pre-Fetch" );
  917. case 0x35:
  918. return( "Synchronize Cache" );
  919. case 0x37:
  920. return( "Read Defect Data (10)" );
  921. case 0x3b:
  922. return( "Write Buffer" );
  923. case 0x3c:
  924. return( "Read Buffer" );
  925. case 0x3e:
  926. return( "Read Long" );
  927. case 0x3f:
  928. return( "Write Long" );
  929. case 0x41:
  930. return( "Write Same" );
  931. case 0x4c:
  932. return( "Log Select" );
  933. case 0x4d:
  934. return( "Log Sense" );
  935. case 0x56:
  936. return( "Reserve (10)" );
  937. case 0x57:
  938. return( "Release (10)" );
  939. case 0xa0:
  940. return( "ReportLuns" );
  941. case 0xb7:
  942. return( "Read Defect Data (12)" );
  943. case 0xca:
  944. return( "Peripheral Device Addressing SCSI Passthrough" );
  945. case 0xcb:
  946. return( "Compaq Array Firmware Passthrough" );
  947. default:
  948. return( NULL );
  949. }
  950. } // end ScsiToAscii()
  951. void cpqfcTS_print_scsi_cmd(Scsi_Cmnd * cmd)
  952. {
  953. printk("cpqfcTS: (%s) chnl 0x%02x, trgt = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  954. ScsiToAscii( cmd->cmnd[0]), cmd->channel, cmd->target, cmd->lun, cmd->cmd_len);
  955. if( cmd->cmnd[0] == 0) // Test Unit Ready?
  956. {
  957. int i;
  958. printk("Cmnd->request_bufflen = 0x%X, ->use_sg = %d, ->bufflen = %d\n",
  959. cmd->request_bufflen, cmd->use_sg, cmd->bufflen);
  960. printk("Cmnd->request_buffer = %p, ->sglist_len = %d, ->buffer = %p\n",
  961. cmd->request_buffer, cmd->sglist_len, cmd->buffer);
  962. for (i = 0; i < cmd->cmd_len; i++)
  963. printk("0x%02x ", cmd->cmnd[i]);
  964. printk("\n");
  965. }
  966. }
  967. #endif /* DEBUG_CMND */
  968. static void QueCmndOnBoardLock( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  969. {
  970. int i;
  971. for( i=0; i< CPQFCTS_REQ_QUEUE_LEN; i++)
  972. { // find spare slot
  973. if( cpqfcHBAdata->BoardLockCmnd[i] == NULL )
  974. {
  975. cpqfcHBAdata->BoardLockCmnd[i] = Cmnd;
  976. // printk(" BoardLockCmnd[%d] %p Queued, chnl/target/lun %d/%d/%d\n",
  977. // i,Cmnd, Cmnd->channel, Cmnd->target, Cmnd->lun);
  978. break;
  979. }
  980. }
  981. if( i >= CPQFCTS_REQ_QUEUE_LEN)
  982. {
  983. printk(" cpqfcTS WARNING: Lost Cmnd %p on BoardLock Q full!", Cmnd);
  984. }
  985. }
  986. static void QueLinkDownCmnd( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  987. {
  988. int indx;
  989. // Remember the command ptr so we can return; we'll complete when
  990. // the device comes back, causing immediate retry
  991. for( indx=0; indx < CPQFCTS_REQ_QUEUE_LEN; indx++)//, SCptr++)
  992. {
  993. if( cpqfcHBAdata->LinkDnCmnd[indx] == NULL ) // available?
  994. {
  995. #ifdef DUMMYCMND_DBG
  996. printk(" @add Cmnd %p to LnkDnCmnd[%d]@ ", Cmnd,indx);
  997. #endif
  998. cpqfcHBAdata->LinkDnCmnd[indx] = Cmnd;
  999. break;
  1000. }
  1001. }
  1002. if( indx >= CPQFCTS_REQ_QUEUE_LEN ) // no space for Cmnd??
  1003. {
  1004. // this will result in an _abort call later (with possible trouble)
  1005. printk("no buffer for LinkDnCmnd!! %p\n", Cmnd);
  1006. }
  1007. }
  1008. // The file <scsi/scsi_host.h> says not to call scsi_done from
  1009. // inside _queuecommand, so we'll do it from the heartbeat timer
  1010. // (clarification: Turns out it's ok to call scsi_done from queuecommand
  1011. // for cases that don't go to the hardware like scsi cmds destined
  1012. // for LUNs we know don't exist, so this code might be simplified...)
  1013. static void QueBadTargetCmnd( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  1014. {
  1015. int i;
  1016. // printk(" can't find target %d\n", Cmnd->target);
  1017. for( i=0; i< CPQFCTS_MAX_TARGET_ID; i++)
  1018. { // find spare slot
  1019. if( cpqfcHBAdata->BadTargetCmnd[i] == NULL )
  1020. {
  1021. cpqfcHBAdata->BadTargetCmnd[i] = Cmnd;
  1022. // printk(" BadTargetCmnd[%d] %p Queued, chnl/target/lun %d/%d/%d\n",
  1023. // i,Cmnd, Cmnd->channel, Cmnd->target, Cmnd->lun);
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. // This is the "main" entry point for Linux Scsi commands --
  1029. // it all starts here.
  1030. int cpqfcTS_queuecommand(Scsi_Cmnd *Cmnd, void (* done)(Scsi_Cmnd *))
  1031. {
  1032. struct Scsi_Host *HostAdapter = Cmnd->device->host;
  1033. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  1034. PTACHYON fcChip = &cpqfcHBAdata->fcChip;
  1035. TachFCHDR_GCMND fchs; // only use for FC destination id field
  1036. PFC_LOGGEDIN_PORT pLoggedInPort;
  1037. ULONG ulStatus, SESTtype;
  1038. LONG ExchangeID;
  1039. ENTER("cpqfcTS_queuecommand");
  1040. PCI_TRACEO( (ULONG)Cmnd, 0x98)
  1041. Cmnd->scsi_done = done;
  1042. #ifdef DEBUG_CMND
  1043. cpqfcTS_print_scsi_cmd( Cmnd);
  1044. #endif
  1045. // prevent board contention with kernel thread...
  1046. if( cpqfcHBAdata->BoardLock )
  1047. {
  1048. // printk(" @BrdLck Hld@ ");
  1049. QueCmndOnBoardLock( cpqfcHBAdata, Cmnd);
  1050. }
  1051. else
  1052. {
  1053. // in the current system (2.2.12), this routine is called
  1054. // after spin_lock_irqsave(), so INTs are disabled. However,
  1055. // we might have something pending in the LinkQ, which
  1056. // might cause the WorkerTask to run. In case that
  1057. // happens, make sure we lock it out.
  1058. PCI_TRACE( 0x98)
  1059. CPQ_SPINLOCK_HBA( cpqfcHBAdata)
  1060. PCI_TRACE( 0x98)
  1061. // can we find an FC device mapping to this SCSI target?
  1062. pLoggedInPort = fcFindLoggedInPort( fcChip,
  1063. Cmnd, // search Scsi Nexus
  1064. 0, // DON'T search linked list for FC port id
  1065. NULL, // DON'T search linked list for FC WWN
  1066. NULL); // DON'T care about end of list
  1067. if( pLoggedInPort == NULL ) // not found!
  1068. {
  1069. // printk(" @Q bad targ cmnd %p@ ", Cmnd);
  1070. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1071. }
  1072. else if (Cmnd->device->lun >= CPQFCTS_MAX_LUN)
  1073. {
  1074. printk(KERN_WARNING "cpqfc: Invalid LUN: %d\n", Cmnd->device->lun);
  1075. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1076. }
  1077. else // we know what FC device to send to...
  1078. {
  1079. // does this device support FCP target functions?
  1080. // (determined by PRLI field)
  1081. if( !(pLoggedInPort->fcp_info & TARGET_FUNCTION) )
  1082. {
  1083. printk(" Doesn't support TARGET functions port_id %Xh\n",
  1084. pLoggedInPort->port_id );
  1085. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1086. }
  1087. // In this case (previous login OK), the device is temporarily
  1088. // unavailable waiting for re-login, in which case we expect it
  1089. // to be back in between 25 - 500ms.
  1090. // If the FC port doesn't log back in within several seconds
  1091. // (i.e. implicit "logout"), or we get an explicit logout,
  1092. // we set "device_blocked" in Scsi_Device struct; in this
  1093. // case 30 seconds will elapse before Linux/Scsi sends another
  1094. // command to the device.
  1095. else if( pLoggedInPort->prli != TRUE )
  1096. {
  1097. // printk("Device (Chnl/Target %d/%d) invalid PRLI, port_id %06lXh\n",
  1098. // Cmnd->channel, Cmnd->target, pLoggedInPort->port_id);
  1099. QueLinkDownCmnd( cpqfcHBAdata, Cmnd);
  1100. // Need to use "blocked" flag??
  1101. // Cmnd->device->device_blocked = TRUE; // just let it timeout
  1102. }
  1103. else // device supports TARGET functions, and is logged in...
  1104. {
  1105. // (context of fchs is to "reply" to...)
  1106. fchs.s_id = pLoggedInPort->port_id; // destination FC address
  1107. // what is the data direction? For data TO the device,
  1108. // we need IWE (Intiator Write Entry). Otherwise, IRE.
  1109. if( Cmnd->cmnd[0] == WRITE_10 ||
  1110. Cmnd->cmnd[0] == WRITE_6 ||
  1111. Cmnd->cmnd[0] == WRITE_BUFFER ||
  1112. Cmnd->cmnd[0] == VENDOR_WRITE_OPCODE || // CPQ specific
  1113. Cmnd->cmnd[0] == MODE_SELECT )
  1114. {
  1115. SESTtype = SCSI_IWE; // data from HBA to Device
  1116. }
  1117. else
  1118. SESTtype = SCSI_IRE; // data from Device to HBA
  1119. ulStatus = cpqfcTSBuildExchange(
  1120. cpqfcHBAdata,
  1121. SESTtype, // e.g. Initiator Read Entry (IRE)
  1122. &fchs, // we are originator; only use d_id
  1123. Cmnd, // Linux SCSI command (with scatter/gather list)
  1124. &ExchangeID );// fcController->fcExchanges index, -1 if failed
  1125. if( !ulStatus ) // Exchange setup?
  1126. {
  1127. if( cpqfcHBAdata->BoardLock )
  1128. {
  1129. TriggerHBA( fcChip->Registers.ReMapMemBase, 0);
  1130. printk(" @bl! %d, xID %Xh@ ", current->pid, ExchangeID);
  1131. }
  1132. ulStatus = cpqfcTSStartExchange( cpqfcHBAdata, ExchangeID );
  1133. if( !ulStatus )
  1134. {
  1135. PCI_TRACEO( ExchangeID, 0xB8)
  1136. // submitted to Tach's Outbound Que (ERQ PI incremented)
  1137. // waited for completion for ELS type (Login frames issued
  1138. // synchronously)
  1139. }
  1140. else
  1141. // check reason for Exchange not being started - we might
  1142. // want to Queue and start later, or fail with error
  1143. {
  1144. printk("quecommand: cpqfcTSStartExchange failed: %Xh\n", ulStatus );
  1145. }
  1146. } // end good BuildExchange status
  1147. else // SEST table probably full -- why? hardware hang?
  1148. {
  1149. printk("quecommand: cpqfcTSBuildExchange faild: %Xh\n", ulStatus);
  1150. }
  1151. } // end can't do FCP-SCSI target functions
  1152. } // end can't find target (FC device)
  1153. CPQ_SPINUNLOCK_HBA( cpqfcHBAdata)
  1154. }
  1155. PCI_TRACEO( (ULONG)Cmnd, 0x9C)
  1156. LEAVE("cpqfcTS_queuecommand");
  1157. return 0;
  1158. }
  1159. // Entry point for upper Scsi layer intiated abort. Typically
  1160. // this is called if the command (for hard disk) fails to complete
  1161. // in 30 seconds. This driver intends to complete all disk commands
  1162. // within Exchange ".timeOut" seconds (now 7) with target status, or
  1163. // in case of ".timeOut" expiration, a DID_SOFT_ERROR which causes
  1164. // immediate retry.
  1165. // If any disk commands get the _abort call, except for the case that
  1166. // the physical device was removed or unavailable due to hardware
  1167. // errors, it should be considered a driver error and reported to
  1168. // the author.
  1169. int cpqfcTS_abort(Scsi_Cmnd *Cmnd)
  1170. {
  1171. // printk(" cpqfcTS_abort called?? \n");
  1172. return 0;
  1173. }
  1174. int cpqfcTS_eh_abort(Scsi_Cmnd *Cmnd)
  1175. {
  1176. struct Scsi_Host *HostAdapter = Cmnd->device->host;
  1177. // get the pointer to our Scsi layer HBA buffer
  1178. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  1179. PTACHYON fcChip = &cpqfcHBAdata->fcChip;
  1180. FC_EXCHANGES *Exchanges = fcChip->Exchanges;
  1181. int i;
  1182. ENTER("cpqfcTS_eh_abort");
  1183. Cmnd->result = DID_ABORT <<16; // assume we'll find it
  1184. printk(" @Linux _abort Scsi_Cmnd %p ", Cmnd);
  1185. // See if we can find a Cmnd pointer that matches...
  1186. // The most likely case is we accepted the command
  1187. // from Linux Scsi (e.g. ceated a SEST entry) and it
  1188. // got lost somehow. If we can't find any reference
  1189. // to the passed pointer, we can only presume it
  1190. // got completed as far as our driver is concerned.
  1191. // If we found it, we will try to abort it through
  1192. // common mechanism. If FC ABTS is successful (ACC)
  1193. // or is rejected (RJT) by target, we will call
  1194. // Scsi "done" quickly. Otherwise, the ABTS will timeout
  1195. // and we'll call "done" later.
  1196. // Search the SEST exchanges for a matching Cmnd ptr.
  1197. for( i=0; i< TACH_SEST_LEN; i++)
  1198. {
  1199. if( Exchanges->fcExchange[i].Cmnd == Cmnd )
  1200. {
  1201. // found it!
  1202. printk(" x_ID %Xh, type %Xh\n", i, Exchanges->fcExchange[i].type);
  1203. Exchanges->fcExchange[i].status = INITIATOR_ABORT; // seconds default
  1204. Exchanges->fcExchange[i].timeOut = 10; // seconds default (changed later)
  1205. // Since we need to immediately return the aborted Cmnd to Scsi
  1206. // upper layers, we can't make future reference to any of its
  1207. // fields (e.g the Nexus).
  1208. cpqfcTSPutLinkQue( cpqfcHBAdata, BLS_ABTS, &i);
  1209. break;
  1210. }
  1211. }
  1212. if( i >= TACH_SEST_LEN ) // didn't find Cmnd ptr in chip's SEST?
  1213. {
  1214. // now search our non-SEST buffers (i.e. Cmnd waiting to
  1215. // start on the HBA or waiting to complete with error for retry).
  1216. // first check BadTargetCmnd
  1217. for( i=0; i< CPQFCTS_MAX_TARGET_ID; i++)
  1218. {
  1219. if( cpqfcHBAdata->BadTargetCmnd[i] == Cmnd )
  1220. {
  1221. cpqfcHBAdata->BadTargetCmnd[i] = NULL;
  1222. printk("in BadTargetCmnd Q\n");
  1223. goto Done; // exit
  1224. }
  1225. }
  1226. // if not found above...
  1227. for( i=0; i < CPQFCTS_REQ_QUEUE_LEN; i++)
  1228. {
  1229. if( cpqfcHBAdata->LinkDnCmnd[i] == Cmnd )
  1230. {
  1231. cpqfcHBAdata->LinkDnCmnd[i] = NULL;
  1232. printk("in LinkDnCmnd Q\n");
  1233. goto Done;
  1234. }
  1235. }
  1236. for( i=0; i< CPQFCTS_REQ_QUEUE_LEN; i++)
  1237. { // find spare slot
  1238. if( cpqfcHBAdata->BoardLockCmnd[i] == Cmnd )
  1239. {
  1240. cpqfcHBAdata->BoardLockCmnd[i] = NULL;
  1241. printk("in BoardLockCmnd Q\n");
  1242. goto Done;
  1243. }
  1244. }
  1245. Cmnd->result = DID_ERROR <<16; // Hmmm...
  1246. printk("Not found! ");
  1247. // panic("_abort");
  1248. }
  1249. Done:
  1250. // panic("_abort");
  1251. LEAVE("cpqfcTS_eh_abort");
  1252. return 0; // (see scsi.h)
  1253. }
  1254. // FCP-SCSI Target Device Reset
  1255. // See dpANS Fibre Channel Protocol for SCSI
  1256. // X3.269-199X revision 12, pg 25
  1257. #ifdef SUPPORT_RESET
  1258. int cpqfcTS_TargetDeviceReset( Scsi_Device *ScsiDev,
  1259. unsigned int reset_flags)
  1260. {
  1261. int timeout = 10*HZ;
  1262. int retries = 1;
  1263. char scsi_cdb[12];
  1264. int result;
  1265. Scsi_Cmnd * SCpnt;
  1266. Scsi_Device * SDpnt;
  1267. // FIXME, cpqfcTS_TargetDeviceReset needs to be fixed
  1268. // similarly to how the passthrough ioctl was fixed
  1269. // around the 2.5.30 kernel. Scsi_Cmnd replaced with
  1270. // Scsi_Request, etc.
  1271. // For now, so people don't fall into a hole...
  1272. // printk(" ENTERING cpqfcTS_TargetDeviceReset() - flag=%d \n",reset_flags);
  1273. if (ScsiDev->host->eh_active) return FAILED;
  1274. memset( scsi_cdb, 0, sizeof( scsi_cdb));
  1275. scsi_cdb[0] = RELEASE;
  1276. SCpnt = scsi_get_command(ScsiDev, GFP_KERNEL);
  1277. {
  1278. CPQFC_DECLARE_COMPLETION(wait);
  1279. SCpnt->SCp.buffers_residual = FCP_TARGET_RESET;
  1280. // FIXME: this would panic, SCpnt->request would be NULL.
  1281. SCpnt->request->CPQFC_WAITING = &wait;
  1282. scsi_do_cmd(SCpnt, scsi_cdb, NULL, 0, my_ioctl_done, timeout, retries);
  1283. CPQFC_WAIT_FOR_COMPLETION(&wait);
  1284. SCpnt->request->CPQFC_WAITING = NULL;
  1285. }
  1286. if(driver_byte(SCpnt->result) != 0)
  1287. switch(SCpnt->sense_buffer[2] & 0xf) {
  1288. case ILLEGAL_REQUEST:
  1289. if(cmd[0] == ALLOW_MEDIUM_REMOVAL) dev->lockable = 0;
  1290. else printk("SCSI device (ioctl) reports ILLEGAL REQUEST.\n");
  1291. break;
  1292. case NOT_READY: // This happens if there is no disc in drive
  1293. if(dev->removable && (cmd[0] != TEST_UNIT_READY)){
  1294. printk(KERN_INFO "Device not ready. Make sure there is a disc in the drive.\n");
  1295. break;
  1296. }
  1297. case UNIT_ATTENTION:
  1298. if (dev->removable){
  1299. dev->changed = 1;
  1300. SCpnt->result = 0; // This is no longer considered an error
  1301. // gag this error, VFS will log it anyway /axboe
  1302. // printk(KERN_INFO "Disc change detected.\n");
  1303. break;
  1304. };
  1305. default: // Fall through for non-removable media
  1306. printk("SCSI error: host %d id %d lun %d return code = %x\n",
  1307. dev->host->host_no,
  1308. dev->id,
  1309. dev->lun,
  1310. SCpnt->result);
  1311. printk("\tSense class %x, sense error %x, extended sense %x\n",
  1312. sense_class(SCpnt->sense_buffer[0]),
  1313. sense_error(SCpnt->sense_buffer[0]),
  1314. SCpnt->sense_buffer[2] & 0xf);
  1315. };
  1316. result = SCpnt->result;
  1317. SDpnt = SCpnt->device;
  1318. scsi_put_command(SCpnt);
  1319. SCpnt = NULL;
  1320. // printk(" LEAVING cpqfcTS_TargetDeviceReset() - return SUCCESS \n");
  1321. return SUCCESS;
  1322. }
  1323. #else
  1324. int cpqfcTS_TargetDeviceReset( Scsi_Device *ScsiDev,
  1325. unsigned int reset_flags)
  1326. {
  1327. return -ENOTSUPP;
  1328. }
  1329. #endif /* SUPPORT_RESET */
  1330. int cpqfcTS_eh_device_reset(Scsi_Cmnd *Cmnd)
  1331. {
  1332. int retval;
  1333. Scsi_Device *SDpnt = Cmnd->device;
  1334. // printk(" ENTERING cpqfcTS_eh_device_reset() \n");
  1335. spin_unlock_irq(Cmnd->device->host->host_lock);
  1336. retval = cpqfcTS_TargetDeviceReset( SDpnt, 0);
  1337. spin_lock_irq(Cmnd->device->host->host_lock);
  1338. return retval;
  1339. }
  1340. int cpqfcTS_reset(Scsi_Cmnd *Cmnd, unsigned int reset_flags)
  1341. {
  1342. ENTER("cpqfcTS_reset");
  1343. LEAVE("cpqfcTS_reset");
  1344. return SCSI_RESET_ERROR; /* Bus Reset Not supported */
  1345. }
  1346. /* This function determines the bios parameters for a given
  1347. harddisk. These tend to be numbers that are made up by the
  1348. host adapter. Parameters:
  1349. size, device number, list (heads, sectors,cylinders).
  1350. (from hosts.h)
  1351. */
  1352. int cpqfcTS_biosparam(struct scsi_device *sdev, struct block_device *n,
  1353. sector_t capacity, int ip[])
  1354. {
  1355. int size = capacity;
  1356. ENTER("cpqfcTS_biosparam");
  1357. ip[0] = 64;
  1358. ip[1] = 32;
  1359. ip[2] = size >> 11;
  1360. if( ip[2] > 1024 )
  1361. {
  1362. ip[0] = 255;
  1363. ip[1] = 63;
  1364. ip[2] = size / (ip[0] * ip[1]);
  1365. }
  1366. LEAVE("cpqfcTS_biosparam");
  1367. return 0;
  1368. }
  1369. irqreturn_t cpqfcTS_intr_handler( int irq,
  1370. void *dev_id,
  1371. struct pt_regs *regs)
  1372. {
  1373. unsigned long flags, InfLoopBrk=0;
  1374. struct Scsi_Host *HostAdapter = dev_id;
  1375. CPQFCHBA *cpqfcHBA = (CPQFCHBA *)HostAdapter->hostdata;
  1376. int MoreMessages = 1; // assume we have something to do
  1377. UCHAR IntPending;
  1378. int handled = 0;
  1379. ENTER("intr_handler");
  1380. spin_lock_irqsave( HostAdapter->host_lock, flags);
  1381. // is this our INT?
  1382. IntPending = readb( cpqfcHBA->fcChip.Registers.INTPEND.address);
  1383. // broken boards can generate messages forever, so
  1384. // prevent the infinite loop
  1385. #define INFINITE_IMQ_BREAK 10000
  1386. if( IntPending )
  1387. {
  1388. handled = 1;
  1389. // mask our HBA interrupts until we handle it...
  1390. writeb( 0, cpqfcHBA->fcChip.Registers.INTEN.address);
  1391. if( IntPending & 0x4) // "INT" - Tach wrote to IMQ
  1392. {
  1393. while( (++InfLoopBrk < INFINITE_IMQ_BREAK) && (MoreMessages ==1) )
  1394. {
  1395. MoreMessages = CpqTsProcessIMQEntry( HostAdapter); // ret 0 when done
  1396. }
  1397. if( InfLoopBrk >= INFINITE_IMQ_BREAK )
  1398. {
  1399. printk("WARNING: Compaq FC adapter generating excessive INTs -REPLACE\n");
  1400. printk("or investigate alternate causes (e.g. physical FC layer)\n");
  1401. }
  1402. else // working normally - re-enable INTs and continue
  1403. writeb( 0x1F, cpqfcHBA->fcChip.Registers.INTEN.address);
  1404. } // (...ProcessIMQEntry() clears INT by writing IMQ consumer)
  1405. else // indications of errors or problems...
  1406. // these usually indicate critical system hardware problems.
  1407. {
  1408. if( IntPending & 0x10 )
  1409. printk(" cpqfcTS adapter external memory parity error detected\n");
  1410. if( IntPending & 0x8 )
  1411. printk(" cpqfcTS adapter PCI master address crossed 45-bit boundary\n");
  1412. if( IntPending & 0x2 )
  1413. printk(" cpqfcTS adapter DMA error detected\n");
  1414. if( IntPending & 0x1 ) {
  1415. UCHAR IntStat;
  1416. printk(" cpqfcTS adapter PCI error detected\n");
  1417. IntStat = readb( cpqfcHBA->fcChip.Registers.INTSTAT.address);
  1418. printk("cpqfc: ISR = 0x%02x\n", IntStat);
  1419. if (IntStat & 0x1) {
  1420. __u16 pcistat;
  1421. /* read the pci status register */
  1422. pci_read_config_word(cpqfcHBA->PciDev, 0x06, &pcistat);
  1423. printk("PCI status register is 0x%04x\n", pcistat);
  1424. if (pcistat & 0x8000) printk("Parity Error Detected.\n");
  1425. if (pcistat & 0x4000) printk("Signalled System Error\n");
  1426. if (pcistat & 0x2000) printk("Received Master Abort\n");
  1427. if (pcistat & 0x1000) printk("Received Target Abort\n");
  1428. if (pcistat & 0x0800) printk("Signalled Target Abort\n");
  1429. }
  1430. if (IntStat & 0x4) printk("(INT)\n");
  1431. if (IntStat & 0x8)
  1432. printk("CRS: PCI master address crossed 46 bit bouandary\n");
  1433. if (IntStat & 0x10) printk("MRE: external memory parity error.\n");
  1434. }
  1435. }
  1436. }
  1437. spin_unlock_irqrestore( HostAdapter->host_lock, flags);
  1438. LEAVE("intr_handler");
  1439. return IRQ_RETVAL(handled);
  1440. }
  1441. int cpqfcTSDecodeGBICtype( PTACHYON fcChip, char cErrorString[])
  1442. {
  1443. // Verify GBIC type (if any) and correct Tachyon Port State Machine
  1444. // (GBIC) module definition is:
  1445. // GPIO1, GPIO0, GPIO4 for MD2, MD1, MD0. The input states appear
  1446. // to be inverted -- i.e., a setting of 111 is read when there is NO
  1447. // GBIC present. The Module Def (MD) spec says 000 is "no GBIC"
  1448. // Hard code the bit states to detect Copper,
  1449. // Long wave (single mode), Short wave (multi-mode), and absent GBIC
  1450. ULONG ulBuff;
  1451. sprintf( cErrorString, "\nGBIC detected: ");
  1452. ulBuff = fcChip->Registers.TYstatus.value & 0x13;
  1453. switch( ulBuff )
  1454. {
  1455. case 0x13: // GPIO4, GPIO1, GPIO0 = 111; no GBIC!
  1456. sprintf( &cErrorString[ strlen( cErrorString)],
  1457. "NONE! ");
  1458. return FALSE;
  1459. case 0x11: // Copper GBIC detected
  1460. sprintf( &cErrorString[ strlen( cErrorString)],
  1461. "Copper. ");
  1462. break;
  1463. case 0x10: // Long-wave (single mode) GBIC detected
  1464. sprintf( &cErrorString[ strlen( cErrorString)],
  1465. "Long-wave. ");
  1466. break;
  1467. case 0x1: // Short-wave (multi mode) GBIC detected
  1468. sprintf( &cErrorString[ strlen( cErrorString)],
  1469. "Short-wave. ");
  1470. break;
  1471. default: // unknown GBIC - presumably it will work (?)
  1472. sprintf( &cErrorString[ strlen( cErrorString)],
  1473. "Unknown. ");
  1474. break;
  1475. } // end switch GBIC detection
  1476. return TRUE;
  1477. }
  1478. int cpqfcTSGetLPSM( PTACHYON fcChip, char cErrorString[])
  1479. {
  1480. // Tachyon's Frame Manager LPSM in LinkDown state?
  1481. // (For non-loop port, check PSM instead.)
  1482. // return string with state and FALSE is Link Down
  1483. int LinkUp;
  1484. if( fcChip->Registers.FMstatus.value & 0x80 )
  1485. LinkUp = FALSE;
  1486. else
  1487. LinkUp = TRUE;
  1488. sprintf( &cErrorString[ strlen( cErrorString)],
  1489. " LPSM %Xh ",
  1490. (fcChip->Registers.FMstatus.value >>4) & 0xf );
  1491. switch( fcChip->Registers.FMstatus.value & 0xF0)
  1492. {
  1493. // bits set in LPSM
  1494. case 0x10:
  1495. sprintf( &cErrorString[ strlen( cErrorString)], "ARB");
  1496. break;
  1497. case 0x20:
  1498. sprintf( &cErrorString[ strlen( cErrorString)], "ARBwon");
  1499. break;
  1500. case 0x30:
  1501. sprintf( &cErrorString[ strlen( cErrorString)], "OPEN");
  1502. break;
  1503. case 0x40:
  1504. sprintf( &cErrorString[ strlen( cErrorString)], "OPENed");
  1505. break;
  1506. case 0x50:
  1507. sprintf( &cErrorString[ strlen( cErrorString)], "XmitCLS");
  1508. break;
  1509. case 0x60:
  1510. sprintf( &cErrorString[ strlen( cErrorString)], "RxCLS");
  1511. break;
  1512. case 0x70:
  1513. sprintf( &cErrorString[ strlen( cErrorString)], "Xfer");
  1514. break;
  1515. case 0x80:
  1516. sprintf( &cErrorString[ strlen( cErrorString)], "Init");
  1517. break;
  1518. case 0x90:
  1519. sprintf( &cErrorString[ strlen( cErrorString)], "O-IInitFin");
  1520. break;
  1521. case 0xa0:
  1522. sprintf( &cErrorString[ strlen( cErrorString)], "O-IProtocol");
  1523. break;
  1524. case 0xb0:
  1525. sprintf( &cErrorString[ strlen( cErrorString)], "O-ILipRcvd");
  1526. break;
  1527. case 0xc0:
  1528. sprintf( &cErrorString[ strlen( cErrorString)], "HostControl");
  1529. break;
  1530. case 0xd0:
  1531. sprintf( &cErrorString[ strlen( cErrorString)], "LoopFail");
  1532. break;
  1533. case 0xe0:
  1534. sprintf( &cErrorString[ strlen( cErrorString)], "Offline");
  1535. break;
  1536. case 0xf0:
  1537. sprintf( &cErrorString[ strlen( cErrorString)], "OldPort");
  1538. break;
  1539. case 0:
  1540. default:
  1541. sprintf( &cErrorString[ strlen( cErrorString)], "Monitor");
  1542. break;
  1543. }
  1544. return LinkUp;
  1545. }
  1546. #include "linux/slab.h"
  1547. // Dynamic memory allocation alignment routines
  1548. // HP's Tachyon Fibre Channel Controller chips require
  1549. // certain memory queues and register pointers to be aligned
  1550. // on various boundaries, usually the size of the Queue in question.
  1551. // Alignment might be on 2, 4, 8, ... or even 512 byte boundaries.
  1552. // Since most O/Ss don't allow this (usually only Cache aligned -
  1553. // 32-byte boundary), these routines provide generic alignment (after
  1554. // O/S allocation) at any boundary, and store the original allocated
  1555. // pointer for deletion (O/S free function). Typically, we expect
  1556. // these functions to only be called at HBA initialization and
  1557. // removal time (load and unload times)
  1558. // ALGORITHM notes:
  1559. // Memory allocation varies by compiler and platform. In the worst case,
  1560. // we are only assured BYTE alignment, but in the best case, we can
  1561. // request allocation on any desired boundary. Our strategy: pad the
  1562. // allocation request size (i.e. waste memory) so that we are assured
  1563. // of passing desired boundary near beginning of contiguous space, then
  1564. // mask out lower address bits.
  1565. // We define the following algorithm:
  1566. // allocBoundary - compiler/platform specific address alignment
  1567. // in number of bytes (default is single byte; i.e. 1)
  1568. // n_alloc - number of bytes application wants @ aligned address
  1569. // ab - alignment boundary, in bytes (e.g. 4, 32, ...)
  1570. // t_alloc - total allocation needed to ensure desired boundary
  1571. // mask - to clear least significant address bits for boundary
  1572. // Compute:
  1573. // t_alloc = n_alloc + (ab - allocBoundary)
  1574. // allocate t_alloc bytes @ alloc_address
  1575. // mask = NOT (ab - 1)
  1576. // (e.g. if ab=32 _0001 1111 -> _1110 0000
  1577. // aligned_address = alloc_address & mask
  1578. // set n_alloc bytes to 0
  1579. // return aligned_address (NULL if failed)
  1580. //
  1581. // If u32_AlignedAddress is non-zero, then search for BaseAddress (stored
  1582. // from previous allocation). If found, invoke call to FREE the memory.
  1583. // Return NULL if BaseAddress not found
  1584. // we need about 8 allocations per HBA. Figuring at most 10 HBAs per server
  1585. // size the dynamic_mem array at 80.
  1586. void* fcMemManager( struct pci_dev *pdev, ALIGNED_MEM *dynamic_mem,
  1587. ULONG n_alloc, ULONG ab, ULONG u32_AlignedAddress,
  1588. dma_addr_t *dma_handle)
  1589. {
  1590. USHORT allocBoundary=1; // compiler specific - worst case 1
  1591. // best case - replace malloc() call
  1592. // with function that allocates exactly
  1593. // at desired boundary
  1594. unsigned long ulAddress;
  1595. ULONG t_alloc, i;
  1596. void *alloc_address = 0; // def. error code / address not found
  1597. LONG mask; // must be 32-bits wide!
  1598. ENTER("fcMemManager");
  1599. if( u32_AlignedAddress ) // are we freeing existing memory?
  1600. {
  1601. // printk(" freeing AlignedAddress %Xh\n", u32_AlignedAddress);
  1602. for( i=0; i<DYNAMIC_ALLOCATIONS; i++) // look for the base address
  1603. {
  1604. // printk("dynamic_mem[%u].AlignedAddress %lX\n", i, dynamic_mem[i].AlignedAddress);
  1605. if( dynamic_mem[i].AlignedAddress == u32_AlignedAddress )
  1606. {
  1607. alloc_address = dynamic_mem[i].BaseAllocated; // 'success' status
  1608. pci_free_consistent(pdev,dynamic_mem[i].size,
  1609. alloc_address,
  1610. dynamic_mem[i].dma_handle);
  1611. dynamic_mem[i].BaseAllocated = 0; // clear for next use
  1612. dynamic_mem[i].AlignedAddress = 0;
  1613. dynamic_mem[i].size = 0;
  1614. break; // quit for loop; done
  1615. }
  1616. }
  1617. }
  1618. else if( n_alloc ) // want new memory?
  1619. {
  1620. dma_addr_t handle;
  1621. t_alloc = n_alloc + (ab - allocBoundary); // pad bytes for alignment
  1622. // printk("pci_alloc_consistent() for Tach alignment: %ld bytes\n", t_alloc);
  1623. // (would like to) allow thread block to free pages
  1624. alloc_address = // total bytes (NumberOfBytes)
  1625. pci_alloc_consistent(pdev, t_alloc, &handle);
  1626. // now mask off least sig. bits of address
  1627. if( alloc_address ) // (only if non-NULL)
  1628. {
  1629. // find place to store ptr, so we
  1630. // can free it later...
  1631. mask = (LONG)(ab - 1); // mask all low-order bits
  1632. mask = ~mask; // invert bits
  1633. for( i=0; i<DYNAMIC_ALLOCATIONS; i++) // look for free slot
  1634. {
  1635. if( dynamic_mem[i].BaseAllocated == 0) // take 1st available
  1636. {
  1637. dynamic_mem[i].BaseAllocated = alloc_address;// address from O/S
  1638. dynamic_mem[i].dma_handle = handle;
  1639. if (dma_handle != NULL)
  1640. {
  1641. // printk("handle = %p, ab=%d, boundary = %d, mask=0x%08x\n",
  1642. // handle, ab, allocBoundary, mask);
  1643. *dma_handle = (dma_addr_t)
  1644. ((((ULONG)handle) + (ab - allocBoundary)) & mask);
  1645. }
  1646. dynamic_mem[i].size = t_alloc;
  1647. break;
  1648. }
  1649. }
  1650. ulAddress = (unsigned long)alloc_address;
  1651. ulAddress += (ab - allocBoundary); // add the alignment bytes-
  1652. // then truncate address...
  1653. alloc_address = (void*)(ulAddress & mask);
  1654. dynamic_mem[i].AlignedAddress =
  1655. (ULONG)(ulAddress & mask); // 32bit Tach address
  1656. memset( alloc_address, 0, n_alloc ); // clear new memory
  1657. }
  1658. else // O/S dynamic mem alloc failed!
  1659. alloc_address = 0; // (for debugging breakpt)
  1660. }
  1661. LEAVE("fcMemManager");
  1662. return alloc_address; // good (or NULL) address
  1663. }
  1664. static Scsi_Host_Template driver_template = {
  1665. .detect = cpqfcTS_detect,
  1666. .release = cpqfcTS_release,
  1667. .info = cpqfcTS_info,
  1668. .proc_info = cpqfcTS_proc_info,
  1669. .ioctl = cpqfcTS_ioctl,
  1670. .queuecommand = cpqfcTS_queuecommand,
  1671. .eh_device_reset_handler = cpqfcTS_eh_device_reset,
  1672. .eh_abort_handler = cpqfcTS_eh_abort,
  1673. .bios_param = cpqfcTS_biosparam,
  1674. .can_queue = CPQFCTS_REQ_QUEUE_LEN,
  1675. .this_id = -1,
  1676. .sg_tablesize = SG_ALL,
  1677. .cmd_per_lun = CPQFCTS_CMD_PER_LUN,
  1678. .use_clustering = ENABLE_CLUSTERING,
  1679. };
  1680. #include "scsi_module.c"