xref: /openbmc/linux/drivers/scsi/bfa/bfad_im.h (revision a36c61f9)
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];
1187725ccfdSJing Huang };
1197725ccfdSJing Huang 
1207725ccfdSJing Huang struct Scsi_Host *bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port,
1217725ccfdSJing Huang 				struct bfad_s *);
1227725ccfdSJing Huang bfa_status_t bfad_os_thread_workq(struct bfad_s *bfad);
1237725ccfdSJing Huang void bfad_os_destroy_workq(struct bfad_im_s *im);
1247725ccfdSJing Huang void bfad_os_fc_host_init(struct bfad_im_port_s *im_port);
1257725ccfdSJing Huang void bfad_os_scsi_host_free(struct bfad_s *bfad,
1267725ccfdSJing Huang 				 struct bfad_im_port_s *im_port);
1277725ccfdSJing Huang void bfad_os_ramp_up_qdepth(struct bfad_itnim_s *itnim,
1287725ccfdSJing Huang 				 struct scsi_device *sdev);
1297725ccfdSJing Huang void bfad_os_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
1307725ccfdSJing Huang struct bfad_itnim_s *bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id);
1317725ccfdSJing Huang 
1327725ccfdSJing Huang extern struct scsi_host_template bfad_im_scsi_host_template;
1337725ccfdSJing Huang extern struct scsi_host_template bfad_im_vport_template;
1347725ccfdSJing Huang extern struct fc_function_template bfad_im_fc_function_template;
135b504293fSJing Huang extern struct fc_function_template bfad_im_vport_fc_function_template;
1367725ccfdSJing Huang extern struct scsi_transport_template *bfad_im_scsi_transport_template;
137b504293fSJing Huang extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
1387725ccfdSJing Huang 
139a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_host_attrs[];
140a36c61f9SKrishna Gudipati extern struct device_attribute *bfad_im_vport_attrs[];
141a36c61f9SKrishna Gudipati 
142a36c61f9SKrishna Gudipati irqreturn_t bfad_intx(int irq, void *dev_id);
143a36c61f9SKrishna Gudipati 
144a36c61f9SKrishna Gudipati /* Firmware releated */
145a36c61f9SKrishna Gudipati #define BFAD_FW_FILE_CT_FC      "ctfw_fc.bin"
146a36c61f9SKrishna Gudipati #define BFAD_FW_FILE_CT_CNA     "ctfw_cna.bin"
147a36c61f9SKrishna Gudipati #define BFAD_FW_FILE_CB_FC      "cbfw_fc.bin"
148a36c61f9SKrishna Gudipati 
149a36c61f9SKrishna Gudipati u32 *bfad_get_firmware_buf(struct pci_dev *pdev);
150a36c61f9SKrishna Gudipati u32 *bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
151a36c61f9SKrishna Gudipati 		u32 *bfi_image_size, char *fw_name);
152a36c61f9SKrishna Gudipati 
153a36c61f9SKrishna Gudipati static inline u32 *
154a36c61f9SKrishna Gudipati bfad_load_fwimg(struct pci_dev *pdev)
155a36c61f9SKrishna Gudipati {
156a36c61f9SKrishna Gudipati 	return bfad_get_firmware_buf(pdev);
157a36c61f9SKrishna Gudipati }
158a36c61f9SKrishna Gudipati 
159a36c61f9SKrishna Gudipati static inline void
160a36c61f9SKrishna Gudipati bfad_free_fwimg(void)
161a36c61f9SKrishna Gudipati {
162a36c61f9SKrishna Gudipati 	if (bfi_image_ct_fc_size && bfi_image_ct_fc)
163a36c61f9SKrishna Gudipati 		vfree(bfi_image_ct_fc);
164a36c61f9SKrishna Gudipati 	if (bfi_image_ct_cna_size && bfi_image_ct_cna)
165a36c61f9SKrishna Gudipati 		vfree(bfi_image_ct_cna);
166a36c61f9SKrishna Gudipati 	if (bfi_image_cb_fc_size && bfi_image_cb_fc)
167a36c61f9SKrishna Gudipati 		vfree(bfi_image_cb_fc);
168a36c61f9SKrishna Gudipati }
1697725ccfdSJing Huang #endif
170