cpqfcTSstructs.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:46k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* Copyright(c) 2000, Compaq Computer Corporation
  2.  * Fibre Channel Host Bus Adapter 64-bit, 66MHz PCI 
  3.  * Originally developed and tested on:
  4.  * (front): [chip] Tachyon TS HPFC-5166A/1.2  L2C1090 ...
  5.  *          SP# P225CXCBFIEL6T, Rev XC
  6.  *          SP# 161290-001, Rev XD
  7.  * (back): Board No. 010008-001 A/W Rev X5, FAB REV X5
  8.  *  
  9.  * This program is free software; you can redistribute it and/or modify it
  10.  * under the terms of the GNU General Public License as published by the
  11.  * Free Software Foundation; either version 2, or (at your option) any
  12.  * later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful, but
  15.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.  * General Public License for more details.
  18.  * Written by Don Zimmerman
  19. */
  20. #ifndef CPQFCTSSTRUCTS_H
  21. #define CPQFCTSSTRUCTS_H
  22. #include <linux/timer.h>  // timer declaration in our host data
  23. #include <linux/tqueue.h> // task queue sched
  24. #include <asm/atomic.h>
  25. #include "cpqfcTSioctl.h"
  26. #define DbgDelay(secs) { int wait_time; printk( " DbgDelay %ds ", secs); 
  27.                          for( wait_time=jiffies + (secs*HZ); 
  28.          time_before(jiffies, wait_time) ;) ; }
  29. #define CPQFCTS_DRIVER_VER(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
  30. // don't forget to also change MODULE_DESCRIPTION in cpqfcTSinit.c
  31. #define VER_MAJOR 2
  32. #define VER_MINOR 1
  33. #define VER_SUBMINOR 1
  34. // Macros for kernel (esp. SMP) tracing using a PCI analyzer
  35. // (e.g. x86).
  36. //#define PCI_KERNEL_TRACE
  37. #ifdef PCI_KERNEL_TRACE
  38. #define PCI_TRACE(x) inl( fcChip->Registers.IOBaseL +x);
  39. #define PCI_TRACEO(x,y) outl( x, (fcChip->Registers.IOBaseL +y));
  40. #else
  41. #define PCI_TRACE(x) 
  42. #define PCI_TRACEO(x,y)
  43. #endif
  44.  
  45. //#define DEBUG_CMND 1   // debug output for Linux Scsi CDBs
  46. //#define DUMMYCMND_DBG 1
  47. //#define DEBUG_CPQFCTS 1
  48. //#undef DEBUG_CPQFCTS 
  49. #ifdef DEBUG_CPQFCTS
  50. #define ENTER(x) printk("cpqfcts : entering %s()n", x);
  51. #define LEAVE(x) printk("cpqfcts : leaving %s()n", x);
  52. #define DEBUG(x) x
  53. #else
  54. #define ENTER(x)
  55. #define LEAVE(x)
  56. #define DEBUG(x)
  57. #endif /* DEBUG_CPQFCTS */
  58. //#define DEBUG_CPQFCTS_PCI 1
  59. //#undef DEBUG_CPQFCTS_PCI
  60. #if DEBUG_CPQFCTS_PCI
  61. #define DEBUG_PCI(x) x
  62. #else
  63. #define DEBUG_PCI(x)
  64. #endif /* DEBUG_CPQFCTS_PCI */
  65. #define STACHLITE66_TS12  "Compaq FibreChannel HBA Tachyon TS HPFC-5166A/1.2"
  66. #define STACHLITE66_TS13  "Compaq FibreChannel HBA Tachyon TS HPFC-5166A/1.3"
  67. #define STACHLITE_UNKNOWN "Compaq FibreChannel HBA Tachyon Chip/Board Ver??"
  68. #define SAGILENT_XL2_21   "Agilent FC HBA, Tachyon XL2 HPFC-5200B/2.1"
  69. // PDA is Peripheral Device Address, VSA is Volume Set Addressing
  70. // Linux SCSI parameters
  71. #define CPQFCTS_MAX_TARGET_ID 64
  72. // Note, changing CPQFCTS_MAX_LUN to less than 32 (e.g, 8) will result in
  73. // strange behavior if a box with more than, e.g. 8, is on the loop.
  74. #define CPQFCTS_MAX_LUN 32    // The RA-4x00 supports 32 (Linux SCSI supports 8)
  75. #define CPQFCTS_MAX_CHANNEL 0 // One FC port on cpqfcTS HBA
  76. #define CPQFCTS_CMD_PER_LUN 15 // power of 2 -1, must be >0 
  77. #define CPQFCTS_REQ_QUEUE_LEN (TACH_SEST_LEN/2) // must be < TACH_SEST_LEN
  78. #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
  79. #ifndef DECLARE_MUTEX_LOCKED
  80. #define DECLARE_MUTEX_LOCKED(sem) struct semaphore sem = MUTEX_LOCKED
  81. #endif
  82. #define DEV_NAME "cpqfcTS"
  83. struct SupportedPCIcards
  84. {
  85.   __u16 vendor_id;
  86.   __u16 device_id;
  87. };
  88.  
  89. // nn:nn denotes bit field
  90.                             // TachyonHeader struct def.
  91.                             // the fields shared with ODB
  92.                             // need to have same value
  93. #ifndef BYTE
  94. //typedef UCHAR BYTE;
  95. typedef __u8 BYTE;
  96. #endif
  97. #ifndef UCHAR
  98. typedef __u8 UCHAR;
  99. #endif
  100. #ifndef LONG
  101. typedef __s32 LONG;
  102. #endif
  103. #ifndef ULONG
  104. typedef __u32 ULONG;
  105. #endif
  106. #ifndef PVOID
  107. typedef void * PVOID;
  108. #endif
  109. #ifndef USHORT
  110. typedef __u16 USHORT;
  111. #endif
  112. #ifndef BOOLEAN
  113. typedef __u8 BOOLEAN;
  114. #endif
  115. // macro for FC-PH reject codes
  116. // payload format for LS_RJT (FC payloads are big endian):
  117. //     byte  0         1         2         3  (MSB)
  118. // DWORD 0   01        00        00        00
  119. // DWORD 1   resvd     code      expl.     vendor
  120. #define LS_RJT_REASON( code, expl) (( code<<8) | (expl <<16))
  121. #define TachLiteSTATUS 0x12
  122. // Fibre Channel EXCHANGE status codes for Tachyon chips/ driver software
  123. // 32-bit ERROR word defines
  124. #define INVALID_ARGS 0x1
  125. #define LNKDWN_OSLS  0x2
  126. #define LNKDWN_LASER 0x4
  127. #define OUTQUE_FULL  0x8
  128. #define DRIVERQ_FULL 0x10
  129. #define SEST_FULL    0x20
  130. #define BAD_ALPA     0x40
  131. #define OVERFLOW     0x80  // inbound CM
  132. #define COUNT_ERROR     0x100  // inbound CM
  133. #define LINKFAIL_RX     0x200  // inbound CM
  134. #define ABORTSEQ_NOTIFY 0x400  // outbound CM
  135. #define LINKFAIL_TX     0x800  // outbound CM
  136. #define HOSTPROG_ERR     0x1000  // outbound CM
  137. #define FRAME_TO         0x2000  // outbound CM
  138. #define INV_ENTRY        0x4000  // outbound CM
  139. #define SESTPROG_ERR     0x8000  // outbound CM
  140. #define OUTBOUND_TIMEOUT 0x10000L // timeout waiting for Tachyon outbound CM
  141. #define INITIATOR_ABORT  0x20000L // initiator exchange timeout or O/S ABORT
  142. #define MEMPOOL_FAIL     0x40000L // O/S memory pool allocation failed
  143. #define FC2_TIMEOUT      0x80000L // driver timeout for lost frames
  144. #define TARGET_ABORT     0x100000L // ABTS received from FC port
  145. #define EXCHANGE_QUEUED  0x200000L // e.g. Link State was LDn on fcStart
  146. #define PORTID_CHANGED   0x400000L // fc Port address changed
  147. #define DEVICE_REMOVED   0x800000L // fc Port address changed
  148. // Several error scenarios result in SEST Exchange frames 
  149. // unexpectedly arriving in the SFQ
  150. #define SFQ_FRAME        0x1000000L // SFQ frames from open Exchange
  151. // Maximum number of Host Bus Adapters (HBA) / controllers supported
  152. // only important for mem allocation dimensions - increase as necessary
  153. #define MAX_ADAPTERS 8
  154. #define MAX_RX_PAYLOAD 1024  // hardware dependent max frame payload
  155. // Tach header struc defines
  156. #define SOFi3 0x7
  157. #define SOFf  0x8
  158. #define SOFn3 0xB
  159. #define EOFn  0x5
  160. #define EOFt  0x6
  161. // FCP R_CTL defines
  162. #define FCP_CMND 0x6
  163. #define FCP_XFER_RDY 0x5
  164. #define FCP_RSP 0x7
  165. #define FCP_RESPONSE 0x777 // (arbitrary #)
  166. #define NEED_FCP_RSP 0x77  // (arbitrary #)
  167. #define FCP_DATA 0x1
  168. #define RESET_TACH 0x100 // Reset Tachyon/TachLite
  169. #define SCSI_IWE 0x2000  // initiator write entry (for SEST)
  170. #define SCSI_IRE 0x3000  // initiator read entry (for SEST)
  171. #define SCSI_TRE 0x400  // target read entry (for SEST)
  172. #define SCSI_TWE 0x500  // target write entry (for SEST)
  173. #define TOGGLE_LASER 0x800
  174. #define LIP 0x900
  175. #define CLEAR_FCPORTS 99 // (arbitrary #) free mem for Logged in ports
  176. #define FMINIT 0x707     // (arbitrary) for Frame Manager Init command
  177. // BLS == Basic Link Service
  178. // ELS == Extended Link Service
  179. #define BLS_NOP 4
  180. #define BLS_ABTS 0x10   // FC-PH Basic Link Service Abort Sequence
  181. #define BLS_ABTS_ACC 0x100  // FC-PH Basic Link Service Abort Sequence Accept
  182. #define BLS_ABTS_RJT 0x101  // FC-PH Basic Link Service Abort Sequence Reject
  183. #define ELS_PLOGI 0x03  // FC-PH Port Login (arbitrary assign)
  184. #define ELS_SCR   0x70  // (arb assign) State Change Registration (Fabric)
  185. #define FCS_NSR   0x72  // (arb assign) Name Service Request (Fabric)
  186. #define ELS_FLOGI 0x44  // (arb assign) Fabric Login
  187. #define ELS_FDISC 0x41  // (arb assign) Fabric Discovery (Login)
  188. #define ELS_PDISC 0x50  // FC-PH2 Port Discovery
  189. #define ELS_ABTX  0x06  // FC-PH Abort Exchange 
  190. #define ELS_LOGO 0x05   // FC-PH Port Logout
  191. #define ELS_PRLI 0x20   // FCP-SCSI Process Login
  192. #define ELS_PRLO 0x21   // FCP-SCSI Process Logout
  193. #define ELS_LOGO_ACC 0x07   // {FC-PH} Port Logout Accept
  194. #define ELS_PLOGI_ACC 0x08  // {FC-PH} Port Login Accept
  195. #define ELS_ACC 0x18        // {FC-PH} (generic) ACCept
  196. #define ELS_PRLI_ACC 0x22  // {FCP-SCSI} Process Login Accept
  197. #define ELS_RJT 0x1000000
  198. #define SCSI_REPORT_LUNS 0x0A0
  199. #define REPORT_LUNS 0xA0 // SCSI-3 command op-code
  200. #define FCP_TARGET_RESET 0x200
  201. #define ELS_LILP_FRAME 0x00000711 // 1st payload word of LILP frame
  202. #define SFQ_UNASSISTED_FCP  1  // ICM, DWord3, "Type" unassisted FCP
  203. #define SFQ_UNKNOWN         0x31 // (arbitrary) ICM, DWord3, "Type" unknown
  204. // these "LINK" bits refer to loop or non-loop
  205. #define LINKACTIVE 0x2    // fcLinkQ type - LINK UP Tachyon FM 'Lup' bit set
  206. #define LINKDOWN 0xf2     // fcLinkQ type - LINK DOWN Tachyon FM 'Ldn' bit set
  207. //#define VOLUME_SET_ADDRESSING 1 // "channel" or "bus" 1
  208. typedef struct      // 32 bytes hdr ONLY (e.g. FCP_DATA buffer for SEST)
  209. {
  210.   ULONG reserved;   // dword 0 (don't use)
  211.   ULONG sof_eof;
  212.   ULONG d_id;       // dword 2 - 31:24 R_CTL, 23:0 D_ID
  213.   ULONG s_id;       // dword 3 - 31:24 CS_CTL, 23:0 S_ID
  214.   ULONG f_ctl;      // dword 4 - 31:24 Type,  23:0 F_CTL
  215.   ULONG seq_cnt;    // dword 5 - 31:24 SEQ_ID, 23:16 DF_CTL, 15:0 SEQ_CNT
  216.   ULONG ox_rx_id;   // dword 6 - 31:16 OX_ID,  15:0 RX_ID
  217.   ULONG ro;         // dword 7 - relative offset
  218. } TachFCHDR;
  219.                     // NOTE!! the following struct MUST be 64 bytes.
  220. typedef struct      // 32 bytes hdr + 32 bytes payload
  221. {
  222.   ULONG reserved;   // dword 0 (don't use - must clear to 0)
  223.   ULONG sof_eof;    // dword 1 - 31:24 SOF:EOF, UAM,CLS, LCr, TFV, TimeStamp
  224.   ULONG d_id;       // dword 2 - 31:24 R_CTL, 23:0 D_ID
  225.   ULONG s_id;       // dword 3 - 31:24 CS_CTL, 23:0 S_ID
  226.   ULONG f_ctl;      // dword 4 - 31:24 Type,  23:0 F_CTL
  227.   ULONG seq_cnt;    // dword 5 - 31:24 SEQ_ID, 23:16 DF_CTL, 15:0 SEQ_CNT
  228.   ULONG ox_rx_id;   // dword 6 - 31:16 OX_ID,  15:0 RX_ID
  229.   ULONG ro;  // dword 7 - relative offset
  230. //---------
  231.   __u32 pl[8];              // dwords 8-15 frame data payload
  232. } TachFCHDR_CMND;
  233. typedef struct      // 32 bytes hdr + 120 bytes payload
  234. {
  235.   ULONG reserved;   // dword 0 (don't use - must clear to 0)
  236.   ULONG sof_eof;    // dword 1 - 31:24 SOF:EOF, UAM,CLS, LCr, TFV, TimeStamp
  237.   ULONG d_id;       // dword 2 - 31:24 R_CTL, 23:0 D_ID
  238.   ULONG s_id;       // dword 3 - 31:24 CS_CTL, 23:0 S_ID
  239.   ULONG f_ctl;      // dword 4 - 31:24 Type,  23:0 F_CTL
  240.   ULONG seq_cnt;    // dword 5 - 31:24 SEQ_ID, 23:16 DF_CTL, 15:0 SEQ_CNT
  241.   ULONG ox_rx_id;   // dword 6 - 31:16 OX_ID,  15:0 RX_ID
  242.   ULONG ro;  // dword 7 - relative offset
  243. //---------
  244.   __u32 pl[30];              // largest necessary payload (for LOGIN cmnds)
  245. } TachFCHDR_GCMND;
  246. typedef struct      // 32 bytes hdr + 64 bytes payload
  247. {
  248.   ULONG reserved;   // dword 0 (don't use)
  249.   ULONG sof_eof;
  250.   ULONG d_id;       // dword 2 - 31:24 R_CTL, 23:0 D_ID
  251.   ULONG s_id;       // dword 3 - 31:24 CS_CTL, 23:0 S_ID
  252.   ULONG f_ctl;      // dword 4 - 31:24 Type,  23:0 F_CTL
  253.   ULONG seq_cnt;    // dword 5 - 31:24 SEQ_ID, 23:16 DF_CTL, 15:0 SEQ_CNT
  254.   ULONG ox_rx_id;   // dword 6 - 31:16 OX_ID,  15:0 RX_ID
  255.   ULONG ro;  // dword 7 - relative offset
  256. //---------
  257.   __u32 pl[18]; // payload for FCP-RSP (response buffer) RA-4x00 is 72bytes
  258. } TachFCHDR_RSP;
  259. // Inbound Message Queue structures...
  260. typedef struct              // each entry 8 words (32 bytes)
  261. {
  262.   ULONG type;               // IMQ completion message types
  263.   ULONG word[7];            // remainder of structure
  264.                             // interpreted by IMQ type
  265. } TachyonIMQE;
  266. // Queues for TachLite not in original Tachyon
  267. // ERQ       - Exchange Request Queue (for outbound commands)
  268. // SFQ       - Single Frame Queue (for incoming frames)
  269.                             // Define Tachyon Outbound Command Que
  270.                             // (Since many Tachyon registers are Read
  271.                             // only, maintain copies for debugging)
  272.                             // most Tach ques need power-of-2 sizes,
  273.                             // where registers are loaded with po2 -1
  274. #define TACH_SEST_LEN 512   // TachLite SEST
  275. #define ELS_EXCHANGES 64    // e.g. PLOGI, RSCN, ...
  276. // define the total number of outstanding (simultaneous) exchanges
  277. #define TACH_MAX_XID (TACH_SEST_LEN + ELS_EXCHANGES)  // ELS exchanges
  278. #define ERQ_LEN 128         // power of 2, max 4096
  279. // Inbound Message Queue structures...
  280. #define IMQ_LEN 512              // minimum 4 entries [(power of 2) - 1]
  281. typedef struct                   // 8 words - 32 bytes
  282. {
  283.   TachyonIMQE QEntry[IMQ_LEN];
  284.   ULONG producerIndex;   // IMQ Producer Index register
  285.                                  // @32 byte align
  286.   ULONG consumerIndex;   // Consumer Index register (in Tachyon)
  287.   ULONG length;          // Length register
  288.   ULONG base;
  289. } TachyonIMQ;                    // @ 32 * IMQ_LEN align
  290. typedef struct           // inbound completion message
  291. {
  292.   ULONG Type;
  293.   ULONG Index;
  294.   ULONG TransferLength;
  295. } TachyonInbCM;
  296. // arbitrary numeric tags for TL structures
  297. #define TL_FCHS 1  // TachLite Fibre Channel Header Structure
  298. #define TL_IWE 2  // initiator write entry (for SEST)
  299. #define TL_TWE 3  // target write entry (for SEST)
  300. #define TL_IRE 4  // initiator read entry (for SEST)
  301. #define TL_TRE 5  // target read entry (for SEST)
  302. #define TL_IRB 6  // I/O request block
  303.                                 // for INCOMING frames
  304. #define SFQ_LEN 32              // minimum 32 entries, max 4096
  305. typedef struct                  // Single Frame Que
  306. {
  307.   TachFCHDR_CMND QEntry[SFQ_LEN]; // must be 64 bytes!!
  308.   ULONG producerIndex;   // IMQ Producer Index register
  309.                                  // @32 byte align
  310.   ULONG consumerIndex;   // Consumer Index register (in Tachyon)
  311.   ULONG length;          // Length register
  312.   ULONG base;
  313. } TachLiteSFQ;
  314. typedef struct                 // I/O Request Block flags
  315. {
  316.   UCHAR  BRD : 1;
  317.   UCHAR      : 1; // reserved
  318.   UCHAR  SFA : 1;
  319.   UCHAR  DNC : 1;
  320.   UCHAR  DIN : 1;
  321.   UCHAR  DCM : 1;
  322.   UCHAR  CTS : 1;
  323.   UCHAR  SBV : 1;  // IRB entry valid - IRB'B' only
  324. } IRBflags;
  325. typedef struct                  // I/O Request Block
  326. {                          // Request 'A'
  327.   ULONG Req_A_SFS_Len;     // total frame len (hdr + payload), min 32
  328.   ULONG Req_A_SFS_Addr;    // 32-bit pointer to FCHS struct (to be sent)
  329.   ULONG Req_A_SFS_D_ID;    // 24-bit FC destination (i.e. 8 bit al_pa)
  330.   ULONG Req_A_Trans_ID;    // X_ID (OX_ID or RX_ID) and/or Index in SEST
  331.                            // Request 'B'
  332.   ULONG Req_B_SFS_Len;     // total frame len (hdr + payload), min 32
  333.   ULONG Req_B_SFS_Addr;    // 32-bit pointer to FCHS struct (to be sent)
  334.   ULONG Req_B_SFS_D_ID;    // 24-bit FC destination (i.e. 8 bit al_pa)
  335.   ULONG Req_B_Trans_ID;    // X_ID (OX_ID or RX_ID) and/or Index in SEST
  336. } TachLiteIRB;
  337. typedef struct           // TachLite placeholder for IRBs
  338. {                        // aligned @sizeof(ERQ) for TachLite
  339.                          // MAX commands is sum of SEST len and ERQ
  340.                          // we know that each SEST entry requires an
  341.                          // IRB (ERQ) entry; in addition, we provide
  342.                          // ERQ_LEN
  343.   TachLiteIRB QEntry[ERQ_LEN]; // Base register; entries 32 bytes ea.
  344.   ULONG consumerIndex;   // Consumer Index register
  345.   ULONG producerIndex;   // ERQ Producer Index register
  346.   ULONG length;          // Length register
  347.   ULONG base;            // copy of base ptr for debug
  348.                          // struct is sized for largest expected cmnd (LOGIN)
  349. } TachLiteERQ;
  350. // for now, just 32 bit DMA, eventually 40something, with code changes
  351. #define CPQFCTS_DMA_MASK ((unsigned long) (0x00000000FFFFFFFF))
  352. #define TL_MAX_SG_ELEM_LEN 0x7ffff  // Max buffer length a single S/G entry
  353. // may represent (a hardware limitation).  The
  354. // only reason to ever change this is if you
  355. // want to exercise very-hard-to-reach code in
  356. // cpqfcTSworker.c:build_SEST_sglist().
  357. #define TL_DANGER_SGPAGES 7  // arbitrary high water mark for # of S/G pages
  358. // we must exceed to elicit a warning indicative
  359. // of EXTREMELY large data transfers or 
  360. // EXTREME memory fragmentation.
  361. // (means we just used up 2048 S/G elements,
  362. // Never seen this is real life, only in 
  363. // testing with tricked up driver.)
  364. #define TL_EXT_SG_PAGE_COUNT 256  // Number of Extended Scatter/Gather a/l PAIRS
  365.                                   // Tachyon register (IOBaseU 0x68)
  366.                                   // power-of-2 value ONLY!  4 min, 256 max
  367.                           // byte len is #Pairs * 2 ULONG/Pair * 4 bytes/ULONG
  368. #define TL_EXT_SG_PAGE_BYTELEN (TL_EXT_SG_PAGE_COUNT *2 *4)
  369. // SEST entry types: IWE, IRE, TWE, TRE
  370. typedef struct 
  371. {
  372.   ULONG Hdr_Len;
  373.   ULONG Hdr_Addr;
  374.   ULONG RSP_Len;
  375.   ULONG RSP_Addr;
  376.   ULONG Buff_Off;
  377. #define USES_EXTENDED_SGLIST(this_sest, x_ID) 
  378. (!((this_sest)->u[ x_ID ].IWE.Buff_Off & 0x80000000))
  379.   ULONG Link;
  380.   ULONG RX_ID;
  381.   ULONG Data_Len;
  382.   ULONG Exp_RO;
  383.   ULONG Exp_Byte_Cnt;
  384.    // --- extended/local Gather Len/Address pairs
  385.   ULONG GLen1;
  386.   ULONG GAddr1;
  387.   ULONG GLen2;
  388.   ULONG GAddr2;
  389.   ULONG GLen3;
  390.   ULONG GAddr3;
  391. } TachLiteIWE;
  392. typedef struct 
  393. {
  394.   ULONG Seq_Accum;
  395.   ULONG reserved;       // must clear to 0
  396.   ULONG RSP_Len;
  397.   ULONG RSP_Addr;
  398.   ULONG Buff_Off;
  399.   ULONG Buff_Index;           // ULONG 5
  400.   ULONG Exp_RO;
  401.   ULONG Byte_Count;
  402.   ULONG reserved_;      // ULONG 8
  403.   ULONG Exp_Byte_Cnt;
  404.    // --- extended/local Scatter Len/Address pairs
  405.   ULONG SLen1;
  406.   ULONG SAddr1;
  407.   ULONG SLen2;
  408.   ULONG SAddr2;
  409.   ULONG SLen3;
  410.   ULONG SAddr3;
  411. } TachLiteIRE;
  412. typedef struct          // Target Write Entry
  413. {
  414.   ULONG Seq_Accum;      // dword 0
  415.   ULONG reserved;       // dword 1  must clear to 0
  416.   ULONG Remote_Node_ID;
  417.   ULONG reserved1;      // dword 3  must clear to 0
  418.   ULONG Buff_Off;
  419.   ULONG Buff_Index;     // ULONG 5
  420.   ULONG Exp_RO;
  421.   ULONG Byte_Count;
  422.   ULONG reserved_;      // ULONG 8
  423.   ULONG Exp_Byte_Cnt;
  424.    // --- extended/local Scatter Len/Address pairs
  425.   ULONG SLen1;
  426.   ULONG SAddr1;
  427.   ULONG SLen2;
  428.   ULONG SAddr2;
  429.   ULONG SLen3;
  430.   ULONG SAddr3;
  431. } TachLiteTWE;
  432. typedef struct      
  433. {
  434.   ULONG Hdr_Len;
  435.   ULONG Hdr_Addr;
  436.   ULONG RSP_Len;        // DWord 2
  437.   ULONG RSP_Addr;
  438.   ULONG Buff_Off;
  439.   ULONG Buff_Index;     // DWord 5
  440.   ULONG reserved;
  441.   ULONG Data_Len;
  442.   ULONG reserved_;
  443.   ULONG reserved__;
  444.    // --- extended/local Gather Len/Address pairs
  445.   ULONG GLen1;          // DWord A
  446.   ULONG GAddr1;
  447.   ULONG GLen2;
  448.   ULONG GAddr2;
  449.   ULONG GLen3;
  450.   ULONG GAddr3;
  451. } TachLiteTRE;
  452. typedef struct ext_sg_page_ptr_t *PSGPAGES;
  453. typedef struct ext_sg_page_ptr_t 
  454. {
  455.   unsigned char page[TL_EXT_SG_PAGE_BYTELEN * 2]; // 2x for alignment
  456.   dma_addr_t busaddr;  // need the bus addresses and
  457.   unsigned int maplen;  // lengths for later pci unmapping.
  458.   PSGPAGES next;
  459. } SGPAGES; // linked list of S/G pairs, by Exchange
  460. typedef struct                  // SCSI Exchange State Table
  461. {
  462.   union                         // Entry can be IWE, IRE, TWE, TRE
  463.   {                             // 64 bytes per entry
  464.     TachLiteIWE IWE;
  465.     TachLiteIRE IRE;
  466.     TachLiteTWE TWE;
  467.     TachLiteTRE TRE;
  468.   } u[TACH_SEST_LEN];
  469.   TachFCHDR DataHDR[TACH_SEST_LEN]; // for SEST FCP_DATA frame hdr (no pl)
  470.   TachFCHDR_RSP RspHDR[TACH_SEST_LEN]; // space for SEST FCP_RSP frame
  471.   PSGPAGES sgPages[TACH_SEST_LEN]; // head of linked list of Pool-allocations
  472.   ULONG length;          // Length register
  473.   ULONG base;            // copy of base ptr for debug
  474. } TachSEST;
  475. typedef struct                  // each register has it's own address
  476.                                 // and value (used for write-only regs)
  477. {
  478.   void* address;
  479.   volatile ULONG value;
  480. } FCREGISTER;
  481. typedef struct         // Host copy - TachLite Registers
  482. {
  483.   ULONG IOBaseL, IOBaseU;  // I/O port lower and upper TL register addresses
  484.   ULONG MemBase;           // memory mapped register addresses
  485.   void* ReMapMemBase;      // O/S VM reference for MemBase
  486.   ULONG wwn_hi;            // WWN is set once at startup
  487.   ULONG wwn_lo;
  488.   ULONG my_al_pa;          // al_pa received after LIP()
  489.   ULONG ROMCTR;            // flags for on-board RAM/ROM
  490.   ULONG RAMBase;           // on-board RAM (i.e. some Tachlites)
  491.   ULONG SROMBase;          // on-board EEPROM (some Tachlites)
  492.   ULONG PCIMCTR;           // PCI Master Control Reg (has bus width)
  493.   FCREGISTER INTEN;        // copy of interrupt enable mask
  494.   FCREGISTER INTPEND;      // interrupt pending
  495.   FCREGISTER INTSTAT;      // interrupt status
  496.   FCREGISTER SFQconsumerIndex; 
  497.   FCREGISTER ERQproducerIndex; 
  498.   FCREGISTER TYconfig;   // TachYon (chip level)
  499.   FCREGISTER TYcontrol;
  500.   FCREGISTER TYstatus;
  501.   FCREGISTER FMconfig;   // Frame Manager (FC loop level)
  502.   FCREGISTER FMcontrol;
  503.   FCREGISTER FMstatus;
  504.   FCREGISTER FMLinkStatus1;
  505.   FCREGISTER FMLinkStatus2;
  506.   FCREGISTER FMBB_CreditZero;
  507.   FCREGISTER status;
  508.   FCREGISTER ed_tov;     // error detect time-out value
  509.   FCREGISTER rcv_al_pa;  // received arb. loop physical address
  510.   FCREGISTER primitive;  // e.g. LIP(), OPN(), ...
  511. } TL_REGISTERS;
  512. typedef struct 
  513. {
  514.   ULONG ok;
  515.   ULONG invalidArgs;
  516.   ULONG linkDown;
  517.   ULONG linkUp;
  518.   ULONG outQueFull;
  519.   ULONG SESTFull;
  520.   ULONG hpe;    // host programming err (from Tach)
  521.   ULONG FC4aborted; // aborts from Application or upper driver layer
  522.   ULONG FC2aborted; // aborts from our driver's timeouts
  523.   ULONG timeouts;   // our driver timeout (on individual exchanges)
  524.   ULONG logouts;    // explicit - sent LOGO; implicit - device removed
  525.   ULONG retries;
  526.   ULONG linkFailTX;
  527.   ULONG linkFailRX;
  528.   ULONG CntErrors;  // byte count expected != count received (typ. SEST)
  529.   ULONG e_stores;   // elastic store errs
  530.   ULONG resets;     // hard or soft controller resets
  531.   ULONG FMinits;    // TACH Frame Manager Init (e.g. LIPs)
  532.   ULONG lnkQueFull;  // too many LOGIN, loop commands
  533.   ULONG ScsiQueFull; // too many FCP-SCSI inbound frames
  534.   ULONG LossofSignal;   // FM link status 1 regs
  535.   ULONG BadRXChar;   // FM link status 1 regs
  536.   ULONG LossofSync;   // FM link status 1 regs
  537.   ULONG Rx_EOFa;   // FM link status 2 regs (received EOFa)
  538.   ULONG Dis_Frm;   // FM link status 2 regs (discarded frames)
  539.   ULONG Bad_CRC;   // FM link status 2 regs
  540.   ULONG BB0_Timer; //  FM BB_Credit Zero Timer Reg
  541.   ULONG loopBreaks; // infinite loop exits
  542.   ULONG lastBB0timer;  // static accum. buffer needed by Tachlite
  543. } FCSTATS;
  544. typedef struct               // Config Options
  545. {                            // LS Bit first
  546.   USHORT        : 1;           // bit0:
  547.   USHORT  flogi : 1;           // bit1: We sent FLOGI - wait for Fabric logins
  548.   USHORT  fabric: 1;           // bit2: Tachyon detected Fabric (FM stat LG)
  549.   USHORT  LILPin: 1;           // bit3: We can use an FC-AL LILP frame
  550.   USHORT  target: 1;           // bit4: this Port has SCSI target capability
  551.   USHORT  initiator:    1;     // bit5: this Port has SCSI initiator capability
  552.   USHORT  extLoopback:  1;     // bit6: loopback at GBIC
  553.   USHORT  intLoopback:  1;     // bit7: loopback in HP silicon
  554.   USHORT        : 1;           // bit8:
  555.   USHORT        : 1;           // bit9:
  556.   USHORT        : 1;           // bit10:
  557.   USHORT        : 1;           // bit11:
  558.   USHORT        : 1;           // bit12:
  559.   USHORT        : 1;           // bit13:
  560.   USHORT        : 1;           // bit14:
  561.   USHORT        : 1;           // bit15:
  562. } FC_OPTIONS;
  563. typedef struct dyn_mem_pair
  564. {
  565.   void *BaseAllocated;  // address as allocated from O/S;
  566.   unsigned long AlignedAddress; // aligned address (used by Tachyon DMA)
  567.   dma_addr_t dma_handle;
  568.   size_t size;
  569. } ALIGNED_MEM;
  570. // these structs contain only CRUCIAL (stuff we actually use) parameters
  571. // from FC-PH(n) logins.  (Don't save entire LOGIN payload to save mem.)
  572. // Implicit logout happens when the loop goes down - we require PDISC
  573. // to restore.  Explicit logout is when WE decide never to talk to someone,
  574. // or when a target refuses to talk to us, i.e. sends us a LOGO frame or
  575. // LS_RJT reject in response to our PLOGI request.
  576. #define IMPLICIT_LOGOUT 1
  577. #define EXPLICIT_LOGOUT 2
  578. typedef struct 
  579. {
  580.   UCHAR channel; // SCSI "bus"
  581.   UCHAR target;
  582.   UCHAR InqDeviceType;  // byte 0 from SCSI Inquiry response
  583.   UCHAR VolumeSetAddressing;  // FCP-SCSI LUN coding (40h for VSA)
  584.   UCHAR LunMasking;     // True if selective presentation supported
  585.   UCHAR lun[CPQFCTS_MAX_LUN];
  586. } SCSI_NEXUS;
  587. typedef struct        
  588. {
  589.   union 
  590.   {
  591.     UCHAR ucWWN[8];  // a FC 64-bit World Wide Name/ PortID of target
  592.                      // addressing of single target on single loop...
  593.     u64 liWWN;
  594.   } u;
  595.   ULONG port_id;     // a FC 24-bit address of port (lower 8 bits = al_pa)
  596.   Scsi_Cmnd ScsiCmnd;   // command buffer for Report Luns
  597. #define REPORT_LUNS_PL 256  
  598.   UCHAR ReportLunsPayload[REPORT_LUNS_PL];
  599.   
  600.   SCSI_NEXUS ScsiNexus; // LUNs per FC device
  601.   ULONG LOGO_counter; // might try several times before logging out for good
  602.   ULONG LOGO_timer;   // after LIP, ports expecting PDISC must time-out and
  603.                       // LOGOut if successful PDISC not completed in 2 secs
  604.   ULONG concurrent_seq;  // must be 1 or greater
  605.   ULONG rx_data_size;    // e.g. 128, 256, 1024, 2048 per FC-PH spec
  606.   ULONG BB_credit;
  607.   ULONG EE_credit;
  608.   ULONG fcp_info;        // from PRLI (i.e. INITIATOR/ TARGET flags)
  609.                          // flags for login process
  610.   BOOLEAN Originator;    // Login sequence Originated (if false, we
  611.                          // responded to another port's login sequence)
  612.   BOOLEAN plogi;         // PLOGI frame ACCepted (originated or responded)
  613.   BOOLEAN pdisc;         // PDISC frame was ORIGINATED (self-login logic)
  614.   BOOLEAN prli;          // PRLI frame ACCepted (originated or responded)
  615.   BOOLEAN flogi;         // FLOGI frame ACCepted (originated or responded)
  616.   BOOLEAN logo;          // port permanently logged out (invalid login param)
  617.   BOOLEAN flogiReq;      // Fabric login required (set in LIP process)
  618.   UCHAR highest_ver;
  619.   UCHAR lowest_ver;
  620.   
  621.   // when the "target" (actually FC Port) is waiting for login
  622.   // (e.g. after Link reset), set the device_blocked bit;
  623.   // after Port completes login, un-block target.
  624.   UCHAR device_blocked; // see Scsi_Device struct
  625.                     // define singly-linked list of logged-in ports
  626.                     // once a port_id is identified, it is remembered,
  627.                     // even if the port is removed indefinitely
  628.   PVOID pNextPort;  // actually, type PFC_LOGGEDIN_PORT; void for Compiler
  629. } FC_LOGGEDIN_PORT, *PFC_LOGGEDIN_PORT;
  630. // This serves as the ESB (Exchange Status Block),
  631. // and has timeout counter; used for ABORTs
  632. typedef struct                
  633. {                                  // FC-1 X_IDs
  634.   ULONG type;            // ELS_PLOGI, SCSI_IWE, ... (0 if free)
  635.   PFC_LOGGEDIN_PORT pLoggedInPort; // FC device on other end of Exchange
  636.   Scsi_Cmnd *Cmnd;       // Linux SCSI command packet includes S/G list
  637.   ULONG timeOut;         // units of ??, DEC by driver, Abort when 0
  638.   ULONG reTries;         // need one or more retries?
  639.   ULONG status;          // flags indicating errors (0 if none)
  640.   TachLiteIRB IRB;       // I/O Request Block, gets copied to ERQ
  641.   TachFCHDR_GCMND fchs;  // location of IRB's Req_A_SFS_Addr
  642. } FC_EXCHANGE, *PFC_EXCHANGE;
  643. // Unfortunately, Linux limits our kmalloc() allocations to 128k.
  644. // Because of this and the fact that our ScsiRegister allocation
  645. // is also constrained, we move this large structure out for
  646. // allocation after Scsi Register.
  647. // (In other words, this cumbersome indirection is necessary
  648. // because of kernel memory allocation constraints!)
  649. typedef struct // we will allocate this dynamically
  650. {
  651.   FC_EXCHANGE fcExchange[ TACH_MAX_XID ];
  652. } FC_EXCHANGES;
  653. typedef struct
  654. {
  655.   char Name[64]; // name of controller ("HP Tachlite TL Rev2.0, 33MHz, 64bit bus")
  656.   //PVOID  pAdapterDevExt; // back pointer to device object/extension
  657.   ULONG ChipType;        // local numeric key for Tachyon Type / Rev.
  658.   ULONG status;              // our Driver - logical status
  659.   
  660.   TL_REGISTERS Registers;    // reg addresses & host memory copies
  661.                              // FC-4 mapping of 'transaction' to X_IDs
  662.   UCHAR LILPmap[32*4];       // Loop Position Map of ALPAs (late FC-AL only)
  663.   FC_OPTIONS Options;        // e.g. Target, Initiator, loopback...
  664.   UCHAR highest_FCPH_ver;    // FC-PH version limits
  665.   UCHAR lowest_FCPH_ver;     // FC-PH version limits
  666.   FC_EXCHANGES *Exchanges;  
  667.   ULONG fcLsExchangeLRU;       // Least Recently Used counter (Link Service)
  668.   ULONG fcSestExchangeLRU;       // Least Recently Used counter (FCP-SCSI)
  669.   FC_LOGGEDIN_PORT fcPorts;  // linked list of every FC port ever seen
  670.   FCSTATS fcStats;           // FC comm err counters
  671.                              // Host memory QUEUE pointers
  672.   TachLiteERQ *ERQ;          // Exchange Request Que 
  673.   TachyonIMQ *IMQ;           // Inbound Message Que 
  674.   TachLiteSFQ *SFQ;          // Single Frame Queue
  675.   TachSEST *SEST;            // SCSI Exchange State Table
  676.   dma_addr_t exch_dma_handle;
  677.   // these function pointers are for "generic" functions, which are
  678.   // replaced with Host Bus Adapter types at
  679.   // runtime.
  680.   int (*CreateTachyonQues)( void* , int);
  681.   int (*DestroyTachyonQues)( void* , int);
  682.   int (*LaserControl)(void*, int );   // e.g. On/Off
  683.   int (*ResetTachyon)(void*, int );
  684.   void (*FreezeTachyon)(void*, int );
  685.   void (*UnFreezeTachyon)(void*, int );
  686.   int (*InitializeTachyon)(void*, int, int );
  687.   int (*InitializeFrameManager)(void*, int );
  688.   int (*ProcessIMQEntry)(void*);
  689.   int (*ReadWriteWWN)(void*, int ReadWrite);
  690.   int (*ReadWriteNVRAM)(void*, void*, int ReadWrite);
  691. } TACHYON, *PTACHYON;
  692. void cpqfcTSClearLinkStatusCounters(TACHYON * fcChip);
  693. int CpqTsCreateTachLiteQues( void* pHBA, int opcode);
  694. int CpqTsDestroyTachLiteQues( void* , int);
  695. int CpqTsInitializeTachLite( void *pHBA, int opcode1, int opcode2);
  696. int CpqTsProcessIMQEntry(void* pHBA);
  697. int CpqTsResetTachLite(void *pHBA, int type);
  698. void CpqTsFreezeTachlite(void *pHBA, int type);
  699. void CpqTsUnFreezeTachlite(void *pHBA, int type);
  700. int CpqTsInitializeFrameManager(void *pHBA, int);
  701. int CpqTsLaserControl( void* addrBase, int opcode );
  702. int CpqTsReadWriteWWN(void*, int ReadWrite);
  703. int CpqTsReadWriteNVRAM(void*, void* data, int ReadWrite);
  704. void cpqfcTS_WorkTask( struct Scsi_Host *HostAdapter);
  705. void cpqfcTSWorkerThread( void *host);
  706. int cpqfcTS_GetNVRAM_data( UCHAR *wwnbuf, UCHAR *buf );
  707. ULONG cpqfcTS_ReadNVRAM( void* GPIOin, void* GPIOout , USHORT count,
  708. UCHAR *buf );
  709. BOOLEAN tl_write_i2c_nvram( void* GPIOin, void* GPIOout,
  710.   USHORT startOffset,  // e.g. 0x2f for WWN start
  711.   USHORT count,
  712.   UCHAR *buf );
  713. // define misc functions 
  714. int cpqfcTSGetLPSM( PTACHYON fcChip, char cErrorString[]);
  715. int cpqfcTSDecodeGBICtype( PTACHYON fcChip, char cErrorString[]);
  716. void* fcMemManager( struct pci_dev *pdev,
  717. ALIGNED_MEM *dyn_mem_pair, ULONG n_alloc, ULONG ab,
  718.                    ULONG ulAlignedAddress, dma_addr_t *dma_handle);
  719. void BigEndianSwap(  UCHAR *source, UCHAR *dest,  USHORT cnt);
  720. //ULONG virt_to_phys( PVOID virtaddr );
  721.                   
  722. // Linux interrupt handler
  723. void cpqfcTS_intr_handler( int irq,void *dev_id,struct pt_regs *regs);
  724. void cpqfcTSheartbeat( unsigned long ptr );
  725. // The biggest Q element we deal with is Aborts - we
  726. // need 4 bytes for x_ID, and a Scsi_Cmnd (~284 bytes)
  727. //#define LINKQ_ITEM_SIZE ((4+sizeof(Scsi_Cmnd)+3)/4)
  728. #define LINKQ_ITEM_SIZE (3*16)
  729. typedef struct
  730. {
  731.   ULONG Type;              // e.g. LINKUP, SFQENTRY, PDISC, BLS_ABTS, ...
  732.   ULONG ulBuff[ LINKQ_ITEM_SIZE ];
  733. } LINKQ_ITEM;
  734. #define FC_LINKQ_DEPTH TACH_MAX_XID
  735. typedef struct
  736. {
  737.   ULONG producer;
  738.   ULONG consumer;  // when producer equals consumer, Q empty
  739.   LINKQ_ITEM Qitem[ FC_LINKQ_DEPTH ];
  740. } FC_LINK_QUE, *PFC_LINK_QUE;
  741.      // DPC routines post to here on Inbound SCSI frames
  742.      // User thread processes
  743. #define FC_SCSIQ_DEPTH 32
  744. typedef struct
  745. {
  746.   int Type;              // e.g. SCSI
  747.   ULONG ulBuff[ 3*16 ];
  748. } SCSIQ_ITEM;
  749. typedef struct
  750. {
  751.   ULONG producer;
  752.   ULONG consumer;  // when producer equals consumer, Q empty
  753.   SCSIQ_ITEM Qitem[ FC_SCSIQ_DEPTH ];
  754. } FC_SCSI_QUE, *PFC_SCSI_QUE;
  755. #define DYNAMIC_ALLOCATIONS 4  // Tachyon aligned allocations: ERQ,IMQ,SFQ,SEST
  756. // Linux space allocated per HBA (chip state, etc.)
  757. typedef struct 
  758. {
  759.   struct Scsi_Host *HostAdapter; // back pointer to Linux Scsi struct
  760.   TACHYON fcChip;    // All Tachyon registers, Queues, functions
  761.   ALIGNED_MEM dynamic_mem[DYNAMIC_ALLOCATIONS];
  762.   struct pci_dev *PciDev;
  763.   dma_addr_t fcLQ_dma_handle;
  764.   Scsi_Cmnd *LinkDnCmnd[CPQFCTS_REQ_QUEUE_LEN]; // collects Cmnds during LDn
  765.                                                 // (for Acceptable targets)
  766.   Scsi_Cmnd *BoardLockCmnd[CPQFCTS_REQ_QUEUE_LEN]; // SEST was full
  767.   
  768.   Scsi_Cmnd *BadTargetCmnd[CPQFCTS_MAX_TARGET_ID]; // missing targets
  769.   u_char HBAnum;     // 0-based host number
  770.   struct timer_list cpqfcTStimer; // FC utility timer for implicit
  771.                                   // logouts, FC protocol timeouts, etc.
  772.   int fcStatsTime;  // Statistics delta reporting time
  773.   struct task_struct *worker_thread; // our kernel thread
  774.   int PortDiscDone;    // set by SendLogins(), cleared by LDn
  775.   
  776.   struct semaphore *TachFrozen;
  777.   struct semaphore *TYOBcomplete;    // handshake for Tach outbound frames
  778.   struct semaphore *fcQueReady;      // FibreChannel work for our kernel thread
  779.   struct semaphore *notify_wt;       // synchronizes kernel thread kill
  780.   struct semaphore *BoardLock;
  781.   
  782.   PFC_LINK_QUE fcLQ;             // the WorkerThread operates on this
  783.   spinlock_t hba_spinlock;           // held/released by WorkerThread
  784. } CPQFCHBA;
  785. #define CPQ_SPINLOCK_HBA( x )   spin_lock(&x->hba_spinlock);
  786. #define CPQ_SPINUNLOCK_HBA(x)   spin_unlock(&x->hba_spinlock);
  787. void cpqfcTSImplicitLogout( CPQFCHBA* cpqfcHBAdata,
  788. PFC_LOGGEDIN_PORT pFcPort);
  789. void cpqfcTSTerminateExchange( CPQFCHBA*, SCSI_NEXUS *target, int );
  790. PFC_LOGGEDIN_PORT fcPortLoggedIn( 
  791.    CPQFCHBA *cpqfcHBAdata, 
  792.    TachFCHDR_GCMND* fchs, 
  793.    BOOLEAN, 
  794.    BOOLEAN);
  795. void fcProcessLoggedIn( 
  796.    CPQFCHBA *cpqfcHBAdata, TachFCHDR_GCMND* fchs);
  797. ULONG cpqfcTSBuildExchange( 
  798.   CPQFCHBA *cpqfcHBAdata,
  799.   ULONG type, // e.g. PLOGI
  800.   TachFCHDR_GCMND* InFCHS,  // incoming FCHS
  801.   void *Data,               // the CDB, scatter/gather, etc.  
  802.   LONG *ExchangeID );       // allocated exchange ID
  803. ULONG cpqfcTSStartExchange( 
  804.   CPQFCHBA *cpqfcHBAdata,
  805.   LONG ExchangeID );
  806. void cpqfcTSCompleteExchange( 
  807.        struct pci_dev *pcidev,
  808.        PTACHYON fcChip, 
  809.        ULONG exchange_ID);
  810. PFC_LOGGEDIN_PORT  fcFindLoggedInPort( 
  811.   PTACHYON fcChip, 
  812.   Scsi_Cmnd *Cmnd,  // (We want the channel/target/lun Nexus from Cmnd)
  813.   ULONG port_id,  // search linked list for al_pa, or
  814.   UCHAR wwn[8],    // search linked list for WWN, or...
  815.   PFC_LOGGEDIN_PORT *pLastLoggedInPort
  816. );
  817. void cpqfcTSPutLinkQue( 
  818.   CPQFCHBA *cpqfcHBAdata, 
  819.   int Type, 
  820.   void *QueContent);
  821. void fcPutScsiQue( 
  822.   CPQFCHBA *cpqfcHBAdata, 
  823.   int Type, 
  824.   void *QueContent);
  825. void fcLinkQReset(
  826.    CPQFCHBA *);
  827. void fcScsiQReset(
  828.    CPQFCHBA *);
  829. void fcSestReset(
  830.    CPQFCHBA *);
  831. void cpqfc_pci_unmap(struct pci_dev *pcidev, 
  832. Scsi_Cmnd *cmd, 
  833. PTACHYON fcChip, 
  834. ULONG x_ID);
  835. extern const UCHAR valid_al_pa[];
  836. extern const int number_of_al_pa;
  837. #define FCP_RESID_UNDER   0x80000
  838. #define FCP_RESID_OVER    0x40000
  839. #define FCP_SNS_LEN_VALID 0x20000
  840. #define FCP_RSP_LEN_VALID 0x10000
  841. // RSP_CODE definitions (dpANS Fibre Channel Protocol for SCSI, pg 34)
  842. #define FCP_DATA_LEN_NOT_BURST_LEN 0x1000000
  843. #define FCP_CMND_FIELD_INVALID     0x2000000
  844. #define FCP_DATA_RO_NOT_XRDY_RO    0x3000000
  845. #define FCP_TASKFUNCTION_NS        0x4000000
  846. #define FCP_TASKFUNCTION_FAIL      0x5000000
  847. // FCP-SCSI response status struct
  848. typedef struct  // see "TachFCHDR_RSP" definition - 64 bytes
  849. {
  850.   __u32 reserved;
  851.   __u32 reserved1;
  852.   __u32 fcp_status;    // field validity and SCSI status
  853.   __u32 fcp_resid;
  854.   __u32 fcp_sns_len;   // length of FCP_SNS_INFO field
  855.   __u32 fcp_rsp_len;   // length of FCP_RSP_INFO field (expect 8)
  856.   __u32 fcp_rsp_info;  // 4 bytes of FCP protocol response information
  857.   __u32 fcp_rsp_info2; // (4 more bytes, since most implementations use 8)
  858.   __u8  fcp_sns_info[36]; // bytes for SCSI sense (ASC, ASCQ)
  859. } FCP_STATUS_RESPONSE, *PFCP_STATUS_RESPONSE;
  860. // Fabric State Change Registration
  861. typedef struct scrpl
  862. {
  863.   __u32 command;
  864.   __u32 function;
  865. } SCR_PL;
  866. // Fabric Name Service Request
  867. typedef struct nsrpl
  868. {
  869.   __u32 CT_Rev;  // (& IN_ID)   WORD 0
  870.   __u32 FCS_Type;            // WORD 1
  871.   __u32 Command_code;        // WORD 2
  872.   __u32 reason_code;         // WORD 3
  873.   __u32 FCP;                 // WORD 4 (lower byte)
  874.   
  875. } NSR_PL;
  876. // "FC.H"
  877. #define MAX_RX_SIZE 0x800 // Max Receive Buffer Size is 2048
  878. #define MIN_RX_SIZE 0x100 // Min Size is 256, per FC-PLDA Spec
  879. #define MAX_TARGET_RXIDS SEST_DEPTH
  880. #define TARGET_RX_SIZE SEST_BUFFER_LENGTH
  881. #define CLASS_1 0x01
  882. #define CLASS_2 0x02
  883. #define CLASS_3 0x03
  884. #define FC_PH42 0x08
  885. #define FC_PH43 0x09
  886. #define FC_PH3 0x20
  887. #define RR_TOV 2 // Minimum Time for target to wait for
  888. // PDISC after a LIP.
  889. #define E_D_TOV 2 // Minimum Time to wait for Sequence
  890. // Completion.
  891. #define R_A_TOV 0 // Minimum Time for Target to wait 
  892. // before reclaiming resources.
  893. //
  894. // R_CTL Field
  895. //
  896. // Routing Bits (31-28)
  897. //
  898. #define FC4_DEVICE_DATA 0x00000000
  899. #define EXT_LINK_DATA 0x20000000
  900. #define FC4_LINK_DATA 0x30000000
  901. #define VIDEO_DATA 0x40000000
  902. #define BASIC_LINK_DATA 0x80000000
  903. #define LINK_CONTROL 0xC0000000
  904. #define ROUTING_MASK 0xF0000000
  905. //
  906. // Information Bits (27-24)
  907. //
  908. #define UNCAT_INFORMATION 0x00000000
  909. #define SOLICITED_DATA 0x01000000
  910. #define UNSOLICITED_CONTROL 0x02000000
  911. #define SOLICITED_CONTROL 0x03000000
  912. #define UNSOLICITED_DATA 0x04000000
  913. #define DATA_DESCRIPTOR 0x05000000
  914. #define UNSOLICITED_COMMAND 0x06000000
  915. #define COMMAND_STATUS 0x07000000
  916. #define INFO_MASK 0x0F000000
  917. //
  918. // (Link Control Codes)
  919. //
  920. #define ACK_1 0x00000000
  921. #define ACK_0_OR_N 0x01000000
  922. #define P_RJT 0x02000000 
  923. #define F_RJT 0x03000000 
  924. #define P_BSY 0x04000000
  925. #define FABRIC_BUSY_TO_DF 0x05000000 // Fabric Busy to Data Frame
  926. #define FABRIC_BUSY_TO_LC 0x06000000 // Fabric Busy to Link Ctl Frame
  927. #define LINK_CREDIT_RESET 0x07000000
  928. //
  929. // (Link Service Command Codes)
  930. //
  931. //#define LS_RJT 0x01000000 // LS Reject
  932. #define LS_ACC 0x02000000 // LS Accept
  933. #define LS_PLOGI 0x03000000 // N_PORT Login
  934. #define LS_FLOGI 0x04000000 // F_PORT Login
  935. #define LS_LOGO 0x05000000 // Logout
  936. #define LS_ABTX 0x06000000 // Abort Exchange
  937. #define LS_RCS 0x07000000 // Read Connection Status
  938. #define LS_RES 0x08000000 // Read Exchange Status
  939. #define LS_RSS 0x09000000 // Read Sequence Status
  940. #define LS_RSI 0x0A000000 // Request Seq Initiative
  941. #define LS_ESTS 0x0B000000 // Establish Steaming
  942. #define LS_ESTC 0x0C000000 // Estimate Credit
  943. #define LS_ADVC 0x0D000000 // Advice Credit
  944. #define LS_RTV 0x0E000000 // Read Timeout Value
  945. #define LS_RLS 0x0F000000 // Read Link Status
  946. #define LS_ECHO 0x10000000 // Echo
  947. #define LS_TEST 0x11000000 // Test
  948. #define LS_RRQ 0x12000000 // Reinstate Rec. Qual.
  949. #define LS_PRLI 0x20000000 // Process Login
  950. #define LS_PRLO 0x21000000 // Process Logout
  951. #define LS_TPRLO 0x24000000 // 3rd Party Process Logout
  952. #define LS_PDISC 0x50000000 // Process Discovery
  953. #define LS_FDISC 0x51000000 // Fabric Discovery
  954. #define LS_ADISC 0x52000000 // Discover Address
  955. #define LS_RNC 0x53000000 // Report Node Capability
  956. #define LS_SCR                  0x62000000      // State Change Registration
  957. #define LS_MASK 0xFF000000
  958. //
  959. //  TYPE Bit Masks
  960. //
  961. #define BASIC_LINK_SERVICE 0x00000000
  962. #define EXT_LINK_SERVICE 0x01000000
  963. #define LLC 0x04000000
  964. #define LLC_SNAP 0x05000000
  965. #define SCSI_FCP 0x08000000
  966. #define SCSI_GPP 0x09000000
  967. #define IPI3_MASTER 0x11000000
  968. #define IPI3_SLAVE 0x12000000
  969. #define IPI3_PEER 0x13000000
  970. #define CP_IPI3_MASTER 0x15000000
  971. #define CP_IPI3_SLAVE 0x16000000
  972. #define CP_IPI3_PEER 0x17000000
  973. #define SBCCS_CHANNEL 0x19000000
  974. #define SBCCS_CONTROL 0x1A000000
  975. #define FIBRE_SERVICES 0x20000000
  976. #define FC_FG 0x21000000
  977. #define FC_XS 0x22000000
  978. #define FC_AL 0x23000000
  979. #define SNMP 0x24000000
  980. #define HIPPI_FP 0x40000000
  981. #define TYPE_MASK 0xFF000000
  982. typedef struct {
  983. UCHAR seq_id_valid;
  984. UCHAR seq_id;
  985. USHORT reserved;  // 2 bytes reserved
  986. ULONG ox_rx_id;
  987. USHORT low_seq_cnt;
  988. USHORT high_seq_cnt;
  989. } BA_ACC_PAYLOAD;
  990. typedef struct {
  991. UCHAR reserved;
  992. UCHAR reason_code;
  993. UCHAR reason_explain;
  994. UCHAR vendor_unique;
  995. } BA_RJT_PAYLOAD;
  996. typedef struct {
  997. ULONG  command_code;
  998. ULONG  sid;
  999. USHORT ox_id;
  1000. USHORT rx_id;
  1001. } RRQ_MESSAGE;
  1002. typedef struct {
  1003. ULONG command_code;
  1004. UCHAR vendor;
  1005. UCHAR explain;
  1006. UCHAR reason;
  1007. UCHAR reserved;
  1008. } REJECT_MESSAGE;
  1009. #define N_OR_F_PORT 0x1000
  1010. #define RANDOM_RELATIVE_OFFSET 0x4000
  1011. #define CONTINUOSLY_INCREASING 0x8000
  1012. #define CLASS_VALID 0x8000
  1013. #define INTERMIX_MODE 0x4000
  1014. #define TRANSPARENT_STACKED 0x2000
  1015. #define LOCKDOWN_STACKED 0x1000
  1016. #define SEQ_DELIVERY 0x800
  1017. #define XID_NOT_SUPPORTED 0x00
  1018. #define XID_SUPPORTED 0x4000
  1019. #define XID_REQUIRED 0xC000
  1020. #define ASSOCIATOR_NOT_SUPPORTED 0x00
  1021. #define ASSOCIATOR_SUPPORTED 0x1000
  1022. #define ASSOCIATOR_REQUIRED 0x3000
  1023. #define INIT_ACK0_SUPPORT 0x800
  1024. #define INIT_ACKN_SUPPORT 0x400
  1025. #define RECIP_ACK0_SUPPORT 0x8000
  1026. #define RECIP_ACKN_SUPPORT 0x4000
  1027. #define X_ID_INTERLOCK 0x2000
  1028. #define ERROR_POLICY 0x1800 // Error Policy Supported
  1029. #define ERROR_DISCARD 0x00 // Only Discard Supported
  1030. #define ERROR_DISC_PROCESS 0x02 // Discard and process supported
  1031. #define NODE_ID 0x01
  1032. #define IEEE_EXT 0x20
  1033. //
  1034. // Categories Supported Per Sequence
  1035. //
  1036. #define CATEGORIES_PER_SEQUENCE 0x300
  1037. #define ONE_CATEGORY_SEQUENCE 0x00 // 1 Category per Sequence
  1038. #define TWO_CATEGORY_SEQUENCE 0x01 // 2 Categories per Sequence
  1039. #define MANY_CATEGORY_SEQUENCE 0x03 // > 2 Categories/Sequence
  1040. typedef struct {
  1041. USHORT initiator_control;
  1042. USHORT service_options;
  1043. USHORT rx_data_size;
  1044. USHORT recipient_control;
  1045. USHORT ee_credit;
  1046. USHORT concurrent_sequences;
  1047. USHORT reserved;
  1048. USHORT open_sequences;
  1049. } CLASS_PARAMETERS;
  1050. typedef struct {
  1051. ULONG login_cmd;
  1052. //
  1053. // Common Service Parameters
  1054. //
  1055. struct {
  1056. USHORT bb_credit;
  1057. UCHAR lowest_ver;
  1058. UCHAR highest_ver;
  1059. USHORT bb_rx_size;
  1060. USHORT common_features;
  1061. USHORT rel_offset;
  1062. USHORT concurrent_seq;
  1063. ULONG e_d_tov;
  1064. } cmn_services;
  1065. //
  1066. // Port Name
  1067. //
  1068. UCHAR port_name[8];
  1069. //
  1070. // Node/Fabric Name
  1071. //
  1072. UCHAR node_name[8];
  1073. //
  1074. // Class 1, 2 and 3 Service Parameters
  1075. //
  1076. CLASS_PARAMETERS class1;
  1077. CLASS_PARAMETERS class2;
  1078. CLASS_PARAMETERS class3;
  1079. ULONG reserved[4];
  1080. //
  1081. // Vendor Version Level
  1082. //
  1083. UCHAR vendor_id[2];
  1084. UCHAR vendor_version[6];
  1085. ULONG buffer_size;
  1086. USHORT rxid_start;
  1087. USHORT total_rxids;
  1088. } LOGIN_PAYLOAD;
  1089. typedef struct
  1090. {
  1091.   ULONG cmd;  // 4 bytes
  1092.   UCHAR n_port_identifier[3];
  1093.   UCHAR reserved;
  1094.   UCHAR port_name[8];
  1095. } LOGOUT_PAYLOAD;
  1096. //
  1097. // PRLI Request Service Parameter Defines
  1098. //
  1099. #define PRLI_ACC 0x01
  1100. #define PRLI_REQ 0x02
  1101. #define ORIG_PROCESS_ASSOC_VALID 0x8000
  1102. #define RESP_PROCESS_ASSOC_VALID 0x4000
  1103. #define ESTABLISH_PAIR 0x2000
  1104. #define DATA_OVERLAY_ALLOWED 0x40
  1105. #define INITIATOR_FUNCTION 0x20
  1106. #define TARGET_FUNCTION 0x10
  1107. #define CMD_DATA_MIXED 0x08
  1108. #define DATA_RESP_MIXED 0x04
  1109. #define READ_XFER_RDY 0x02
  1110. #define WRITE_XFER_RDY 0x01
  1111. #define RESPONSE_CODE_MASK 0xF00
  1112. #define REQUEST_EXECUTED 0x100
  1113. #define NO_RESOURCES 0x200
  1114. #define INIT_NOT_COMPLETE 0x300
  1115. #define IMAGE_DOES_NOT_EXIST 0x400
  1116. #define BAD_PREDEFINED_COND 0x500
  1117. #define REQ_EXEC_COND 0x600
  1118. #define NO_MULTI_PAGE 0x700
  1119. typedef struct {
  1120. USHORT payload_length;
  1121. UCHAR page_length;
  1122. UCHAR cmd;
  1123. ULONG valid;
  1124. ULONG orig_process_associator;
  1125. ULONG resp_process_associator;
  1126. ULONG fcp_info;
  1127. } PRLI_REQUEST;
  1128. typedef struct {
  1129. USHORT payload_length;
  1130. UCHAR page_length;
  1131. UCHAR cmd;
  1132. ULONG valid;
  1133. ULONG orig_process_associator;
  1134. ULONG resp_process_associator;
  1135. ULONG reserved;
  1136. } PRLO_REQUEST;
  1137. typedef struct {
  1138. ULONG cmd;
  1139. ULONG hard_address;
  1140. UCHAR port_name[8];
  1141. UCHAR node_name[8];
  1142. ULONG s_id;
  1143. } ADISC_PAYLOAD;
  1144. struct ext_sg_entry_t {
  1145. __u32 len:18; /* buffer length, bits 0-17 */
  1146. __u32 uba:13; /* upper bus address bits 18-31 */
  1147. __u32 lba; /* lower bus address bits 0-31 */
  1148. }; 
  1149. // J. McCarty's LINK.H
  1150. //
  1151. // LS_RJT Reason Codes
  1152. //
  1153. #define INVALID_COMMAND_CODE 0x01
  1154. #define LOGICAL_ERROR 0x03
  1155. #define LOGICAL_BUSY 0x05
  1156. #define PROTOCOL_ERROR 0x07
  1157. #define UNABLE_TO_PERFORM 0x09
  1158. #define COMMAND_NOT_SUPPORTED 0x0B
  1159. #define LS_VENDOR_UNIQUE 0xFF
  1160. //
  1161. //  LS_RJT Reason Codes Explanations
  1162. //
  1163. #define NO_REASON 0x00
  1164. #define OPTIONS_ERROR 0x01
  1165. #define INITIATOR_CTL_ERROR 0x03
  1166. #define RECIPIENT_CTL_ERROR 0x05
  1167. #define DATA_FIELD_SIZE_ERROR 0x07
  1168. #define CONCURRENT_SEQ_ERROR 0x09
  1169. #define CREDIT_ERROR 0x0B
  1170. #define INVALID_PORT_NAME 0x0D
  1171. #define INVALID_NODE_NAME 0x0E
  1172. #define INVALID_CSP 0x0F // Invalid Service Parameters
  1173. #define INVALID_ASSOC_HDR 0x11 // Invalid Association Header
  1174. #define ASSOC_HDR_REQUIRED 0x13 // Association Header Required
  1175. #define LS_INVALID_S_ID 0x15
  1176. #define INVALID_OX_RX_ID 0x17 // Invalid OX_ID RX_ID Combination
  1177. #define CMD_IN_PROCESS 0x19
  1178. #define INVALID_IDENTIFIER 0x1F // Invalid N_PORT Identifier
  1179. #define INVALID_SEQ_ID 0x21
  1180. #define ABT_INVALID_XCHNG 0x23  // Attempt to Abort an invalid Exchange
  1181. #define ABT_INACTIVE_XCHNG 0x25  // Attempt to Abort an inactive Exchange
  1182. #define NEED_REC_QUAL 0x27 // Recovery Qualifier required
  1183. #define NO_LOGIN_RESOURCES 0x29 // No resources to support login
  1184. #define NO_DATA 0x2A // Unable to supply requested data
  1185. #define REQUEST_NOT_SUPPORTED 0x2C // Request Not Supported
  1186. //
  1187. // Link Control Codes
  1188. //
  1189. //
  1190. // P_BSY Action Codes
  1191. //
  1192. #define SEQUENCE_TERMINATED 0x01000000
  1193. #define SEQUENCE_ACTIVE 0x02000000
  1194. //
  1195. // P_BSY Reason Codes
  1196. //
  1197. #define PHYS_NPORT_BUSY 0x010000
  1198. #define NPORT_RESOURCE_BUSY 0x020000
  1199. //
  1200. //  P_RJT, F_RJT Action Codes
  1201. //
  1202. #define RETRYABLE_ERROR 0x01000000
  1203. #define NON_RETRYABLE_ERROR 0x02000000
  1204. //
  1205. //  P_RJT, F_RJT Reason Codes
  1206. //
  1207. #define INVALID_D_ID 0x010000
  1208. #define INVALID_S_ID 0x020000
  1209. #define NPORT_NOT_AVAIL_TMP 0x030000
  1210. #define NPORT_NOT_AVAIL_PERM 0x040000
  1211. #define CLASS_NOT_SUPPORTED 0x050000
  1212. #define USAGE_ERROR 0x060000
  1213. #define TYPE_NOT_SUPPORTED 0x070000
  1214. #define INVAL_LINK_CONTROL 0x080000
  1215. #define INVAL_R_CTL 0x090000
  1216. #define INVAL_F_CTL 0x0A0000
  1217. #define INVAL_OX_ID 0x0B0000
  1218. #define INVAL_RX_ID 0x0C0000
  1219. #define INVAL_SEQ_ID 0x0D0000
  1220. #define INVAL_DF_CTL 0x0E0000
  1221. #define INVAL_SEQ_CNT 0x0F0000
  1222. #define INVAL_PARAMS 0x100000
  1223. #define EXCHANGE_ERROR 0x110000
  1224. #define LS_PROTOCOL_ERROR 0x120000
  1225. #define INCORRECT_LENGTH 0x130000
  1226. #define UNEXPECTED_ACK 0x140000
  1227. #define LOGIN_REQ 0x160000
  1228. #define EXCESSIVE_SEQ 0x170000
  1229. #define NO_EXCHANGE 0x180000
  1230. #define SEC_HDR_NOT_SUPPORTED 0x190000
  1231. #define NO_FABRIC 0x1A0000
  1232. #define P_VENDOR_UNIQUE 0xFF0000
  1233. //
  1234. //  BA_RJT Reason Codes
  1235. //
  1236. #define BA_INVALID_COMMAND 0x00010000
  1237. #define BA_LOGICAL_ERROR 0x00030000
  1238. #define BA_LOGICAL_BUSY 0x00050000
  1239. #define BA_PROTOCOL_ERROR 0x00070000
  1240. #define BA_UNABLE_TO_PERFORM 0x00090000
  1241. //
  1242. //  BA_RJT Reason Explanation Codes
  1243. //
  1244. #define BA_NO_REASON 0x00000000
  1245. #define BA_INVALID_OX_RX 0x00000300
  1246. #define BA_SEQUENCE_ABORTED 0x00000500
  1247. #endif /* CPQFCTSSTRUCTS_H */