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