bfa_fcpim.h 12.9 KB
Newer Older
K
Krishna Gudipati 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
 * All rights reserved
 * www.brocade.com
 *
 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (GPL) Version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

#ifndef __BFA_FCPIM_H__
#define __BFA_FCPIM_H__

#include "bfa.h"
#include "bfa_svc.h"
#include "bfi_ms.h"
#include "bfa_defs_svc.h"
#include "bfa_cs.h"

27
/* FCP module related definitions */
28 29
#define BFA_IO_MAX	BFI_IO_MAX
#define BFA_FWTIO_MAX	2000
30 31 32 33 34 35 36 37 38 39 40 41 42 43

struct bfa_fcp_mod_s;
struct bfa_iotag_s {
	struct list_head	qe;	/* queue element	*/
	u16	tag;			/* FW IO tag		*/
};

struct bfa_itn_s {
	bfa_isr_func_t isr;
};

void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
		void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
void bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m);
44
void bfa_iotag_attach(struct bfa_fcp_mod_s *fcp);
45
void bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw);
46 47

#define BFA_FCP_MOD(_hal)	(&(_hal)->modules.fcp_mod)
48
#define BFA_MEM_FCP_KVA(__bfa)	(&(BFA_FCP_MOD(__bfa)->kva_seg))
49 50 51 52 53
#define BFA_IOTAG_FROM_TAG(_fcp, _tag)	\
	(&(_fcp)->iotag_arr[(_tag & BFA_IOIM_IOTAG_MASK)])
#define BFA_ITN_FROM_TAG(_fcp, _tag)	\
	((_fcp)->itn_arr + ((_tag) & ((_fcp)->num_itns - 1)))
#define BFA_SNSINFO_FROM_TAG(_fcp, _tag) \
54
	bfa_mem_get_dmabuf_kva(_fcp, _tag, BFI_IOIM_SNSLEN)
K
Krishna Gudipati 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

#define BFA_ITNIM_MIN   32
#define BFA_ITNIM_MAX   1024

#define BFA_IOIM_MIN	8
#define BFA_IOIM_MAX	2000

#define BFA_TSKIM_MIN   4
#define BFA_TSKIM_MAX   512
#define BFA_FCPIM_PATHTOV_DEF	(30 * 1000)	/* in millisecs */
#define BFA_FCPIM_PATHTOV_MAX	(90 * 1000)	/* in millisecs */


#define bfa_itnim_ioprofile_update(__itnim, __index)			\
	(__itnim->ioprofile.iocomps[__index]++)

#define BFA_IOIM_RETRY_TAG_OFFSET 11
72
#define BFA_IOIM_IOTAG_MASK 0x07ff /* 2K IOs */
K
Krishna Gudipati 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#define BFA_IOIM_RETRY_MAX 7

/* Buckets are are 512 bytes to 2MB */
static inline u32
bfa_ioim_get_index(u32 n) {
	int pos = 0;
	if (n >= (1UL)<<22)
		return BFA_IOBUCKET_MAX - 1;
	n >>= 8;
	if (n >= (1UL)<<16)
		n >>= 16; pos += 16;
	if (n >= 1 << 8)
		n >>= 8; pos += 8;
	if (n >= 1 << 4)
		n >>= 4; pos += 4;
	if (n >= 1 << 2)
		n >>= 2; pos += 2;
	if (n >= 1 << 1)
		pos += 1;

	return (n == 0) ? (0) : pos;
}

/*
 * forward declarations
 */
struct bfa_ioim_s;
struct bfa_tskim_s;
struct bfad_ioim_s;
struct bfad_tskim_s;

typedef void    (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim);

