xref: /openbmc/linux/drivers/scsi/bfa/bfad_im.h (revision 6d4bc344)
17725ccfdSJing Huang /*
2889d0d42SAnil Gurumurthy  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3889d0d42SAnil Gurumurthy  * Copyright (c) 2014- QLogic Corporation.
47725ccfdSJing Huang  * All rights reserved
5889d0d42SAnil Gurumurthy  * www.qlogic.com
67725ccfdSJing Huang  *
731e1d569SAnil Gurumurthy  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
87725ccfdSJing Huang  *
97725ccfdSJing Huang  * This program is free software; you can redistribute it and/or modify it
107725ccfdSJing Huang  * under the terms of the GNU General Public License (GPL) Version 2 as
117725ccfdSJing Huang  * published by the Free Software Foundation
127725ccfdSJing Huang  *
137725ccfdSJing Huang  * This program is distributed in the hope that it will be useful, but
147725ccfdSJing Huang  * WITHOUT ANY WARRANTY; without even the implied warranty of
157725ccfdSJing Huang  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
167725ccfdSJing Huang  * General Public License for more details.
177725ccfdSJing Huang  */
187725ccfdSJing Huang 
197725ccfdSJing Huang #ifndef __BFAD_IM_H__
207725ccfdSJing Huang #define __BFAD_IM_H__
217725ccfdSJing Huang 
22a36c61f9SKrishna Gudipati #include "bfa_fcs.h"
237725ccfdSJing Huang 
247725ccfdSJing Huang #define FCPI_NAME " fcpim"
257725ccfdSJing Huang 
26a36c61f9SKrishna Gudipati #ifndef KOBJ_NAME_LEN
27a36c61f9SKrishna Gudipati #define KOBJ_NAME_LEN           20
28a36c61f9SKrishna Gudipati #endif
29a36c61f9SKrishna Gudipati 
307725ccfdSJing Huang bfa_status_t bfad_im_module_init(void);
317725ccfdSJing Huang void bfad_im_module_exit(void);
327725ccfdSJing Huang bfa_status_t bfad_im_probe(struct bfad_s *bfad);
337725ccfdSJing Huang void bfad_im_probe_undo(struct bfad_s *bfad);
347725ccfdSJing Huang bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
357725ccfdSJing Huang void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
367725ccfdSJing Huang void bfad_im_port_clean(struct bfad_im_port_s *im_port);
377725ccfdSJing Huang int  bfad_im_scsi_host_alloc(struct bfad_s *bfad,
38b504293fSJing Huang 		struct bfad_im_port_s *im_port, struct device *dev);
397725ccfdSJing Huang void bfad_im_scsi_host_free(struct bfad_s *bfad,
407725ccfdSJing Huang 				struct bfad_im_port_s *im_port);
416192bd7cSKrishna Gudipati u32 bfad_im_supported_speeds(struct bfa_s *bfa);
427725ccfdSJing Huang 
437725ccfdSJing Huang #define MAX_FCP_TARGET 1024
447725ccfdSJing Huang #define MAX_FCP_LUN 16384
457725ccfdSJing Huang #define BFAD_TARGET_RESET_TMO 60
467725ccfdSJing Huang #define BFAD_LUN_RESET_TMO 60
477725ccfdSJing Huang #define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
487725ccfdSJing Huang #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
497725ccfdSJing Huang 
507725ccfdSJing Huang /*
517725ccfdSJing Huang  * itnim flags
527725ccfdSJing Huang  */
537725ccfdSJing Huang #define IO_DONE_BIT			0
547725ccfdSJing Huang 
557725ccfdSJing Huang struct bfad_itnim_data_s {
567725ccfdSJing Huang 	struct bfad_itnim_s *itnim;
577725ccfdSJing Huang };
587725ccfdSJing Huang 
597725ccfdSJing Huang struct bfad_im_port_s {
607725ccfdSJing Huang 	struct bfad_s         *bfad;
617725ccfdSJing Huang 	struct bfad_port_s    *port;
627725ccfdSJing Huang 	struct work_struct port_delete_work;
637725ccfdSJing Huang 	int             idr_id;
647725ccfdSJing Huang 	u16        cur_scsi_id;
65b504293fSJing Huang 	u16	flags;
667725ccfdSJing Huang 	struct list_head binding_list;
677725ccfdSJing Huang 	struct Scsi_Host *shost;
687725ccfdSJing Huang 	struct list_head itnim_mapped_list;
69b504293fSJing Huang 	struct fc_vport *fc_vport;
707725ccfdSJing Huang };
717725ccfdSJing Huang 
727725ccfdSJing Huang enum bfad_itnim_state {
737725ccfdSJing Huang 	ITNIM_STATE_NONE,
747725ccfdSJing Huang 	ITNIM_STATE_ONLINE,
757725ccfdSJing Huang 	ITNIM_STATE_OFFLINE_PENDING,
767725ccfdSJing Huang 	ITNIM_STATE_OFFLINE,
777725ccfdSJing Huang 	ITNIM_STATE_TIMEOUT,
787725ccfdSJing Huang 	ITNIM_STATE_FREE,
797725ccfdSJing Huang };
807725ccfdSJing Huang 
817725ccfdSJing Huang /*
827725ccfdSJing Huang  * Per itnim data structure
837725ccfdSJing Huang  */
847725ccfdSJing Huang struct bfad_itnim_s {
857725ccfdSJing Huang 	struct list_head list_entry;
867725ccfdSJing Huang 	struct bfa_fcs_itnim_s fcs_itnim;
877725ccfdSJing Huang 	struct work_struct itnim_work;
887725ccfdSJing Huang 	u32        flags;
897725ccfdSJing Huang 	enum bfad_itnim_state state;
907725ccfdSJing Huang 	struct bfad_im_s *im;
917725ccfdSJing Huang 	struct bfad_im_port_s *im_port;
927725ccfdSJing Huang 	struct bfad_rport_s *drv_rport;
937725ccfdSJing Huang 	struct fc_rport *fc_rport;
947725ccfdSJing Huang 	struct bfa_itnim_s *bfa_itnim;
957725ccfdSJing Huang 	u16        scsi_tgt_id;
965b7db7afSKrishna Gudipati 	u16	   channel;
977725ccfdSJing Huang 	u16        queue_work;
987725ccfdSJing Huang 	unsigned long	last_ramp_up_time;
997725ccfdSJing Huang 	unsigned long	last_queue_full_time;
1007725ccfdSJing Huang };
1017725ccfdSJing Huang 
1027725ccfdSJing Huang enum bfad_binding_type {
1037725ccfdSJing Huang 	FCP_PWWN_BINDING = 0x1,
1047725ccfdSJing Huang 	FCP_NWWN_BINDING = 0x2,
1057725ccfdSJing Huang 	FCP_FCID_BINDING = 0x3,
1067725ccfdSJing Huang };
1077725ccfdSJing Huang 
1087725ccfdSJing Huang struct bfad_fcp_binding {
1097725ccfdSJing Huang 	struct list_head list_entry;
1107725ccfdSJing Huang 	enum bfad_binding_type binding_type;
1117725ccfdSJing Huang 	u16        scsi_target_id;
1127725ccfdSJing Huang 	u32        fc_id;
1137725ccfdSJing Huang 	wwn_t           nwwn;
1147725ccfdSJing Huang 	wwn_t           pwwn;
1157725ccfdSJing Huang };
1167725ccfdSJing Huang 
1177725ccfdSJing Huang struct bfad_im_s {
1187725ccfdSJing Huang 	struct bfad_s         *bfad;
1197725ccfdSJing Huang 	struct workqueue_struct *drv_workq;
120a36c61f9SKrishna Gudipati 	char            drv_workq_name[KOBJ_NAME_LEN];
1217826f304SKrishna Gudipati 	struct work_struct	aen_im_notify_work;
1227725ccfdSJing Huang };
1237725ccfdSJing Huang 
1247826f304SKrishna Gudipati #define bfad_get_aen_entry(_drv, _entry) do {				\
1257826f304SKrishna Gudipati 	unsigned long	_flags;						\
1267826f304SKrishna Gudipati 	spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags);		\
1277826f304SKrishna Gudipati 	bfa_q_deq(&(_drv)->free_aen_q, &(_entry));			\
1287826f304SKrishna Gudipati 	if (_entry)							\
1297826f304SKrishna Gudipati 		list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q);	\
1307826f304SKrishna Gudipati 	spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags);	\
1317826f304SKrishna Gudipati } while (0)
1327826f304SKrishna Gudipati 
1337826f304SKrishna Gudipati /* post fc_host vendor event */
1346d4bc344SArnd Bergmann static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
1356d4bc344SArnd Bergmann 					     struct bfad_s *drv, int cnt,
1366d4bc344SArnd Bergmann 					     enum bfa_aen_category cat,
1376d4bc344SArnd Bergmann 					     enum bfa_ioc_aen_event evt)
1386d4bc344SArnd Bergmann {
1396d4bc344SArnd Bergmann 	struct timespec64 ts;
1406d4bc344SArnd Bergmann 
1416d4bc344SArnd Bergmann 	ktime_get_real_ts64(&ts);
1426d4bc344SArnd Bergmann 	/*
1436d4bc344SArnd Bergmann 	 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
1446d4bc344SArnd Bergmann 	 * architectures, or in 2038 if user space interprets it
1456d4bc344SArnd Bergmann 	 * as 'signed'.
1466d4bc344SArnd Bergmann 	 */
1476d4bc344SArnd Bergmann 	entry->aen_tv_sec = ts.tv_sec;
1486d4bc344SArnd Bergmann 	entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
1496d4bc344SArnd Bergmann 	entry->bfad_num = drv->inst_no;
1506d4bc344SArnd Bergmann 	entry->seq_num = cnt;
1516d4bc344SArnd Bergmann 	entry->aen_category = cat;
1526d4bc344SArnd Bergmann 	entry->aen_type = evt;
1536d4bc344SArnd Bergmann 	if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
1546d4bc344SArnd Bergmann 		queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
1556d4bc344SArnd Bergmann }
1567826f304SKrishna Gudipati 
157f16a1750SMaggie Zhang struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
1587725ccfdSJing Huang 				struct bfad_s *);
159f16a1750SMaggie Zhang bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
160f16a1750SMaggie Zhang void bfad_destroy_workq(struct bfad_im_s *im);
161f16a1750SMaggie Zhang void bfad_fc_host_init(struct bfad_im_port_s *im_port);
162f16a1750SMaggie Zhang void bfad_scsi_host_free(struct bfad_s *bfad,
1637725ccfdSJing Huang 				 struct bfad_im_port_s *im_port);
164f16a1750SMaggie Zhang void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
1657725ccfdSJing Huang 				 struct scsi_device *sdev);
166f16a1750SMaggie Zhang void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
167f16a1750SMaggie Zhang struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
1687725ccfdSJing Huang 
1697725ccfdSJing Huang extern struct scsi_host_template bfad_im_scsi_host_template;
1707725ccfdSJing Huang extern struct scsi_host_template bfad_im_vport_template;
1717725ccfdSJing Huang extern struct fc_function_template bfad_im_fc_function_template;
172b504293fSJing Huang extern struct fc_function_template bfad_im_vport_fc_function_template;
1737725ccfdSJing Huang extern struct scsi_transport_template *bfad_im_scsi_transport_template;
174b504293fSJing Huang extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
1757725ccfdSJing Huang 
176a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_host_attrs[];
177a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_vport_attrs[];
178a36c61f9SKrishna Gudipati 
179a36c61f9SKrishna Gudipati irqreturn_t bfad_intx(int irq, void *dev_id);
180a36c61f9SKrishna Gudipati 
18175cc8cfcSJohannes Thumshirn int bfad_im_bsg_request(struct bsg_job *job);
18275cc8cfcSJohannes Thumshirn int bfad_im_bsg_timeout(struct bsg_job *job);
183b85daafeSKrishna Gudipati 
1845b7db7afSKrishna Gudipati /*
1855b7db7afSKrishna Gudipati  * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
1865b7db7afSKrishna Gudipati  * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
1875b7db7afSKrishna Gudipati  *
1885b7db7afSKrishna Gudipati  * Internally iterate's over all the ITNIM's part of the im_port & set's the
1895b7db7afSKrishna Gudipati  * sdev_bflags for the scsi_device associated with LUN #0.
1905b7db7afSKrishna Gudipati  */
1915b7db7afSKrishna Gudipati #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do {		\
1925b7db7afSKrishna Gudipati 	struct scsi_device *__sdev = NULL;				\
1935b7db7afSKrishna Gudipati 	struct bfad_itnim_s *__itnim = NULL;				\
1945b7db7afSKrishna Gudipati 	u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN;		\
1955b7db7afSKrishna Gudipati 	list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list),	\
1965b7db7afSKrishna Gudipati 			    list_entry) {				\
1975b7db7afSKrishna Gudipati 		__sdev = scsi_device_lookup((__im_port)->shost,		\
1985b7db7afSKrishna Gudipati 					    __itnim->channel,		\
1995b7db7afSKrishna Gudipati 					    __itnim->scsi_tgt_id, 0);	\
2005b7db7afSKrishna Gudipati 		if (__sdev) {						\
2015b7db7afSKrishna Gudipati 			if ((__lunmask_cfg) == BFA_TRUE)		\
2025b7db7afSKrishna Gudipati 				__sdev->sdev_bflags |= scan_flags;	\
2035b7db7afSKrishna Gudipati 			else						\
2045b7db7afSKrishna Gudipati 				__sdev->sdev_bflags &= ~scan_flags;	\
2055b7db7afSKrishna Gudipati 			scsi_device_put(__sdev);			\
2065b7db7afSKrishna Gudipati 		}							\
2075b7db7afSKrishna Gudipati 	}								\
2085b7db7afSKrishna Gudipati } while (0)
2095b7db7afSKrishna Gudipati 
2107725ccfdSJing Huang #endif
211