xref: /openbmc/linux/drivers/scsi/bfa/bfad_im.h (revision 7826f304)
17725ccfdSJing Huang /*
2a36c61f9SKrishna Gudipati  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
37725ccfdSJing Huang  * All rights reserved
47725ccfdSJing Huang  * www.brocade.com
57725ccfdSJing Huang  *
67725ccfdSJing Huang  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
77725ccfdSJing Huang  *
87725ccfdSJing Huang  * This program is free software; you can redistribute it and/or modify it
97725ccfdSJing Huang  * under the terms of the GNU General Public License (GPL) Version 2 as
107725ccfdSJing Huang  * published by the Free Software Foundation
117725ccfdSJing Huang  *
127725ccfdSJing Huang  * This program is distributed in the hope that it will be useful, but
137725ccfdSJing Huang  * WITHOUT ANY WARRANTY; without even the implied warranty of
147725ccfdSJing Huang  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
157725ccfdSJing Huang  * General Public License for more details.
167725ccfdSJing Huang  */
177725ccfdSJing Huang 
187725ccfdSJing Huang #ifndef __BFAD_IM_H__
197725ccfdSJing Huang #define __BFAD_IM_H__
207725ccfdSJing Huang 
21a36c61f9SKrishna Gudipati #include "bfa_fcs.h"
227725ccfdSJing Huang 
237725ccfdSJing Huang #define FCPI_NAME " fcpim"
247725ccfdSJing Huang 
25a36c61f9SKrishna Gudipati #ifndef KOBJ_NAME_LEN
26a36c61f9SKrishna Gudipati #define KOBJ_NAME_LEN           20
27a36c61f9SKrishna Gudipati #endif
28a36c61f9SKrishna Gudipati 
297725ccfdSJing Huang bfa_status_t bfad_im_module_init(void);
307725ccfdSJing Huang void bfad_im_module_exit(void);
317725ccfdSJing Huang bfa_status_t bfad_im_probe(struct bfad_s *bfad);
327725ccfdSJing Huang void bfad_im_probe_undo(struct bfad_s *bfad);
337725ccfdSJing Huang bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
347725ccfdSJing Huang void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
357725ccfdSJing Huang void bfad_im_port_clean(struct bfad_im_port_s *im_port);
367725ccfdSJing Huang int  bfad_im_scsi_host_alloc(struct bfad_s *bfad,
37b504293fSJing Huang 		struct bfad_im_port_s *im_port, struct device *dev);
387725ccfdSJing Huang void bfad_im_scsi_host_free(struct bfad_s *bfad,
397725ccfdSJing Huang 				struct bfad_im_port_s *im_port);
407725ccfdSJing Huang 
417725ccfdSJing Huang #define MAX_FCP_TARGET 1024
427725ccfdSJing Huang #define MAX_FCP_LUN 16384
437725ccfdSJing Huang #define BFAD_TARGET_RESET_TMO 60
447725ccfdSJing Huang #define BFAD_LUN_RESET_TMO 60
457725ccfdSJing Huang #define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
467725ccfdSJing Huang #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
477725ccfdSJing Huang 
487725ccfdSJing Huang /*
497725ccfdSJing Huang  * itnim flags
507725ccfdSJing Huang  */
517725ccfdSJing Huang #define IO_DONE_BIT			0
527725ccfdSJing Huang 
537725ccfdSJing Huang struct bfad_itnim_data_s {
547725ccfdSJing Huang 	struct bfad_itnim_s *itnim;
557725ccfdSJing Huang };
567725ccfdSJing Huang 
577725ccfdSJing Huang struct bfad_im_port_s {
587725ccfdSJing Huang 	struct bfad_s         *bfad;
597725ccfdSJing Huang 	struct bfad_port_s    *port;
607725ccfdSJing Huang 	struct work_struct port_delete_work;
617725ccfdSJing Huang 	int             idr_id;
627725ccfdSJing Huang 	u16        cur_scsi_id;
63b504293fSJing Huang 	u16	flags;
647725ccfdSJing Huang 	struct list_head binding_list;
657725ccfdSJing Huang 	struct Scsi_Host *shost;
667725ccfdSJing Huang 	struct list_head itnim_mapped_list;
67b504293fSJing Huang 	struct fc_vport *fc_vport;
687725ccfdSJing Huang };
697725ccfdSJing Huang 
707725ccfdSJing Huang enum bfad_itnim_state {
717725ccfdSJing Huang 	ITNIM_STATE_NONE,
727725ccfdSJing Huang 	ITNIM_STATE_ONLINE,
737725ccfdSJing Huang 	ITNIM_STATE_OFFLINE_PENDING,
747725ccfdSJing Huang 	ITNIM_STATE_OFFLINE,
757725ccfdSJing Huang 	ITNIM_STATE_TIMEOUT,
767725ccfdSJing Huang 	ITNIM_STATE_FREE,
777725ccfdSJing Huang };
787725ccfdSJing Huang 
797725ccfdSJing Huang /*
807725ccfdSJing Huang  * Per itnim data structure
817725ccfdSJing Huang  */
827725ccfdSJing Huang struct bfad_itnim_s {
837725ccfdSJing Huang 	struct list_head list_entry;
847725ccfdSJing Huang 	struct bfa_fcs_itnim_s fcs_itnim;
857725ccfdSJing Huang 	struct work_struct itnim_work;
867725ccfdSJing Huang 	u32        flags;
877725ccfdSJing Huang 	enum bfad_itnim_state state;
887725ccfdSJing Huang 	struct bfad_im_s *im;
897725ccfdSJing Huang 	struct bfad_im_port_s *im_port;
907725ccfdSJing Huang 	struct bfad_rport_s *drv_rport;
917725ccfdSJing Huang 	struct fc_rport *fc_rport;
927725ccfdSJing Huang 	struct bfa_itnim_s *bfa_itnim;
937725ccfdSJing Huang 	u16        scsi_tgt_id;
947725ccfdSJing Huang 	u16        queue_work;
957725ccfdSJing Huang 	unsigned long	last_ramp_up_time;
967725ccfdSJing Huang 	unsigned long	last_queue_full_time;
977725ccfdSJing Huang };
987725ccfdSJing Huang 
997725ccfdSJing Huang enum bfad_binding_type {
1007725ccfdSJing Huang 	FCP_PWWN_BINDING = 0x1,
1017725ccfdSJing Huang 	FCP_NWWN_BINDING = 0x2,
1027725ccfdSJing Huang 	FCP_FCID_BINDING = 0x3,
1037725ccfdSJing Huang };
1047725ccfdSJing Huang 
1057725ccfdSJing Huang struct bfad_fcp_binding {
1067725ccfdSJing Huang 	struct list_head list_entry;
1077725ccfdSJing Huang 	enum bfad_binding_type binding_type;
1087725ccfdSJing Huang 	u16        scsi_target_id;
1097725ccfdSJing Huang 	u32        fc_id;
1107725ccfdSJing Huang 	wwn_t           nwwn;
1117725ccfdSJing Huang 	wwn_t           pwwn;
1127725ccfdSJing Huang };
1137725ccfdSJing Huang 
1147725ccfdSJing Huang struct bfad_im_s {
1157725ccfdSJing Huang 	struct bfad_s         *bfad;
1167725ccfdSJing Huang 	struct workqueue_struct *drv_workq;
117a36c61f9SKrishna Gudipati 	char            drv_workq_name[KOBJ_NAME_LEN];
1187826f304SKrishna Gudipati 	struct work_struct	aen_im_notify_work;
1197725ccfdSJing Huang };
1207725ccfdSJing Huang 
1217826f304SKrishna Gudipati #define bfad_get_aen_entry(_drv, _entry) do {				\
1227826f304SKrishna Gudipati 	unsigned long	_flags;						\
1237826f304SKrishna Gudipati 	spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags);		\
1247826f304SKrishna Gudipati 	bfa_q_deq(&(_drv)->free_aen_q, &(_entry));			\
1257826f304SKrishna Gudipati 	if (_entry)							\
1267826f304SKrishna Gudipati 		list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q);	\
1277826f304SKrishna Gudipati 	spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags);	\
1287826f304SKrishna Gudipati } while (0)
1297826f304SKrishna Gudipati 
1307826f304SKrishna Gudipati /* post fc_host vendor event */
1317826f304SKrishna Gudipati #define bfad_im_post_vendor_event(_entry, _drv, _cnt, _cat, _evt) do {	      \
1327826f304SKrishna Gudipati 	do_gettimeofday(&(_entry)->aen_tv);				      \
1337826f304SKrishna Gudipati 	(_entry)->bfad_num = (_drv)->inst_no;				      \
1347826f304SKrishna Gudipati 	(_entry)->seq_num = (_cnt);					      \
1357826f304SKrishna Gudipati 	(_entry)->aen_category = (_cat);				      \
1367826f304SKrishna Gudipati 	(_entry)->aen_type = (_evt);					      \
1377826f304SKrishna Gudipati 	if ((_drv)->bfad_flags & BFAD_FC4_PROBE_DONE)			      \
1387826f304SKrishna Gudipati 		queue_work((_drv)->im->drv_workq,			      \
1397826f304SKrishna Gudipati 			   &(_drv)->im->aen_im_notify_work);		      \
1407826f304SKrishna Gudipati } while (0)
1417826f304SKrishna Gudipati 
142f16a1750SMaggie Zhang struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
1437725ccfdSJing Huang 				struct bfad_s *);
144f16a1750SMaggie Zhang bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
145f16a1750SMaggie Zhang void bfad_destroy_workq(struct bfad_im_s *im);
146f16a1750SMaggie Zhang void bfad_fc_host_init(struct bfad_im_port_s *im_port);
147f16a1750SMaggie Zhang void bfad_scsi_host_free(struct bfad_s *bfad,
1487725ccfdSJing Huang 				 struct bfad_im_port_s *im_port);
149f16a1750SMaggie Zhang void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
1507725ccfdSJing Huang 				 struct scsi_device *sdev);
151f16a1750SMaggie Zhang void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
152f16a1750SMaggie Zhang struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
1537725ccfdSJing Huang 
1547725ccfdSJing Huang extern struct scsi_host_template bfad_im_scsi_host_template;
1557725ccfdSJing Huang extern struct scsi_host_template bfad_im_vport_template;
1567725ccfdSJing Huang extern struct fc_function_template bfad_im_fc_function_template;
157b504293fSJing Huang extern struct fc_function_template bfad_im_vport_fc_function_template;
1587725ccfdSJing Huang extern struct scsi_transport_template *bfad_im_scsi_transport_template;
159b504293fSJing Huang extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
1607725ccfdSJing Huang 
161a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_host_attrs[];
162a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_vport_attrs[];
163a36c61f9SKrishna Gudipati 
164a36c61f9SKrishna Gudipati irqreturn_t bfad_intx(int irq, void *dev_id);
165a36c61f9SKrishna Gudipati 
166b85daafeSKrishna Gudipati int bfad_im_bsg_request(struct fc_bsg_job *job);
167b85daafeSKrishna Gudipati int bfad_im_bsg_timeout(struct fc_bsg_job *job);
168b85daafeSKrishna Gudipati 
1697725ccfdSJing Huang #endif
170