106
struct bfa_fcpim_s {
K
Krishna Gudipati 已提交
107
	struct bfa_s		*bfa;
108
	struct bfa_fcp_mod_s	*fcp;
K
Krishna Gudipati 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122
	struct bfa_itnim_s	*itnim_arr;
	struct bfa_ioim_s	*ioim_arr;
	struct bfa_ioim_sp_s	*ioim_sp_arr;
	struct bfa_tskim_s	*tskim_arr;
	int			num_itnims;
	int			num_tskim_reqs;
	u32			path_tov;
	u16			q_depth;
	u8			reqq;		/*  Request queue to be used */
	u8			rsvd;
	struct list_head	itnim_q;	/*  queue of active itnim */
	struct list_head	ioim_resfree_q; /*  IOs waiting for f/w */
	struct list_head	ioim_comp_q;	/*  IO global comp Q	*/
	struct list_head	tskim_free_q;
123
	struct list_head	tskim_unused_q;	/* Unused tskim Q */
124 125
	u32			ios_active;	/*  current active IOs	*/
	u32			delay_comp;
K
Krishna Gudipati 已提交
126 127 128
	struct bfa_fcpim_del_itn_stats_s del_itn_stats;
	bfa_boolean_t		ioredirect;
	bfa_boolean_t		io_profile;
129
	u32			io_profile_start_time;
K
Krishna Gudipati 已提交
130 131 132 133
	bfa_fcpim_profile_t     profile_comp;
	bfa_fcpim_profile_t     profile_start;
};

134 135 136
/* Max FCP dma segs required */
#define BFA_FCP_DMA_SEGS	BFI_IOIM_SNSBUF_SEGS

137 138 139 140
struct bfa_fcp_mod_s {
	struct bfa_s		*bfa;
	struct list_head	iotag_ioim_free_q;	/* free IO resources */
	struct list_head	iotag_tio_free_q;	/* free IO resources */
141
	struct list_head	iotag_unused_q;	/* unused IO resources*/
142 143 144 145 146
	struct bfa_iotag_s	*iotag_arr;
	struct bfa_itn_s	*itn_arr;
	int			num_ioim_reqs;
	int			num_fwtio_reqs;
	int			num_itns;
147
	struct bfa_dma_s	snsbase[BFA_FCP_DMA_SEGS];
148
	struct bfa_fcpim_s	fcpim;
149 150
	struct bfa_mem_dma_s	dma_seg[BFA_FCP_DMA_SEGS];
	struct bfa_mem_kva_s	kva_seg;
151 152
};

153
/*
K
Krishna Gudipati 已提交
154 155 156 157 158 159
 * BFA IO (initiator mode)
 */
struct bfa_ioim_s {
	struct list_head	qe;		/*  queue elememt	*/
	bfa_sm_t		sm;		/*  BFA ioim state machine */
	struct bfa_s		*bfa;		/*  BFA module	*/
160
	struct bfa_fcpim_s	*fcpim;		/*  parent fcpim module */
K
Krishna Gudipati 已提交
161 162
	struct bfa_itnim_s	*itnim;		/*  i-t-n nexus for this IO  */
	struct bfad_ioim_s	*dio;		/*  driver IO handle	*/
163 164 165 166
	u16			iotag;		/*  FWI IO tag	*/
	u16			abort_tag;	/*  unqiue abort request tag */
	u16			nsges;		/*  number of SG elements */
	u16			nsgpgs;		/*  number of SG pages	*/
K
Krishna Gudipati 已提交
167 168 169 170
	struct bfa_sgpg_s	*sgpg;		/*  first SG page	*/
	struct list_head	sgpg_q;		/*  allocated SG pages	*/
	struct bfa_cb_qe_s	hcb_qe;		/*  bfa callback qelem	*/
	bfa_cb_cbfn_t		io_cbfn;	/*  IO completion handler */
171 172 173
	struct bfa_ioim_sp_s	*iosp;		/*  slow-path IO handling */
	u8			reqq;		/*  Request queue for I/O */
	u64			start_time;	/*  IO's Profile start val */
K
Krishna Gudipati 已提交
174 175 176 177
};

struct bfa_ioim_sp_s {
	struct bfi_msg_s	comp_rspmsg;	/*  IO comp f/w response */
178 179
	struct bfa_sgpg_wqe_s	sgpg_wqe;	/*  waitq elem for sgpg	*/
	struct bfa_reqq_wait_s	reqq_wait;	/*  to wait for room in reqq */
K
Krishna Gudipati 已提交
180 181 182 183
	bfa_boolean_t		abort_explicit;	/*  aborted by OS	*/
	struct bfa_tskim_s	*tskim;		/*  Relevant TM cmd	*/
};

