cpqfcTSinit.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  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. kfree(buf);
  574. return result;
  575. }
  576. case CPQFCTS_GETPCIINFO:
  577. {
  578. cpqfc_pci_info_struct pciinfo;
  579. if( !arg)
  580. return -EINVAL;
  581. pciinfo.bus = cpqfcHBAdata->PciDev->bus->number;
  582. pciinfo.dev_fn = cpqfcHBAdata->PciDev->devfn;
  583. pciinfo.board_id = cpqfcHBAdata->PciDev->device |
  584. (cpqfcHBAdata->PciDev->vendor <<16);
  585. if(copy_to_user( arg, &pciinfo, sizeof(cpqfc_pci_info_struct)))
  586. return( -EFAULT);
  587. return 0;
  588. }
  589. case CPQFCTS_GETDRIVVER:
  590. {
  591. DriverVer_type DriverVer =
  592. CPQFCTS_DRIVER_VER( VER_MAJOR,VER_MINOR,VER_SUBMINOR);
  593. if( !arg)
  594. return -EINVAL;
  595. if(copy_to_user( arg, &DriverVer, sizeof(DriverVer)))
  596. return( -EFAULT);
  597. return 0;
  598. }
  599. case CPQFC_IOCTL_FC_TARGET_ADDRESS:
  600. // can we find an FC device mapping to this SCSI target?
  601. /* DumCmnd.channel = ScsiDev->channel; */ // For searching
  602. /* DumCmnd.target = ScsiDev->id; */
  603. /* DumCmnd.lun = ScsiDev->lun; */
  604. DumCmnd = scsi_get_command (ScsiDev, GFP_KERNEL);
  605. if (!DumCmnd)
  606. return -ENOMEM;
  607. pLoggedInPort = fcFindLoggedInPort( fcChip,
  608. DumCmnd, // search Scsi Nexus
  609. 0, // DON'T search linked list for FC port id
  610. NULL, // DON'T search linked list for FC WWN
  611. NULL); // DON'T care about end of list
  612. scsi_put_command (DumCmnd);
  613. if (pLoggedInPort == NULL) {
  614. result = -ENXIO;
  615. break;
  616. }
  617. result = access_ok(VERIFY_WRITE, arg, sizeof(Scsi_FCTargAddress)) ? 0 : -EFAULT;
  618. if (result) break;
  619. put_user(pLoggedInPort->port_id,
  620. &((Scsi_FCTargAddress *) arg)->host_port_id);
  621. for( i=3,j=0; i>=0; i--) // copy the LOGIN port's WWN
  622. put_user(pLoggedInPort->u.ucWWN[i],
  623. &((Scsi_FCTargAddress *) arg)->host_wwn[j++]);
  624. for( i=7; i>3; i--) // copy the LOGIN port's WWN
  625. put_user(pLoggedInPort->u.ucWWN[i],
  626. &((Scsi_FCTargAddress *) arg)->host_wwn[j++]);
  627. break;
  628. case CPQFC_IOCTL_FC_TDR:
  629. result = cpqfcTS_TargetDeviceReset( ScsiDev, 0);
  630. break;
  631. default:
  632. result = -EINVAL;
  633. break;
  634. }
  635. LEAVE("cpqfcTS_ioctl");
  636. return result;
  637. }
  638. /* "Release" the Host Bus Adapter...
  639. disable interrupts, stop the HBA, release the interrupt,
  640. and free all resources */
  641. int cpqfcTS_release(struct Scsi_Host *HostAdapter)
  642. {
  643. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  644. ENTER("cpqfcTS_release");
  645. DEBUG_PCI( printk(" cpqfcTS: delete timer...\n"));
  646. del_timer( &cpqfcHBAdata->cpqfcTStimer);
  647. // disable the hardware...
  648. DEBUG_PCI( printk(" disable hardware, destroy queues, free mem\n"));
  649. cpqfcHBAdata->fcChip.ResetTachyon( cpqfcHBAdata, CLEAR_FCPORTS);
  650. // kill kernel thread
  651. if( cpqfcHBAdata->worker_thread ) // (only if exists)
  652. {
  653. DECLARE_MUTEX_LOCKED(sem); // synchronize thread kill
  654. cpqfcHBAdata->notify_wt = &sem;
  655. DEBUG_PCI( printk(" killing kernel thread\n"));
  656. send_sig( SIGKILL, cpqfcHBAdata->worker_thread, 1);
  657. down( &sem);
  658. cpqfcHBAdata->notify_wt = NULL;
  659. }
  660. cpqfc_free_private_data_pool(cpqfcHBAdata);
  661. // free Linux resources
  662. DEBUG_PCI( printk(" cpqfcTS: freeing resources...\n"));
  663. free_irq( HostAdapter->irq, HostAdapter);
  664. scsi_unregister( HostAdapter);
  665. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseL, 0xff);
  666. release_region( cpqfcHBAdata->fcChip.Registers.IOBaseU, 0xff);
  667. /* we get "vfree: bad address" executing this - need to investigate...
  668. if( (void*)((unsigned long)cpqfcHBAdata->fcChip.Registers.MemBase) !=
  669. cpqfcHBAdata->fcChip.Registers.ReMapMemBase)
  670. vfree( cpqfcHBAdata->fcChip.Registers.ReMapMemBase);
  671. */
  672. pci_disable_device( cpqfcHBAdata->PciDev);
  673. LEAVE("cpqfcTS_release");
  674. return 0;
  675. }
  676. const char * cpqfcTS_info(struct Scsi_Host *HostAdapter)
  677. {
  678. static char buf[300];
  679. CPQFCHBA *cpqfcHBA;
  680. int BusSpeed, BusWidth;
  681. // get the pointer to our Scsi layer HBA buffer
  682. cpqfcHBA = (CPQFCHBA *)HostAdapter->hostdata;
  683. BusWidth = (cpqfcHBA->fcChip.Registers.PCIMCTR &0x4) > 0 ?
  684. 64 : 32;
  685. if( cpqfcHBA->fcChip.Registers.TYconfig.value & 0x80000000)
  686. BusSpeed = 66;
  687. else
  688. BusSpeed = 33;
  689. sprintf(buf,
  690. "%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",
  691. cpqfcHBA->fcChip.Name,
  692. cpqfcHBA->fcChip.Registers.wwn_hi,
  693. cpqfcHBA->fcChip.Registers.wwn_lo,
  694. cpqfcHBA->PciDev->bus->number,
  695. cpqfcHBA->PciDev->device,
  696. HostAdapter->irq,
  697. cpqfcHBA->fcChip.Registers.IOBaseL,
  698. cpqfcHBA->fcChip.Registers.MemBase,
  699. BusWidth,
  700. BusSpeed,
  701. VER_MAJOR, VER_MINOR, VER_SUBMINOR
  702. );
  703. cpqfcTSDecodeGBICtype( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  704. cpqfcTSGetLPSM( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  705. return buf;
  706. }
  707. //
  708. // /proc/scsi support. The following routines allow us to do 'normal'
  709. // sprintf like calls to return the currently requested piece (buflenght
  710. // chars, starting at bufoffset) of the file. Although procfs allows for
  711. // a 1 Kb bytes overflow after te supplied buffer, I consider it bad
  712. // programming to use it to make programming a little simpler. This piece
  713. // of coding is borrowed from ncr53c8xx.c with some modifications
  714. //
  715. struct info_str
  716. {
  717. char *buffer; // Pointer to output buffer
  718. int buflength; // It's length
  719. int bufoffset; // File offset corresponding with buf[0]
  720. int buffillen; // Current filled length
  721. int filpos; // Current file offset
  722. };
  723. static void copy_mem_info(struct info_str *info, char *data, int datalen)
  724. {
  725. if (info->filpos < info->bufoffset) { // Current offset before buffer offset
  726. if (info->filpos + datalen <= info->bufoffset) {
  727. info->filpos += datalen; // Discard if completely before buffer
  728. return;
  729. } else { // Partial copy, set to begin
  730. data += (info->bufoffset - info->filpos);
  731. datalen -= (info->bufoffset - info->filpos);
  732. info->filpos = info->bufoffset;
  733. }
  734. }
  735. info->filpos += datalen; // Update current offset
  736. if (info->buffillen == info->buflength) // Buffer full, discard
  737. return;
  738. if (info->buflength - info->buffillen < datalen) // Overflows buffer ?
  739. datalen = info->buflength - info->buffillen;
  740. memcpy(info->buffer + info->buffillen, data, datalen);
  741. info->buffillen += datalen;
  742. }
  743. static int copy_info(struct info_str *info, char *fmt, ...)
  744. {
  745. va_list args;
  746. char buf[400];
  747. int len;
  748. va_start(args, fmt);
  749. len = vsprintf(buf, fmt, args);
  750. va_end(args);
  751. copy_mem_info(info, buf, len);
  752. return len;
  753. }
  754. // Routine to get data for /proc RAM filesystem
  755. //
  756. int cpqfcTS_proc_info (struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length,
  757. int inout)
  758. {
  759. struct scsi_cmnd *DumCmnd;
  760. struct scsi_device *ScsiDev;
  761. int Chan, Targ, i;
  762. struct info_str info;
  763. CPQFCHBA *cpqfcHBA;
  764. PTACHYON fcChip;
  765. PFC_LOGGEDIN_PORT pLoggedInPort;
  766. char buf[81];
  767. if (inout) return -EINVAL;
  768. // get the pointer to our Scsi layer HBA buffer
  769. cpqfcHBA = (CPQFCHBA *)host->hostdata;
  770. fcChip = &cpqfcHBA->fcChip;
  771. *start = buffer;
  772. info.buffer = buffer;
  773. info.buflength = length;
  774. info.bufoffset = offset;
  775. info.filpos = 0;
  776. info.buffillen = 0;
  777. copy_info(&info, "Driver version = %d.%d.%d", VER_MAJOR, VER_MINOR, VER_SUBMINOR);
  778. cpqfcTSDecodeGBICtype( &cpqfcHBA->fcChip, &buf[0]);
  779. cpqfcTSGetLPSM( &cpqfcHBA->fcChip, &buf[ strlen(buf)]);
  780. copy_info(&info, "%s\n", buf);
  781. #define DISPLAY_WWN_INFO
  782. #ifdef DISPLAY_WWN_INFO
  783. ScsiDev = scsi_get_host_dev (host);
  784. if (!ScsiDev)
  785. return -ENOMEM;
  786. DumCmnd = scsi_get_command (ScsiDev, GFP_KERNEL);
  787. if (!DumCmnd) {
  788. scsi_free_host_dev (ScsiDev);
  789. return -ENOMEM;
  790. }
  791. copy_info(&info, "WWN database: (\"port_id: 000000\" means disconnected)\n");
  792. for ( Chan=0; Chan <= host->max_channel; Chan++) {
  793. DumCmnd->device->channel = Chan;
  794. for (Targ=0; Targ <= host->max_id; Targ++) {
  795. DumCmnd->device->id = Targ;
  796. if ((pLoggedInPort = fcFindLoggedInPort( fcChip,
  797. DumCmnd, // search Scsi Nexus
  798. 0, // DON'T search list for FC port id
  799. NULL, // DON'T search list for FC WWN
  800. NULL))){ // DON'T care about end of list
  801. copy_info(&info, "Host: scsi%d Channel: %02d TargetId: %02d -> WWN: ",
  802. host->host_no, Chan, Targ);
  803. for( i=3; i>=0; i--) // copy the LOGIN port's WWN
  804. copy_info(&info, "%02X", pLoggedInPort->u.ucWWN[i]);
  805. for( i=7; i>3; i--) // copy the LOGIN port's WWN
  806. copy_info(&info, "%02X", pLoggedInPort->u.ucWWN[i]);
  807. copy_info(&info, " port_id: %06X\n", pLoggedInPort->port_id);
  808. }
  809. }
  810. }
  811. scsi_put_command (DumCmnd);
  812. scsi_free_host_dev (ScsiDev);
  813. #endif
  814. // Unfortunately, the proc_info buffer isn't big enough
  815. // for everything we would like...
  816. // For FC stats, compile this and turn off WWN stuff above
  817. //#define DISPLAY_FC_STATS
  818. #ifdef DISPLAY_FC_STATS
  819. // get the Fibre Channel statistics
  820. {
  821. int DeltaSecs = (jiffies - cpqfcHBA->fcStatsTime) / HZ;
  822. int days,hours,minutes,secs;
  823. days = DeltaSecs / (3600*24); // days
  824. hours = (DeltaSecs% (3600*24)) / 3600; // hours
  825. minutes = (DeltaSecs%3600 /60); // minutes
  826. secs = DeltaSecs%60; // secs
  827. copy_info( &info, "Fibre Channel Stats (time dd:hh:mm:ss %02u:%02u:%02u:%02u\n",
  828. days, hours, minutes, secs);
  829. }
  830. cpqfcHBA->fcStatsTime = jiffies; // (for next delta)
  831. copy_info( &info, " LinkUp %9u LinkDown %u\n",
  832. fcChip->fcStats.linkUp, fcChip->fcStats.linkDown);
  833. copy_info( &info, " Loss of Signal %9u Loss of Sync %u\n",
  834. fcChip->fcStats.LossofSignal, fcChip->fcStats.LossofSync);
  835. copy_info( &info, " Discarded Frames %9u Bad CRC Frame %u\n",
  836. fcChip->fcStats.Dis_Frm, fcChip->fcStats.Bad_CRC);
  837. copy_info( &info, " TACH LinkFailTX %9u TACH LinkFailRX %u\n",
  838. fcChip->fcStats.linkFailTX, fcChip->fcStats.linkFailRX);
  839. copy_info( &info, " TACH RxEOFa %9u TACH Elastic Store %u\n",
  840. fcChip->fcStats.Rx_EOFa, fcChip->fcStats.e_stores);
  841. copy_info( &info, " BufferCreditWait %9uus TACH FM Inits %u\n",
  842. fcChip->fcStats.BB0_Timer*10, fcChip->fcStats.FMinits );
  843. copy_info( &info, " FC-2 Timeouts %9u FC-2 Logouts %u\n",
  844. fcChip->fcStats.timeouts, fcChip->fcStats.logouts);
  845. copy_info( &info, " FC-2 Aborts %9u FC-4 Aborts %u\n",
  846. fcChip->fcStats.FC2aborted, fcChip->fcStats.FC4aborted);
  847. // clear the counters
  848. cpqfcTSClearLinkStatusCounters( fcChip);
  849. #endif
  850. return info.buffillen;
  851. }
  852. #if DEBUG_CMND
  853. UCHAR *ScsiToAscii( UCHAR ScsiCommand)
  854. {
  855. /*++
  856. Routine Description:
  857. Converts a SCSI command to a text string for debugging purposes.
  858. Arguments:
  859. ScsiCommand -- hex value SCSI Command
  860. Return Value:
  861. An ASCII, null-terminated string if found, else returns NULL.
  862. Original code from M. McGowen, Compaq
  863. --*/
  864. switch (ScsiCommand)
  865. {
  866. case 0x00:
  867. return( "Test Unit Ready" );
  868. case 0x01:
  869. return( "Rezero Unit or Rewind" );
  870. case 0x02:
  871. return( "Request Block Address" );
  872. case 0x03:
  873. return( "Requese Sense" );
  874. case 0x04:
  875. return( "Format Unit" );
  876. case 0x05:
  877. return( "Read Block Limits" );
  878. case 0x07:
  879. return( "Reassign Blocks" );
  880. case 0x08:
  881. return( "Read (6)" );
  882. case 0x0a:
  883. return( "Write (6)" );
  884. case 0x0b:
  885. return( "Seek (6)" );
  886. case 0x12:
  887. return( "Inquiry" );
  888. case 0x15:
  889. return( "Mode Select (6)" );
  890. case 0x16:
  891. return( "Reserve" );
  892. case 0x17:
  893. return( "Release" );
  894. case 0x1a:
  895. return( "ModeSen(6)" );
  896. case 0x1b:
  897. return( "Start/Stop Unit" );
  898. case 0x1c:
  899. return( "Receive Diagnostic Results" );
  900. case 0x1d:
  901. return( "Send Diagnostic" );
  902. case 0x25:
  903. return( "Read Capacity" );
  904. case 0x28:
  905. return( "Read (10)" );
  906. case 0x2a:
  907. return( "Write (10)" );
  908. case 0x2b:
  909. return( "Seek (10)" );
  910. case 0x2e:
  911. return( "Write and Verify" );
  912. case 0x2f:
  913. return( "Verify" );
  914. case 0x34:
  915. return( "Pre-Fetch" );
  916. case 0x35:
  917. return( "Synchronize Cache" );
  918. case 0x37:
  919. return( "Read Defect Data (10)" );
  920. case 0x3b:
  921. return( "Write Buffer" );
  922. case 0x3c:
  923. return( "Read Buffer" );
  924. case 0x3e:
  925. return( "Read Long" );
  926. case 0x3f:
  927. return( "Write Long" );
  928. case 0x41:
  929. return( "Write Same" );
  930. case 0x4c:
  931. return( "Log Select" );
  932. case 0x4d:
  933. return( "Log Sense" );
  934. case 0x56:
  935. return( "Reserve (10)" );
  936. case 0x57:
  937. return( "Release (10)" );
  938. case 0xa0:
  939. return( "ReportLuns" );
  940. case 0xb7:
  941. return( "Read Defect Data (12)" );
  942. case 0xca:
  943. return( "Peripheral Device Addressing SCSI Passthrough" );
  944. case 0xcb:
  945. return( "Compaq Array Firmware Passthrough" );
  946. default:
  947. return( NULL );
  948. }
  949. } // end ScsiToAscii()
  950. void cpqfcTS_print_scsi_cmd(Scsi_Cmnd * cmd)
  951. {
  952. printk("cpqfcTS: (%s) chnl 0x%02x, trgt = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  953. ScsiToAscii( cmd->cmnd[0]), cmd->channel, cmd->target, cmd->lun, cmd->cmd_len);
  954. if( cmd->cmnd[0] == 0) // Test Unit Ready?
  955. {
  956. int i;
  957. printk("Cmnd->request_bufflen = 0x%X, ->use_sg = %d, ->bufflen = %d\n",
  958. cmd->request_bufflen, cmd->use_sg, cmd->bufflen);
  959. printk("Cmnd->request_buffer = %p, ->sglist_len = %d, ->buffer = %p\n",
  960. cmd->request_buffer, cmd->sglist_len, cmd->buffer);
  961. for (i = 0; i < cmd->cmd_len; i++)
  962. printk("0x%02x ", cmd->cmnd[i]);
  963. printk("\n");
  964. }
  965. }
  966. #endif /* DEBUG_CMND */
  967. static void QueCmndOnBoardLock( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  968. {
  969. int i;
  970. for( i=0; i< CPQFCTS_REQ_QUEUE_LEN; i++)
  971. { // find spare slot
  972. if( cpqfcHBAdata->BoardLockCmnd[i] == NULL )
  973. {
  974. cpqfcHBAdata->BoardLockCmnd[i] = Cmnd;
  975. // printk(" BoardLockCmnd[%d] %p Queued, chnl/target/lun %d/%d/%d\n",
  976. // i,Cmnd, Cmnd->channel, Cmnd->target, Cmnd->lun);
  977. break;
  978. }
  979. }
  980. if( i >= CPQFCTS_REQ_QUEUE_LEN)
  981. {
  982. printk(" cpqfcTS WARNING: Lost Cmnd %p on BoardLock Q full!", Cmnd);
  983. }
  984. }
  985. static void QueLinkDownCmnd( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  986. {
  987. int indx;
  988. // Remember the command ptr so we can return; we'll complete when
  989. // the device comes back, causing immediate retry
  990. for( indx=0; indx < CPQFCTS_REQ_QUEUE_LEN; indx++)//, SCptr++)
  991. {
  992. if( cpqfcHBAdata->LinkDnCmnd[indx] == NULL ) // available?
  993. {
  994. #ifdef DUMMYCMND_DBG
  995. printk(" @add Cmnd %p to LnkDnCmnd[%d]@ ", Cmnd,indx);
  996. #endif
  997. cpqfcHBAdata->LinkDnCmnd[indx] = Cmnd;
  998. break;
  999. }
  1000. }
  1001. if( indx >= CPQFCTS_REQ_QUEUE_LEN ) // no space for Cmnd??
  1002. {
  1003. // this will result in an _abort call later (with possible trouble)
  1004. printk("no buffer for LinkDnCmnd!! %p\n", Cmnd);
  1005. }
  1006. }
  1007. // The file <scsi/scsi_host.h> says not to call scsi_done from
  1008. // inside _queuecommand, so we'll do it from the heartbeat timer
  1009. // (clarification: Turns out it's ok to call scsi_done from queuecommand
  1010. // for cases that don't go to the hardware like scsi cmds destined
  1011. // for LUNs we know don't exist, so this code might be simplified...)
  1012. static void QueBadTargetCmnd( CPQFCHBA *cpqfcHBAdata, Scsi_Cmnd *Cmnd)
  1013. {
  1014. int i;
  1015. // printk(" can't find target %d\n", Cmnd->target);
  1016. for( i=0; i< CPQFCTS_MAX_TARGET_ID; i++)
  1017. { // find spare slot
  1018. if( cpqfcHBAdata->BadTargetCmnd[i] == NULL )
  1019. {
  1020. cpqfcHBAdata->BadTargetCmnd[i] = Cmnd;
  1021. // printk(" BadTargetCmnd[%d] %p Queued, chnl/target/lun %d/%d/%d\n",
  1022. // i,Cmnd, Cmnd->channel, Cmnd->target, Cmnd->lun);
  1023. break;
  1024. }
  1025. }
  1026. }
  1027. // This is the "main" entry point for Linux Scsi commands --
  1028. // it all starts here.
  1029. int cpqfcTS_queuecommand(Scsi_Cmnd *Cmnd, void (* done)(Scsi_Cmnd *))
  1030. {
  1031. struct Scsi_Host *HostAdapter = Cmnd->device->host;
  1032. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  1033. PTACHYON fcChip = &cpqfcHBAdata->fcChip;
  1034. TachFCHDR_GCMND fchs; // only use for FC destination id field
  1035. PFC_LOGGEDIN_PORT pLoggedInPort;
  1036. ULONG ulStatus, SESTtype;
  1037. LONG ExchangeID;
  1038. ENTER("cpqfcTS_queuecommand");
  1039. PCI_TRACEO( (ULONG)Cmnd, 0x98)
  1040. Cmnd->scsi_done = done;
  1041. #ifdef DEBUG_CMND
  1042. cpqfcTS_print_scsi_cmd( Cmnd);
  1043. #endif
  1044. // prevent board contention with kernel thread...
  1045. if( cpqfcHBAdata->BoardLock )
  1046. {
  1047. // printk(" @BrdLck Hld@ ");
  1048. QueCmndOnBoardLock( cpqfcHBAdata, Cmnd);
  1049. }
  1050. else
  1051. {
  1052. // in the current system (2.2.12), this routine is called
  1053. // after spin_lock_irqsave(), so INTs are disabled. However,
  1054. // we might have something pending in the LinkQ, which
  1055. // might cause the WorkerTask to run. In case that
  1056. // happens, make sure we lock it out.
  1057. PCI_TRACE( 0x98)
  1058. CPQ_SPINLOCK_HBA( cpqfcHBAdata)
  1059. PCI_TRACE( 0x98)
  1060. // can we find an FC device mapping to this SCSI target?
  1061. pLoggedInPort = fcFindLoggedInPort( fcChip,
  1062. Cmnd, // search Scsi Nexus
  1063. 0, // DON'T search linked list for FC port id
  1064. NULL, // DON'T search linked list for FC WWN
  1065. NULL); // DON'T care about end of list
  1066. if( pLoggedInPort == NULL ) // not found!
  1067. {
  1068. // printk(" @Q bad targ cmnd %p@ ", Cmnd);
  1069. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1070. }
  1071. else if (Cmnd->device->lun >= CPQFCTS_MAX_LUN)
  1072. {
  1073. printk(KERN_WARNING "cpqfc: Invalid LUN: %d\n", Cmnd->device->lun);
  1074. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1075. }
  1076. else // we know what FC device to send to...
  1077. {
  1078. // does this device support FCP target functions?
  1079. // (determined by PRLI field)
  1080. if( !(pLoggedInPort->fcp_info & TARGET_FUNCTION) )
  1081. {
  1082. printk(" Doesn't support TARGET functions port_id %Xh\n",
  1083. pLoggedInPort->port_id );
  1084. QueBadTargetCmnd( cpqfcHBAdata, Cmnd);
  1085. }
  1086. // In this case (previous login OK), the device is temporarily
  1087. // unavailable waiting for re-login, in which case we expect it
  1088. // to be back in between 25 - 500ms.
  1089. // If the FC port doesn't log back in within several seconds
  1090. // (i.e. implicit "logout"), or we get an explicit logout,
  1091. // we set "device_blocked" in Scsi_Device struct; in this
  1092. // case 30 seconds will elapse before Linux/Scsi sends another
  1093. // command to the device.
  1094. else if( pLoggedInPort->prli != TRUE )
  1095. {
  1096. // printk("Device (Chnl/Target %d/%d) invalid PRLI, port_id %06lXh\n",
  1097. // Cmnd->channel, Cmnd->target, pLoggedInPort->port_id);
  1098. QueLinkDownCmnd( cpqfcHBAdata, Cmnd);
  1099. // Need to use "blocked" flag??
  1100. // Cmnd->device->device_blocked = TRUE; // just let it timeout
  1101. }
  1102. else // device supports TARGET functions, and is logged in...
  1103. {
  1104. // (context of fchs is to "reply" to...)
  1105. fchs.s_id = pLoggedInPort->port_id; // destination FC address
  1106. // what is the data direction? For data TO the device,
  1107. // we need IWE (Intiator Write Entry). Otherwise, IRE.
  1108. if( Cmnd->cmnd[0] == WRITE_10 ||
  1109. Cmnd->cmnd[0] == WRITE_6 ||
  1110. Cmnd->cmnd[0] == WRITE_BUFFER ||
  1111. Cmnd->cmnd[0] == VENDOR_WRITE_OPCODE || // CPQ specific
  1112. Cmnd->cmnd[0] == MODE_SELECT )
  1113. {
  1114. SESTtype = SCSI_IWE; // data from HBA to Device
  1115. }
  1116. else
  1117. SESTtype = SCSI_IRE; // data from Device to HBA
  1118. ulStatus = cpqfcTSBuildExchange(
  1119. cpqfcHBAdata,
  1120. SESTtype, // e.g. Initiator Read Entry (IRE)
  1121. &fchs, // we are originator; only use d_id
  1122. Cmnd, // Linux SCSI command (with scatter/gather list)
  1123. &ExchangeID );// fcController->fcExchanges index, -1 if failed
  1124. if( !ulStatus ) // Exchange setup?
  1125. {
  1126. if( cpqfcHBAdata->BoardLock )
  1127. {
  1128. TriggerHBA( fcChip->Registers.ReMapMemBase, 0);
  1129. printk(" @bl! %d, xID %Xh@ ", current->pid, ExchangeID);
  1130. }
  1131. ulStatus = cpqfcTSStartExchange( cpqfcHBAdata, ExchangeID );
  1132. if( !ulStatus )
  1133. {
  1134. PCI_TRACEO( ExchangeID, 0xB8)
  1135. // submitted to Tach's Outbound Que (ERQ PI incremented)
  1136. // waited for completion for ELS type (Login frames issued
  1137. // synchronously)
  1138. }
  1139. else
  1140. // check reason for Exchange not being started - we might
  1141. // want to Queue and start later, or fail with error
  1142. {
  1143. printk("quecommand: cpqfcTSStartExchange failed: %Xh\n", ulStatus );
  1144. }
  1145. } // end good BuildExchange status
  1146. else // SEST table probably full -- why? hardware hang?
  1147. {
  1148. printk("quecommand: cpqfcTSBuildExchange faild: %Xh\n", ulStatus);
  1149. }
  1150. } // end can't do FCP-SCSI target functions
  1151. } // end can't find target (FC device)
  1152. CPQ_SPINUNLOCK_HBA( cpqfcHBAdata)
  1153. }
  1154. PCI_TRACEO( (ULONG)Cmnd, 0x9C)
  1155. LEAVE("cpqfcTS_queuecommand");
  1156. return 0;
  1157. }
  1158. // Entry point for upper Scsi layer intiated abort. Typically
  1159. // this is called if the command (for hard disk) fails to complete
  1160. // in 30 seconds. This driver intends to complete all disk commands
  1161. // within Exchange ".timeOut" seconds (now 7) with target status, or
  1162. // in case of ".timeOut" expiration, a DID_SOFT_ERROR which causes
  1163. // immediate retry.
  1164. // If any disk commands get the _abort call, except for the case that
  1165. // the physical device was removed or unavailable due to hardware
  1166. // errors, it should be considered a driver error and reported to
  1167. // the author.
  1168. int cpqfcTS_abort(Scsi_Cmnd *Cmnd)
  1169. {
  1170. // printk(" cpqfcTS_abort called?? \n");
  1171. return 0;
  1172. }
  1173. int cpqfcTS_eh_abort(Scsi_Cmnd *Cmnd)
  1174. {
  1175. struct Scsi_Host *HostAdapter = Cmnd->device->host;
  1176. // get the pointer to our Scsi layer HBA buffer
  1177. CPQFCHBA *cpqfcHBAdata = (CPQFCHBA *)HostAdapter->hostdata;
  1178. PTACHYON fcChip = &cpqfcHBAdata->fcChip;
  1179. FC_EXCHANGES *Exchanges = fcChip->Exchanges;
  1180. int i;
  1181. ENTER("cpqfcTS_eh_abort");
  1182. Cmnd->result = DID_ABORT <<16; // assume we'll find it
  1183. printk(" @Linux _abort Scsi_Cmnd %p ", Cmnd);
  1184. // See if we can find a Cmnd pointer that matches...
  1185. // The most likely case is we accepted the command
  1186. // from Linux Scsi (e.g. ceated a SEST entry) and it
  1187. // got lost somehow. If we can't find any reference
  1188. // to the passed pointer, we can only presume it
  1189. // got completed as far as our driver is concerned.
  1190. // If we found it, we will try to abort it through
  1191. // common mechanism. If FC ABTS is successful (ACC)
  1192. // or is rejected (RJT) by target, we will call
  1193. // Scsi "done" quickly. Otherwise, the ABTS will timeout
  1194. // and we'll call "done" later.
  1195. // Search the SEST exchanges for a matching Cmnd ptr.
  1196. for( i=0; i< TACH_SEST_LEN; i++)
  1197. {
  1198. if( Exchanges->fcExchange[i].Cmnd == Cmnd )
  1199. {
  1200. // found it!
  1201. printk(" x_ID %Xh, type %Xh\n", i, Exchanges->fcExchange[i].type);
  1202. Exchanges->fcExchange[i].status = INITIATOR_ABORT; // seconds default
  1203. Exchanges->fcExchange[i].timeOut = 10; // seconds default (changed later)
  1204. // Since we need to immediately return the aborted Cmnd to Scsi
  1205. // upper layers, we can't make future reference to any of its
  1206. // fields (e.g the Nexus).
  1207. cpqfcTSPutLinkQue( cpqfcHBAdata, BLS_ABTS, &i);
  1208. break;
  1209. }
  1210. }
  1211. if( i >= TACH_SEST_LEN ) // didn't find Cmnd ptr in chip's SEST?
  1212. {
  1213. // now search our non-SEST buffers (i.e. Cmnd waiting to
  1214. // start on the HBA or waiting to complete with error for retry).
  1215. // first check BadTargetCmnd
  1216. for( i=0; i< CPQFCTS_MAX_TARGET_ID; i++)
  1217. {
  1218. if( cpqfcHBAdata->BadTargetCmnd[i] == Cmnd )
  1219. {
  1220. cpqfcHBAdata->BadTargetCmnd[i] = NULL;
  1221. printk("in BadTargetCmnd Q\n");
  1222. goto Done; // exit
  1223. }
  1224. }
  1225. // if not found above...
  1226. for( i=0; i < CPQFCTS_REQ_QUEUE_LEN; i++)
  1227. {
  1228. if( cpqfcHBAdata->LinkDnCmnd[i] == Cmnd )
  1229. {
  1230. cpqfcHBAdata->LinkDnCmnd[i] = NULL;
  1231. printk("in LinkDnCmnd Q\n");
  1232. goto Done;
  1233. }
  1234. }
  1235. for( i=0; i< CPQFCTS_REQ_QUEUE_LEN; i++)
  1236. { // find spare slot
  1237. if( cpqfcHBAdata->BoardLockCmnd[i] == Cmnd )
  1238. {
  1239. cpqfcHBAdata->BoardLockCmnd[i] = NULL;
  1240. printk("in BoardLockCmnd Q\n");
  1241. goto Done;
  1242. }
  1243. }
  1244. Cmnd->result = DID_ERROR <<16; // Hmmm...
  1245. printk("Not found! ");
  1246. // panic("_abort");
  1247. }
  1248. Done:
  1249. // panic("_abort");
  1250. LEAVE("cpqfcTS_eh_abort");
  1251. return 0; // (see scsi.h)
  1252. }
  1253. // FCP-SCSI Target Device Reset
  1254. // See dpANS Fibre Channel Protocol for SCSI
  1255. // X3.269-199X revision 12, pg 25
  1256. #ifdef SUPPORT_RESET
  1257. int cpqfcTS_TargetDeviceReset( Scsi_Device *ScsiDev,
  1258. unsigned int reset_flags)
  1259. {
  1260. int timeout = 10*HZ;
  1261. int retries = 1;
  1262. char scsi_cdb[12];
  1263. int result;
  1264. Scsi_Cmnd * SCpnt;
  1265. Scsi_Device * SDpnt;
  1266. // FIXME, cpqfcTS_TargetDeviceReset needs to be fixed
  1267. // similarly to how the passthrough ioctl was fixed
  1268. // around the 2.5.30 kernel. Scsi_Cmnd replaced with
  1269. // Scsi_Request, etc.
  1270. // For now, so people don't fall into a hole...
  1271. // printk(" ENTERING cpqfcTS_TargetDeviceReset() - flag=%d \n",reset_flags);
  1272. if (ScsiDev->host->eh_active) return FAILED;
  1273. memset( scsi_cdb, 0, sizeof( scsi_cdb));
  1274. scsi_cdb[0] = RELEASE;
  1275. SCpnt = scsi_get_command(ScsiDev, GFP_KERNEL);
  1276. {
  1277. CPQFC_DECLARE_COMPLETION(wait);
  1278. SCpnt->SCp.buffers_residual = FCP_TARGET_RESET;
  1279. // FIXME: this would panic, SCpnt->request would be NULL.
  1280. SCpnt->request->CPQFC_WAITING = &wait;
  1281. scsi_do_cmd(SCpnt, scsi_cdb, NULL, 0, my_ioctl_done, timeout, retries);
  1282. CPQFC_WAIT_FOR_COMPLETION(&wait);
  1283. SCpnt->request->CPQFC_WAITING = NULL;
  1284. }
  1285. if(driver_byte(SCpnt->result) != 0)
  1286. switch(SCpnt->sense_buffer[2] & 0xf) {
  1287. case ILLEGAL_REQUEST:
  1288. if(cmd[0] == ALLOW_MEDIUM_REMOVAL) dev->lockable = 0;
  1289. else printk("SCSI device (ioctl) reports ILLEGAL REQUEST.\n");
  1290. break;
  1291. case NOT_READY: // This happens if there is no disc in drive
  1292. if(dev->removable && (cmd[0] != TEST_UNIT_READY)){
  1293. printk(KERN_INFO "Device not ready. Make sure there is a disc in the drive.\n");
  1294. break;
  1295. }
  1296. case UNIT_ATTENTION:
  1297. if (dev->removable){
  1298. dev->changed = 1;
  1299. SCpnt->result = 0; // This is no longer considered an error
  1300. // gag this error, VFS will log it anyway /axboe
  1301. // printk(KERN_INFO "Disc change detected.\n");
  1302. break;
  1303. };
  1304. default: // Fall through for non-removable media
  1305. printk("SCSI error: host %d id %d lun %d return code = %x\n",
  1306. dev->host->host_no,
  1307. dev->id,
  1308. dev->lun,
  1309. SCpnt->result);
  1310. printk("\tSense class %x, sense error %x, extended sense %x\n",
  1311. sense_class(SCpnt->sense_buffer[0]),
  1312. sense_error(SCpnt->sense_buffer[0]),
  1313. SCpnt->sense_buffer[2] & 0xf);
  1314. };
  1315. result = SCpnt->result;
  1316. SDpnt = SCpnt->device;
  1317. scsi_put_command(SCpnt);
  1318. SCpnt = NULL;
  1319. // printk(" LEAVING cpqfcTS_TargetDeviceReset() - return SUCCESS \n");
  1320. return SUCCESS;
  1321. }
  1322. #else
  1323. int cpqfcTS_TargetDeviceReset( Scsi_Device *ScsiDev,
  1324. unsigned int reset_flags)
  1325. {
  1326. return -ENOTSUPP;
  1327. }
  1328. #endif /* SUPPORT_RESET */
  1329. int cpqfcTS_eh_device_reset(Scsi_Cmnd *Cmnd)
  1330. {
  1331. int retval;
  1332. Scsi_Device *SDpnt = Cmnd->device;
  1333. // printk(" ENTERING cpqfcTS_eh_device_reset() \n");
  1334. spin_unlock_irq(Cmnd->device->host->host_lock);
  1335. retval = cpqfcTS_TargetDeviceReset( SDpnt, 0);
  1336. spin_lock_irq(Cmnd->device->host->host_lock);
  1337. return retval;
  1338. }
  1339. int cpqfcTS_reset(Scsi_Cmnd *Cmnd, unsigned int reset_flags)
  1340. {
  1341. ENTER("cpqfcTS_reset");
  1342. LEAVE("cpqfcTS_reset");
  1343. return SCSI_RESET_ERROR; /* Bus Reset Not supported */
  1344. }
  1345. /* This function determines the bios parameters for a given
  1346. harddisk. These tend to be numbers that are made up by the
  1347. host adapter. Parameters:
  1348. size, device number, list (heads, sectors,cylinders).
  1349. (from hosts.h)
  1350. */
  1351. int cpqfcTS_biosparam(struct scsi_device *sdev, struct block_device *n,
  1352. sector_t capacity, int ip[])
  1353. {
  1354. int size = capacity;
  1355. ENTER("cpqfcTS_biosparam");
  1356. ip[0] = 64;
  1357. ip[1] = 32;
  1358. ip[2] = size >> 11;
  1359. if( ip[2] > 1024 )
  1360. {
  1361. ip[0] = 255;
  1362. ip[1] = 63;
  1363. ip[2] = size / (ip[0] * ip[1]);
  1364. }
  1365. LEAVE("cpqfcTS_biosparam");
  1366. return 0;
  1367. }
  1368. irqreturn_t cpqfcTS_intr_handler( int irq,
  1369. void *dev_id,
  1370. struct pt_regs *regs)
  1371. {
  1372. unsigned long flags, InfLoopBrk=0;
  1373. struct Scsi_Host *HostAdapter = dev_id;
  1374. CPQFCHBA *cpqfcHBA = (CPQFCHBA *)HostAdapter->hostdata;
  1375. int MoreMessages = 1; // assume we have something to do
  1376. UCHAR IntPending;
  1377. int handled = 0;
  1378. ENTER("intr_handler");
  1379. spin_lock_irqsave( HostAdapter->host_lock, flags);
  1380. // is this our INT?
  1381. IntPending = readb( cpqfcHBA->fcChip.Registers.INTPEND.address);
  1382. // broken boards can generate messages forever, so
  1383. // prevent the infinite loop
  1384. #define INFINITE_IMQ_BREAK 10000
  1385. if( IntPending )
  1386. {
  1387. handled = 1;
  1388. // mask our HBA interrupts until we handle it...
  1389. writeb( 0, cpqfcHBA->fcChip.Registers.INTEN.address);
  1390. if( IntPending & 0x4) // "INT" - Tach wrote to IMQ
  1391. {
  1392. while( (++InfLoopBrk < INFINITE_IMQ_BREAK) && (MoreMessages ==1) )
  1393. {
  1394. MoreMessages = CpqTsProcessIMQEntry( HostAdapter); // ret 0 when done
  1395. }
  1396. if( InfLoopBrk >= INFINITE_IMQ_BREAK )
  1397. {
  1398. printk("WARNING: Compaq FC adapter generating excessive INTs -REPLACE\n");
  1399. printk("or investigate alternate causes (e.g. physical FC layer)\n");
  1400. }
  1401. else // working normally - re-enable INTs and continue
  1402. writeb( 0x1F, cpqfcHBA->fcChip.Registers.INTEN.address);
  1403. } // (...ProcessIMQEntry() clears INT by writing IMQ consumer)
  1404. else // indications of errors or problems...
  1405. // these usually indicate critical system hardware problems.
  1406. {
  1407. if( IntPending & 0x10 )
  1408. printk(" cpqfcTS adapter external memory parity error detected\n");
  1409. if( IntPending & 0x8 )
  1410. printk(" cpqfcTS adapter PCI master address crossed 45-bit boundary\n");
  1411. if( IntPending & 0x2 )
  1412. printk(" cpqfcTS adapter DMA error detected\n");
  1413. if( IntPending & 0x1 ) {
  1414. UCHAR IntStat;
  1415. printk(" cpqfcTS adapter PCI error detected\n");
  1416. IntStat = readb( cpqfcHBA->fcChip.Registers.INTSTAT.address);
  1417. printk("cpqfc: ISR = 0x%02x\n", IntStat);
  1418. if (IntStat & 0x1) {
  1419. __u16 pcistat;
  1420. /* read the pci status register */
  1421. pci_read_config_word(cpqfcHBA->PciDev, 0x06, &pcistat);
  1422. printk("PCI status register is 0x%04x\n", pcistat);
  1423. if (pcistat & 0x8000) printk("Parity Error Detected.\n");
  1424. if (pcistat & 0x4000) printk("Signalled System Error\n");
  1425. if (pcistat & 0x2000) printk("Received Master Abort\n");
  1426. if (pcistat & 0x1000) printk("Received Target Abort\n");
  1427. if (pcistat & 0x0800) printk("Signalled Target Abort\n");
  1428. }
  1429. if (IntStat & 0x4) printk("(INT)\n");
  1430. if (IntStat & 0x8)
  1431. printk("CRS: PCI master address crossed 46 bit bouandary\n");
  1432. if (IntStat & 0x10) printk("MRE: external memory parity error.\n");
  1433. }
  1434. }
  1435. }
  1436. spin_unlock_irqrestore( HostAdapter->host_lock, flags);
  1437. LEAVE("intr_handler");
  1438. return IRQ_RETVAL(handled);
  1439. }
  1440. int cpqfcTSDecodeGBICtype( PTACHYON fcChip, char cErrorString[])
  1441. {
  1442. // Verify GBIC type (if any) and correct Tachyon Port State Machine
  1443. // (GBIC) module definition is:
  1444. // GPIO1, GPIO0, GPIO4 for MD2, MD1, MD0. The input states appear
  1445. // to be inverted -- i.e., a setting of 111 is read when there is NO
  1446. // GBIC present. The Module Def (MD) spec says 000 is "no GBIC"
  1447. // Hard code the bit states to detect Copper,
  1448. // Long wave (single mode), Short wave (multi-mode), and absent GBIC
  1449. ULONG ulBuff;
  1450. sprintf( cErrorString, "\nGBIC detected: ");
  1451. ulBuff = fcChip->Registers.TYstatus.value & 0x13;
  1452. switch( ulBuff )
  1453. {
  1454. case 0x13: // GPIO4, GPIO1, GPIO0 = 111; no GBIC!
  1455. sprintf( &cErrorString[ strlen( cErrorString)],
  1456. "NONE! ");
  1457. return FALSE;
  1458. case 0x11: // Copper GBIC detected
  1459. sprintf( &cErrorString[ strlen( cErrorString)],
  1460. "Copper. ");
  1461. break;
  1462. case 0x10: // Long-wave (single mode) GBIC detected
  1463. sprintf( &cErrorString[ strlen( cErrorString)],
  1464. "Long-wave. ");
  1465. break;
  1466. case 0x1: // Short-wave (multi mode) GBIC detected
  1467. sprintf( &cErrorString[ strlen( cErrorString)],
  1468. "Short-wave. ");
  1469. break;
  1470. default: // unknown GBIC - presumably it will work (?)
  1471. sprintf( &cErrorString[ strlen( cErrorString)],
  1472. "Unknown. ");
  1473. break;
  1474. } // end switch GBIC detection
  1475. return TRUE;
  1476. }
  1477. int cpqfcTSGetLPSM( PTACHYON fcChip, char cErrorString[])
  1478. {
  1479. // Tachyon's Frame Manager LPSM in LinkDown state?
  1480. // (For non-loop port, check PSM instead.)
  1481. // return string with state and FALSE is Link Down
  1482. int LinkUp;
  1483. if( fcChip->Registers.FMstatus.value & 0x80 )
  1484. LinkUp = FALSE;
  1485. else
  1486. LinkUp = TRUE;
  1487. sprintf( &cErrorString[ strlen( cErrorString)],
  1488. " LPSM %Xh ",
  1489. (fcChip->Registers.FMstatus.value >>4) & 0xf );
  1490. switch( fcChip->Registers.FMstatus.value & 0xF0)
  1491. {
  1492. // bits set in LPSM
  1493. case 0x10:
  1494. sprintf( &cErrorString[ strlen( cErrorString)], "ARB");
  1495. break;
  1496. case 0x20:
  1497. sprintf( &cErrorString[ strlen( cErrorString)], "ARBwon");
  1498. break;
  1499. case 0x30:
  1500. sprintf( &cErrorString[ strlen( cErrorString)], "OPEN");
  1501. break;
  1502. case 0x40:
  1503. sprintf( &cErrorString[ strlen( cErrorString)], "OPENed");
  1504. break;
  1505. case 0x50:
  1506. sprintf( &cErrorString[ strlen( cErrorString)], "XmitCLS");
  1507. break;
  1508. case 0x60:
  1509. sprintf( &cErrorString[ strlen( cErrorString)], "RxCLS");
  1510. break;
  1511. case 0x70:
  1512. sprintf( &cErrorString[ strlen( cErrorString)], "Xfer");
  1513. break;
  1514. case 0x80:
  1515. sprintf( &cErrorString[ strlen( cErrorString)], "Init");
  1516. break;
  1517. case 0x90:
  1518. sprintf( &cErrorString[ strlen( cErrorString)], "O-IInitFin");
  1519. break;
  1520. case 0xa0:
  1521. sprintf( &cErrorString[ strlen( cErrorString)], "O-IProtocol");
  1522. break;
  1523. case 0xb0:
  1524. sprintf( &cErrorString[ strlen( cErrorString)], "O-ILipRcvd");
  1525. break;
  1526. case 0xc0:
  1527. sprintf( &cErrorString[ strlen( cErrorString)], "HostControl");
  1528. break;
  1529. case 0xd0:
  1530. sprintf( &cErrorString[ strlen( cErrorString)], "LoopFail");
  1531. break;
  1532. case 0xe0:
  1533. sprintf( &cErrorString[ strlen( cErrorString)], "Offline");
  1534. break;
  1535. case 0xf0:
  1536. sprintf( &cErrorString[ strlen( cErrorString)], "OldPort");
  1537. break;
  1538. case 0:
  1539. default:
  1540. sprintf( &cErrorString[ strlen( cErrorString)], "Monitor");
  1541. break;
  1542. }
  1543. return LinkUp;
  1544. }
  1545. #include "linux/slab.h"
  1546. // Dynamic memory allocation alignment routines
  1547. // HP's Tachyon Fibre Channel Controller chips require
  1548. // certain memory queues and register pointers to be aligned
  1549. // on various boundaries, usually the size of the Queue in question.
  1550. // Alignment might be on 2, 4, 8, ... or even 512 byte boundaries.
  1551. // Since most O/Ss don't allow this (usually only Cache aligned -
  1552. // 32-byte boundary), these routines provide generic alignment (after
  1553. // O/S allocation) at any boundary, and store the original allocated
  1554. // pointer for deletion (O/S free function). Typically, we expect
  1555. // these functions to only be called at HBA initialization and
  1556. // removal time (load and unload times)
  1557. // ALGORITHM notes:
  1558. // Memory allocation varies by compiler and platform. In the worst case,
  1559. // we are only assured BYTE alignment, but in the best case, we can
  1560. // request allocation on any desired boundary. Our strategy: pad the
  1561. // allocation request size (i.e. waste memory) so that we are assured
  1562. // of passing desired boundary near beginning of contiguous space, then
  1563. // mask out lower address bits.
  1564. // We define the following algorithm:
  1565. // allocBoundary - compiler/platform specific address alignment
  1566. // in number of bytes (default is single byte; i.e. 1)
  1567. // n_alloc - number of bytes application wants @ aligned address
  1568. // ab - alignment boundary, in bytes (e.g. 4, 32, ...)
  1569. // t_alloc - total allocation needed to ensure desired boundary
  1570. // mask - to clear least significant address bits for boundary
  1571. // Compute:
  1572. // t_alloc = n_alloc + (ab - allocBoundary)
  1573. // allocate t_alloc bytes @ alloc_address
  1574. // mask = NOT (ab - 1)
  1575. // (e.g. if ab=32 _0001 1111 -> _1110 0000
  1576. // aligned_address = alloc_address & mask
  1577. // set n_alloc bytes to 0
  1578. // return aligned_address (NULL if failed)
  1579. //
  1580. // If u32_AlignedAddress is non-zero, then search for BaseAddress (stored
  1581. // from previous allocation). If found, invoke call to FREE the memory.
  1582. // Return NULL if BaseAddress not found
  1583. // we need about 8 allocations per HBA. Figuring at most 10 HBAs per server
  1584. // size the dynamic_mem array at 80.
  1585. void* fcMemManager( struct pci_dev *pdev, ALIGNED_MEM *dynamic_mem,
  1586. ULONG n_alloc, ULONG ab, ULONG u32_AlignedAddress,
  1587. dma_addr_t *dma_handle)
  1588. {
  1589. USHORT allocBoundary=1; // compiler specific - worst case 1
  1590. // best case - replace malloc() call
  1591. // with function that allocates exactly
  1592. // at desired boundary
  1593. unsigned long ulAddress;
  1594. ULONG t_alloc, i;
  1595. void *alloc_address = 0; // def. error code / address not found
  1596. LONG mask; // must be 32-bits wide!
  1597. ENTER("fcMemManager");
  1598. if( u32_AlignedAddress ) // are we freeing existing memory?
  1599. {
  1600. // printk(" freeing AlignedAddress %Xh\n", u32_AlignedAddress);
  1601. for( i=0; i<DYNAMIC_ALLOCATIONS; i++) // look for the base address
  1602. {
  1603. // printk("dynamic_mem[%u].AlignedAddress %lX\n", i, dynamic_mem[i].AlignedAddress);
  1604. if( dynamic_mem[i].AlignedAddress == u32_AlignedAddress )
  1605. {
  1606. alloc_address = dynamic_mem[i].BaseAllocated; // 'success' status
  1607. pci_free_consistent(pdev,dynamic_mem[i].size,
  1608. alloc_address,
  1609. dynamic_mem[i].dma_handle);
  1610. dynamic_mem[i].BaseAllocated = 0; // clear for next use
  1611. dynamic_mem[i].AlignedAddress = 0;
  1612. dynamic_mem[i].size = 0;
  1613. break; // quit for loop; done
  1614. }
  1615. }
  1616. }
  1617. else if( n_alloc ) // want new memory?
  1618. {
  1619. dma_addr_t handle;
  1620. t_alloc = n_alloc + (ab - allocBoundary); // pad bytes for alignment
  1621. // printk("pci_alloc_consistent() for Tach alignment: %ld bytes\n", t_alloc);
  1622. // (would like to) allow thread block to free pages
  1623. alloc_address = // total bytes (NumberOfBytes)
  1624. pci_alloc_consistent(pdev, t_alloc, &handle);
  1625. // now mask off least sig. bits of address
  1626. if( alloc_address ) // (only if non-NULL)
  1627. {
  1628. // find place to store ptr, so we
  1629. // can free it later...
  1630. mask = (LONG)(ab - 1); // mask all low-order bits
  1631. mask = ~mask; // invert bits
  1632. for( i=0; i<DYNAMIC_ALLOCATIONS; i++) // look for free slot
  1633. {
  1634. if( dynamic_mem[i].BaseAllocated == 0) // take 1st available
  1635. {
  1636. dynamic_mem[i].BaseAllocated = alloc_address;// address from O/S
  1637. dynamic_mem[i].dma_handle = handle;
  1638. if (dma_handle != NULL)
  1639. {
  1640. // printk("handle = %p, ab=%d, boundary = %d, mask=0x%08x\n",
  1641. // handle, ab, allocBoundary, mask);
  1642. *dma_handle = (dma_addr_t)
  1643. ((((ULONG)handle) + (ab - allocBoundary)) & mask);
  1644. }
  1645. dynamic_mem[i].size = t_alloc;
  1646. break;
  1647. }
  1648. }
  1649. ulAddress = (unsigned long)alloc_address;
  1650. ulAddress += (ab - allocBoundary); // add the alignment bytes-
  1651. // then truncate address...
  1652. alloc_address = (void*)(ulAddress & mask);
  1653. dynamic_mem[i].AlignedAddress =
  1654. (ULONG)(ulAddress & mask); // 32bit Tach address
  1655. memset( alloc_address, 0, n_alloc ); // clear new memory
  1656. }
  1657. else // O/S dynamic mem alloc failed!
  1658. alloc_address = 0; // (for debugging breakpt)
  1659. }
  1660. LEAVE("fcMemManager");
  1661. return alloc_address; // good (or NULL) address
  1662. }
  1663. static Scsi_Host_Template driver_template = {
  1664. .detect = cpqfcTS_detect,
  1665. .release = cpqfcTS_release,
  1666. .info = cpqfcTS_info,
  1667. .proc_info = cpqfcTS_proc_info,
  1668. .ioctl = cpqfcTS_ioctl,
  1669. .queuecommand = cpqfcTS_queuecommand,
  1670. .eh_device_reset_handler = cpqfcTS_eh_device_reset,
  1671. .eh_abort_handler = cpqfcTS_eh_abort,
  1672. .bios_param = cpqfcTS_biosparam,
  1673. .can_queue = CPQFCTS_REQ_QUEUE_LEN,
  1674. .this_id = -1,
  1675. .sg_tablesize = SG_ALL,
  1676. .cmd_per_lun = CPQFCTS_CMD_PER_LUN,
  1677. .use_clustering = ENABLE_CLUSTERING,
  1678. };
  1679. #include "scsi_module.c"