Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 2 | * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. |
| 3 | * Copyright (c) 2014- QLogic Corporation. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 4 | * All rights reserved |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 5 | * www.qlogic.com |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 6 | * |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 7 | * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 11 | * published by the Free Software Foundation |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __BFAD_IM_H__ |
| 20 | #define __BFAD_IM_H__ |
| 21 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 22 | #include "bfa_fcs.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 23 | |
| 24 | #define FCPI_NAME " fcpim" |
| 25 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 26 | #ifndef KOBJ_NAME_LEN |
| 27 | #define KOBJ_NAME_LEN 20 |
| 28 | #endif |
| 29 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 30 | bfa_status_t bfad_im_module_init(void); |
| 31 | void bfad_im_module_exit(void); |
| 32 | bfa_status_t bfad_im_probe(struct bfad_s *bfad); |
| 33 | void bfad_im_probe_undo(struct bfad_s *bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 34 | bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port); |
| 35 | void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 36 | void bfad_im_port_clean(struct bfad_im_port_s *im_port); |
| 37 | int bfad_im_scsi_host_alloc(struct bfad_s *bfad, |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 38 | struct bfad_im_port_s *im_port, struct device *dev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 39 | void bfad_im_scsi_host_free(struct bfad_s *bfad, |
| 40 | struct bfad_im_port_s *im_port); |
Krishna Gudipati | 6192bd7 | 2012-05-11 17:49:59 -0700 | [diff] [blame] | 41 | u32 bfad_im_supported_speeds(struct bfa_s *bfa); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 42 | |
| 43 | #define MAX_FCP_TARGET 1024 |
| 44 | #define MAX_FCP_LUN 16384 |
| 45 | #define BFAD_TARGET_RESET_TMO 60 |
| 46 | #define BFAD_LUN_RESET_TMO 60 |
| 47 | #define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code) |
| 48 | #define BFA_QUEUE_FULL_RAMP_UP_TIME 120 |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * itnim flags |
| 52 | */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 53 | #define IO_DONE_BIT 0 |
| 54 | |
| 55 | struct bfad_itnim_data_s { |
| 56 | struct bfad_itnim_s *itnim; |
| 57 | }; |
| 58 | |
| 59 | struct bfad_im_port_s { |
| 60 | struct bfad_s *bfad; |
| 61 | struct bfad_port_s *port; |
| 62 | struct work_struct port_delete_work; |
| 63 | int idr_id; |
| 64 | u16 cur_scsi_id; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 65 | u16 flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 66 | struct list_head binding_list; |
| 67 | struct Scsi_Host *shost; |
| 68 | struct list_head itnim_mapped_list; |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 69 | struct fc_vport *fc_vport; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | enum bfad_itnim_state { |
| 73 | ITNIM_STATE_NONE, |
| 74 | ITNIM_STATE_ONLINE, |
| 75 | ITNIM_STATE_OFFLINE_PENDING, |
| 76 | ITNIM_STATE_OFFLINE, |
| 77 | ITNIM_STATE_TIMEOUT, |
| 78 | ITNIM_STATE_FREE, |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * Per itnim data structure |
| 83 | */ |
| 84 | struct bfad_itnim_s { |
| 85 | struct list_head list_entry; |
| 86 | struct bfa_fcs_itnim_s fcs_itnim; |
| 87 | struct work_struct itnim_work; |
| 88 | u32 flags; |
| 89 | enum bfad_itnim_state state; |
| 90 | struct bfad_im_s *im; |
| 91 | struct bfad_im_port_s *im_port; |
| 92 | struct bfad_rport_s *drv_rport; |
| 93 | struct fc_rport *fc_rport; |
| 94 | struct bfa_itnim_s *bfa_itnim; |
| 95 | u16 scsi_tgt_id; |
Krishna Gudipati | 5b7db7a | 2011-12-20 18:58:32 -0800 | [diff] [blame] | 96 | u16 channel; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 97 | u16 queue_work; |
| 98 | unsigned long last_ramp_up_time; |
| 99 | unsigned long last_queue_full_time; |
| 100 | }; |
| 101 | |
| 102 | enum bfad_binding_type { |
| 103 | FCP_PWWN_BINDING = 0x1, |
| 104 | FCP_NWWN_BINDING = 0x2, |
| 105 | FCP_FCID_BINDING = 0x3, |
| 106 | }; |
| 107 | |
| 108 | struct bfad_fcp_binding { |
| 109 | struct list_head list_entry; |
| 110 | enum bfad_binding_type binding_type; |
| 111 | u16 scsi_target_id; |
| 112 | u32 fc_id; |
| 113 | wwn_t nwwn; |
| 114 | wwn_t pwwn; |
| 115 | }; |
| 116 | |
| 117 | struct bfad_im_s { |
| 118 | struct bfad_s *bfad; |
| 119 | struct workqueue_struct *drv_workq; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 120 | char drv_workq_name[KOBJ_NAME_LEN]; |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 121 | struct work_struct aen_im_notify_work; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 124 | #define bfad_get_aen_entry(_drv, _entry) do { \ |
| 125 | unsigned long _flags; \ |
| 126 | spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \ |
| 127 | bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \ |
| 128 | if (_entry) \ |
| 129 | list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \ |
| 130 | spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \ |
| 131 | } while (0) |
| 132 | |
| 133 | /* post fc_host vendor event */ |
| 134 | #define bfad_im_post_vendor_event(_entry, _drv, _cnt, _cat, _evt) do { \ |
| 135 | do_gettimeofday(&(_entry)->aen_tv); \ |
| 136 | (_entry)->bfad_num = (_drv)->inst_no; \ |
| 137 | (_entry)->seq_num = (_cnt); \ |
| 138 | (_entry)->aen_category = (_cat); \ |
| 139 | (_entry)->aen_type = (_evt); \ |
| 140 | if ((_drv)->bfad_flags & BFAD_FC4_PROBE_DONE) \ |
| 141 | queue_work((_drv)->im->drv_workq, \ |
| 142 | &(_drv)->im->aen_im_notify_work); \ |
| 143 | } while (0) |
| 144 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 145 | struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 146 | struct bfad_s *); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 147 | bfa_status_t bfad_thread_workq(struct bfad_s *bfad); |
| 148 | void bfad_destroy_workq(struct bfad_im_s *im); |
| 149 | void bfad_fc_host_init(struct bfad_im_port_s *im_port); |
| 150 | void bfad_scsi_host_free(struct bfad_s *bfad, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 151 | struct bfad_im_port_s *im_port); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 152 | void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 153 | struct scsi_device *sdev); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 154 | void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev); |
| 155 | struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 156 | |
| 157 | extern struct scsi_host_template bfad_im_scsi_host_template; |
| 158 | extern struct scsi_host_template bfad_im_vport_template; |
| 159 | extern struct fc_function_template bfad_im_fc_function_template; |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 160 | extern struct fc_function_template bfad_im_vport_fc_function_template; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 161 | extern struct scsi_transport_template *bfad_im_scsi_transport_template; |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 162 | extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 163 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 164 | extern struct device_attribute *bfad_im_host_attrs[]; |
| 165 | extern struct device_attribute *bfad_im_vport_attrs[]; |
| 166 | |
| 167 | irqreturn_t bfad_intx(int irq, void *dev_id); |
| 168 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 169 | int bfad_im_bsg_request(struct fc_bsg_job *job); |
| 170 | int bfad_im_bsg_timeout(struct fc_bsg_job *job); |
| 171 | |
Krishna Gudipati | 5b7db7a | 2011-12-20 18:58:32 -0800 | [diff] [blame] | 172 | /* |
| 173 | * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the |
| 174 | * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan |
| 175 | * |
| 176 | * Internally iterate's over all the ITNIM's part of the im_port & set's the |
| 177 | * sdev_bflags for the scsi_device associated with LUN #0. |
| 178 | */ |
| 179 | #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \ |
| 180 | struct scsi_device *__sdev = NULL; \ |
| 181 | struct bfad_itnim_s *__itnim = NULL; \ |
| 182 | u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \ |
| 183 | list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \ |
| 184 | list_entry) { \ |
| 185 | __sdev = scsi_device_lookup((__im_port)->shost, \ |
| 186 | __itnim->channel, \ |
| 187 | __itnim->scsi_tgt_id, 0); \ |
| 188 | if (__sdev) { \ |
| 189 | if ((__lunmask_cfg) == BFA_TRUE) \ |
| 190 | __sdev->sdev_bflags |= scan_flags; \ |
| 191 | else \ |
| 192 | __sdev->sdev_bflags &= ~scan_flags; \ |
| 193 | scsi_device_put(__sdev); \ |
| 194 | } \ |
| 195 | } \ |
| 196 | } while (0) |
| 197 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 198 | #endif |