184
/*
K
Krishna Gudipati 已提交
185 186 187 188 189
 * BFA Task management command (initiator mode)
 */
struct bfa_tskim_s {
	struct list_head	qe;
	bfa_sm_t		sm;
190
	struct bfa_s		*bfa;	/*  BFA module  */
191
	struct bfa_fcpim_s	*fcpim;	/*  parent fcpim module	*/
K
Krishna Gudipati 已提交
192
	struct bfa_itnim_s	*itnim;	/*  i-t-n nexus for this IO  */
193
	struct bfad_tskim_s	*dtsk;  /*  driver task mgmt cmnd	*/
194
	bfa_boolean_t		notify;	/*  notify itnim on TM comp  */
195
	struct scsi_lun		lun;	/*  lun if applicable	*/
196 197 198
	enum fcp_tm_cmnd	tm_cmnd; /*  task management command  */
	u16			tsk_tag; /*  FWI IO tag	*/
	u8			tsecs;	/*  timeout in seconds	*/
K
Krishna Gudipati 已提交
199 200
	struct bfa_reqq_wait_s  reqq_wait;   /*  to wait for room in reqq */
	struct list_head	io_q;	/*  queue of affected IOs	*/
201
	struct bfa_wc_s		wc;	/*  waiting counter	*/
K
Krishna Gudipati 已提交
202 203 204 205
	struct bfa_cb_qe_s	hcb_qe;	/*  bfa callback qelem	*/
	enum bfi_tskim_status   tsk_status;  /*  TM status	*/
};

206
/*
K
Krishna Gudipati 已提交
207 208 209
 * BFA i-t-n (initiator mode)
 */
struct bfa_itnim_s {
210 211 212 213 214
	struct list_head	qe;	/*  queue element	*/
	bfa_sm_t		sm;	/*  i-t-n im BFA state machine  */
	struct bfa_s		*bfa;	/*  bfa instance	*/
	struct bfa_rport_s	*rport;	/*  bfa rport	*/
	void			*ditn;	/*  driver i-t-n structure	*/
K
Krishna Gudipati 已提交
215
	struct bfi_mhdr_s	mhdr;	/*  pre-built mhdr	*/
216 217
	u8			msg_no;	/*  itnim/rport firmware handle */
	u8			reqq;	/*  CQ for requests	*/
K
Krishna Gudipati 已提交
218 219 220 221 222 223 224 225 226
	struct bfa_cb_qe_s	hcb_qe;	/*  bfa callback qelem	*/
	struct list_head pending_q;	/*  queue of pending IO requests */
	struct list_head io_q;		/*  queue of active IO requests */
	struct list_head io_cleanup_q;	/*  IO being cleaned up	*/
	struct list_head tsk_q;		/*  queue of active TM commands */
	struct list_head  delay_comp_q; /*  queue of failed inflight cmds */
	bfa_boolean_t   seq_rec;	/*  SQER supported	*/
	bfa_boolean_t   is_online;	/*  itnim is ONLINE for IO	*/
	bfa_boolean_t   iotov_active;	/*  IO TOV timer is active	 */
227 228
	struct bfa_wc_s	wc;		/*  waiting counter	*/
	struct bfa_timer_s timer;	/*  pending IO TOV	 */
K
Krishna Gudipati 已提交
229
	struct bfa_reqq_wait_s reqq_wait; /*  to wait for room in reqq */
230
	struct bfa_fcpim_s *fcpim;	/*  fcpim module	*/
K
Krishna Gudipati 已提交
231 232 233 234 235
	struct bfa_itnim_iostats_s	stats;
	struct bfa_itnim_ioprofile_s  ioprofile;
};

