1 /* fcp_impl.h: Generic SCSI on top of FC4 - our interface defines.
2  *
3  * Copyright (C) 1997-1999 Jakub Jelinek (jj@ultra.linux.cz)
4  * Copyright (C) 1998 Jirka Hanika (geo@ff.cuni.cz)
5  */
6 
7 #ifndef _FCP_SCSI_H
8 #define _FCP_SCSI_H
9 
10 #include <linux/types.h>
11 #include <linux/blk.h>
12 #include "../scsi/scsi.h"
13 
14 #include "fc.h"
15 #include "fcp.h"
16 #include "fc-al.h"
17 
18 #include <asm/io.h>
19 #ifdef __sparc__
20 #include <asm/sbus.h>
21 #endif
22 
23 /* 0 or 1 */
24 #define	FCP_SCSI_USE_NEW_EH_CODE	0
25 
26 #define FC_CLASS_OUTBOUND	0x01
27 #define FC_CLASS_INBOUND	0x02
28 #define FC_CLASS_SIMPLE		0x03
29 #define FC_CLASS_IO_WRITE	0x04
30 #define FC_CLASS_IO_READ	0x05
31 #define FC_CLASS_UNSOLICITED	0x06
32 #define FC_CLASS_OFFLINE	0x08
33 
34 #define PROTO_OFFLINE		0x02
35 #define PROTO_REPORT_AL_MAP	0x03
36 #define PROTO_FORCE_LIP		0x06
37 
38 struct _fc_channel;
39 
40 typedef struct fcp_cmnd {
41 	struct fcp_cmnd		*next;
42 	struct fcp_cmnd		*prev;
43 	void			(*done)(Scsi_Cmnd *);
44 	unsigned short		proto;
45 	unsigned short		token;
46 	unsigned int		did;
47 	/* FCP SCSI stuff */
48 	dma_addr_t		data;
49 	/* From now on this cannot be touched for proto == TYPE_SCSI_FCP */
50 	fc_hdr			fch;
51 	dma_addr_t		cmd;
52 	dma_addr_t		rsp;
53 	int			cmdlen;
54 	int			rsplen;
55 	int			class;
56 	int			datalen;
57 	/* This is just used as a verification during login */
58 	struct _fc_channel	*fc;
59 	void			*ls;
60 } fcp_cmnd;
61 
62 typedef struct {
63 	unsigned int		len;
64 	unsigned char		list[0];
65 } fcp_posmap;
66 
67 typedef struct _fc_channel {
68 	struct _fc_channel	*next;
69 	int			irq;
70 	int			state;
71 	int			sid;
72 	int			did;
73 	char			name[16];
74 	void			(*fcp_register)(struct _fc_channel *, u8, int);
75 	void			(*reset)(struct _fc_channel *);
76 	int			(*hw_enque)(struct _fc_channel *, fcp_cmnd *);
77 	fc_wwn			wwn_node;
78 	fc_wwn			wwn_nport;
79 	fc_wwn			wwn_dest;
80 	common_svc_parm		*common_svc;
81 	svc_parm		*class_svcs;
82 #ifdef __sparc__
83 	struct sbus_dev		*dev;
84 #else
85 	struct pci_dev		*dev;
86 #endif
87 	struct module		*module;
88 	/* FCP SCSI stuff */
89 	short			can_queue;
90 	short			abort_count;
91 	int			rsp_size;
92 	fcp_cmd			*scsi_cmd_pool;
93 	char			*scsi_rsp_pool;
94 	dma_addr_t		dma_scsi_cmd, dma_scsi_rsp;
95 	long			*scsi_bitmap;
96 	long			scsi_bitmap_end;
97 	int			scsi_free;
98 	int			(*encode_addr)(Scsi_Cmnd *, u16 *, struct _fc_channel *, fcp_cmnd *);
99 	fcp_cmnd		*scsi_que;
100 	char			scsi_name[4];
101 	fcp_cmnd		**cmd_slots;
102 	int			channels;
103 	int			targets;
104 	long			*ages;
105 	Scsi_Cmnd		*rst_pkt;
106 	fcp_posmap		*posmap;
107 	/* LOGIN stuff */
108 	fcp_cmnd		*login;
109 	void			*ls;
110 } fc_channel;
111 
112 extern fc_channel *fc_channels;
113 
114 #define FC_STATE_UNINITED	0
115 #define FC_STATE_ONLINE		1
116 #define FC_STATE_OFFLINE	2
117 #define FC_STATE_RESETING	3
118 #define FC_STATE_FPORT_OK	4
119 #define FC_STATE_MAYBEOFFLINE	5
120 
121 #define FC_STATUS_OK			0
122 #define FC_STATUS_P_RJT			2
123 #define FC_STATUS_F_RJT			3
124 #define FC_STATUS_P_BSY			4
125 #define FC_STATUS_F_BSY			5
126 #define FC_STATUS_ERR_OFFLINE		0x11
127 #define FC_STATUS_TIMEOUT		0x12
128 #define FC_STATUS_ERR_OVERRUN		0x13
129 #define FC_STATUS_POINTTOPOINT		0x15
130 #define FC_STATUS_AL			0x16
131 #define FC_STATUS_UNKNOWN_CQ_TYPE	0x20
132 #define FC_STATUS_BAD_SEG_CNT		0x21
133 #define FC_STATUS_MAX_XCHG_EXCEEDED	0x22
134 #define FC_STATUS_BAD_XID		0x23
135 #define FC_STATUS_XCHG_BUSY		0x24
136 #define FC_STATUS_BAD_POOL_ID		0x25
137 #define FC_STATUS_INSUFFICIENT_CQES	0x26
138 #define FC_STATUS_ALLOC_FAIL		0x27
139 #define FC_STATUS_BAD_SID		0x28
140 #define FC_STATUS_NO_SEQ_INIT		0x29
141 #define FC_STATUS_TIMED_OUT		-1
142 #define FC_STATUS_BAD_RSP		-2
143 
144 void fcp_queue_empty(fc_channel *);
145 int fcp_init(fc_channel *);
146 void fcp_release(fc_channel *fc_chain, int count);
147 void fcp_receive_solicited(fc_channel *, int, int, int, fc_hdr *);
148 void fcp_state_change(fc_channel *, int);
149 int fc_do_plogi(fc_channel *, unsigned char, fc_wwn *, fc_wwn *);
150 int fc_do_prli(fc_channel *, unsigned char);
151 
152 #define for_each_fc_channel(fc)				\
153 	for (fc = fc_channels; fc; fc = fc->next)
154 
155 #define for_each_online_fc_channel(fc) 			\
156 	for_each_fc_channel(fc)				\
157 		if (fc->state == FC_STATE_ONLINE)
158 
159 int fcp_scsi_queuecommand(Scsi_Cmnd *, void (* done)(Scsi_Cmnd *));
160 int fcp_old_abort(Scsi_Cmnd *);
161 int fcp_scsi_abort(Scsi_Cmnd *);
162 int fcp_scsi_dev_reset(Scsi_Cmnd *);
163 int fcp_scsi_bus_reset(Scsi_Cmnd *);
164 int fcp_scsi_host_reset(Scsi_Cmnd *);
165 
166 #endif /* !(_FCP_SCSI_H) */
167