#define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
236
#define BFA_FCPIM(_hal)	(&(_hal)->modules.fcp_mod.fcpim)
237
#define BFA_IOIM_TAG_2_ID(_iotag)	((_iotag) & BFA_IOIM_IOTAG_MASK)
K
Krishna Gudipati 已提交
238
#define BFA_IOIM_FROM_TAG(_fcpim, _iotag)	\
239
	(&fcpim->ioim_arr[(_iotag & BFA_IOIM_IOTAG_MASK)])
K
Krishna Gudipati 已提交
240 241 242 243
#define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag)	\
	(&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])

#define bfa_io_profile_start_time(_bfa)	\
244
	((_bfa)->modules.fcp_mod.fcpim.io_profile_start_time)
K
Krishna Gudipati 已提交
245
#define bfa_fcpim_get_io_profile(_bfa)	\
246
	((_bfa)->modules.fcp_mod.fcpim.io_profile)
247 248 249 250 251
#define bfa_ioim_update_iotag(__ioim) do {				\
	uint16_t k = (__ioim)->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;	\
	k++; (__ioim)->iotag &= BFA_IOIM_IOTAG_MASK;			\
	(__ioim)->iotag |= k << BFA_IOIM_RETRY_TAG_OFFSET;		\
} while (0)
K
Krishna Gudipati 已提交
252 253

static inline bfa_boolean_t
254
bfa_ioim_maxretry_reached(struct bfa_ioim_s *ioim)
K
Krishna Gudipati 已提交
255
{
256 257
	uint16_t k = ioim->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;
	if (k < BFA_IOIM_RETRY_MAX)
K
Krishna Gudipati 已提交
258 259 260
		return BFA_FALSE;
	return BFA_TRUE;
}
261

K
Krishna Gudipati 已提交
262 263 264
/*
 * function prototypes
 */
265
void	bfa_ioim_attach(struct bfa_fcpim_s *fcpim);
K
Krishna Gudipati 已提交
266 267 268 269 270 271 272 273 274
void	bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
void	bfa_ioim_good_comp_isr(struct bfa_s *bfa,
					struct bfi_msg_s *msg);
void	bfa_ioim_cleanup(struct bfa_ioim_s *ioim);
void	bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim,
					struct bfa_tskim_s *tskim);
void	bfa_ioim_iocdisable(struct bfa_ioim_s *ioim);
void	bfa_ioim_tov(struct bfa_ioim_s *ioim);

275
void	bfa_tskim_attach(struct bfa_fcpim_s *fcpim);
K
Krishna Gudipati 已提交
276 277 278 279
void	bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
void	bfa_tskim_iodone(struct bfa_tskim_s *tskim);
void	bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
void	bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
280
void	bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
K
Krishna Gudipati 已提交
281

282 283
void	bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len);
void	bfa_itnim_attach(struct bfa_fcpim_s *fcpim);
K
Krishna Gudipati 已提交
284 285 286 287 288 289 290 291 292
void	bfa_itnim_iocdisable(struct bfa_itnim_s *itnim);
void	bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
void	bfa_itnim_iodone(struct bfa_itnim_s *itnim);
void	bfa_itnim_tskdone(struct bfa_itnim_s *itnim);
bfa_boolean_t   bfa_itnim_hold_io(struct bfa_itnim_s *itnim);

/*
 * bfa fcpim module API functions
 */
293
void	bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov);
K
Krishna Gudipati 已提交
294 295
u16	bfa_fcpim_path_tov_get(struct bfa_s *bfa);
u16	bfa_fcpim_qdepth_get(struct bfa_s *bfa);
296 297 298 299
bfa_status_t bfa_fcpim_port_iostats(struct bfa_s *bfa,
			struct bfa_itnim_iostats_s *stats, u8 lp_tag);
void bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *fcpim_stats,
			struct bfa_itnim_iostats_s *itnim_stats);
300

K
Krishna Gudipati 已提交
301
#define bfa_fcpim_ioredirect_enabled(__bfa)				\
302
	(((struct bfa_fcpim_s *)(BFA_FCPIM(__bfa)))->ioredirect)
K
Krishna Gudipati 已提交
303 304 305

#define bfa_fcpim_get_next_reqq(__bfa, __qid)				\
{									\
306
	struct bfa_fcpim_s *__fcpim = BFA_FCPIM(__bfa);      \
K
Krishna Gudipati 已提交
307 308 309 310 311 312 313 314 315 316 317
	__fcpim->reqq++;						\
	__fcpim->reqq &= (BFI_IOC_MAX_CQS - 1);      \
	*(__qid) = __fcpim->reqq;					\
}

#define bfa_iocfc_map_msg_to_qid(__msg, __qid)				\
	*(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
/*
 * bfa itnim API functions
 */
struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa,
318 319 320 321 322 323 324 325
		struct bfa_rport_s *rport, void *itnim);
void bfa_itnim_delete(struct bfa_itnim_s *itnim);
void bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec);
void bfa_itnim_offline(struct bfa_itnim_s *itnim);
void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim);
bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
			struct bfa_itnim_ioprofile_s *ioprofile);

K
Krishna Gudipati 已提交
326 327
#define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)

328
/*
329
 * BFA completion callback for bfa_itnim_online().
K
Krishna Gudipati 已提交
330 331 332
 */
void	bfa_cb_itnim_online(void *itnim);

333
/*
334
 * BFA completion callback for bfa_itnim_offline().
K
Krishna Gudipati 已提交
335 336 337 338 339
 */
void	bfa_cb_itnim_offline(void *itnim);
void	bfa_cb_itnim_tov_begin(void *itnim);
void	bfa_cb_itnim_tov(void *itnim);

340
/*
341
 * BFA notification to FCS/driver for second level error recovery.
K
Krishna Gudipati 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
 * Atleast one I/O request has timedout and target is unresponsive to
 * repeated abort requests. Second level error recovery should be initiated
 * by starting implicit logout and recovery procedures.
 */
void	bfa_cb_itnim_sler(void *itnim);

/*
 * bfa ioim API functions
 */
struct bfa_ioim_s	*bfa_ioim_alloc(struct bfa_s *bfa,
					struct bfad_ioim_s *dio,
					struct bfa_itnim_s *itnim,
					u16 nsgles);

void		bfa_ioim_free(struct bfa_ioim_s *ioim);
void		bfa_ioim_start(struct bfa_ioim_s *ioim);
bfa_status_t	bfa_ioim_abort(struct bfa_ioim_s *ioim);
void		bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
				      bfa_boolean_t iotov);
361
/*
362
 * I/O completion notification.
K
Krishna Gudipati 已提交
363 364 365 366 367 368 369 370 371 372
 *
 * @param[in]		dio			driver IO structure
 * @param[in]		io_status		IO completion status
 * @param[in]		scsi_status		SCSI status returned by target
 * @param[in]		sns_len			SCSI sense length, 0 if none
 * @param[in]		sns_info		SCSI sense data, if any
 * @param[in]		residue			Residual length
 *
 * @return None
 */
373 374 375 376
void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
			enum bfi_ioim_status io_status,
			u8 scsi_status, int sns_len,
			u8 *sns_info, s32 residue);
K
Krishna Gudipati 已提交
377

378
/*
379
 * I/O good completion notification.
K
Krishna Gudipati 已提交
380
 */
381
void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
K
Krishna Gudipati 已提交
382

383
/*
384
 * I/O abort completion notification
K
Krishna Gudipati 已提交
385
 */
386
void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio);
K
Krishna Gudipati 已提交
387 388 389 390

/*
 * bfa tskim API functions
 */
391 392 393 394 395 396 397 398
struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa,
			struct bfad_tskim_s *dtsk);
void bfa_tskim_free(struct bfa_tskim_s *tskim);
void bfa_tskim_start(struct bfa_tskim_s *tskim,
			struct bfa_itnim_s *itnim, struct scsi_lun lun,
			enum fcp_tm_cmnd tm, u8 t_secs);
void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
			enum bfi_tskim_status tsk_status);
K
Krishna Gudipati 已提交
399 400

#endif /* __BFA_FCPIM_H__ */