152fa7bf9SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 27725ccfdSJing Huang /* 3889d0d42SAnil Gurumurthy * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. 4889d0d42SAnil Gurumurthy * Copyright (c) 2014- QLogic Corporation. 57725ccfdSJing Huang * All rights reserved 6889d0d42SAnil Gurumurthy * www.qlogic.com 77725ccfdSJing Huang * 831e1d569SAnil Gurumurthy * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. 97725ccfdSJing Huang */ 107725ccfdSJing Huang 117725ccfdSJing Huang #ifndef __BFAD_IM_H__ 127725ccfdSJing Huang #define __BFAD_IM_H__ 137725ccfdSJing Huang 14a36c61f9SKrishna Gudipati #include "bfa_fcs.h" 157725ccfdSJing Huang 167725ccfdSJing Huang #define FCPI_NAME " fcpim" 177725ccfdSJing Huang 18a36c61f9SKrishna Gudipati #ifndef KOBJ_NAME_LEN 19a36c61f9SKrishna Gudipati #define KOBJ_NAME_LEN 20 20a36c61f9SKrishna Gudipati #endif 21a36c61f9SKrishna Gudipati 227725ccfdSJing Huang bfa_status_t bfad_im_module_init(void); 237725ccfdSJing Huang void bfad_im_module_exit(void); 247725ccfdSJing Huang bfa_status_t bfad_im_probe(struct bfad_s *bfad); 257725ccfdSJing Huang void bfad_im_probe_undo(struct bfad_s *bfad); 267725ccfdSJing Huang bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port); 277725ccfdSJing Huang void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port); 287725ccfdSJing Huang void bfad_im_port_clean(struct bfad_im_port_s *im_port); 297725ccfdSJing Huang int bfad_im_scsi_host_alloc(struct bfad_s *bfad, 30b504293fSJing Huang struct bfad_im_port_s *im_port, struct device *dev); 317725ccfdSJing Huang void bfad_im_scsi_host_free(struct bfad_s *bfad, 327725ccfdSJing Huang struct bfad_im_port_s *im_port); 336192bd7cSKrishna Gudipati u32 bfad_im_supported_speeds(struct bfa_s *bfa); 347725ccfdSJing Huang 357725ccfdSJing Huang #define MAX_FCP_TARGET 1024 367725ccfdSJing Huang #define MAX_FCP_LUN 16384 377725ccfdSJing Huang #define BFAD_TARGET_RESET_TMO 60 387725ccfdSJing Huang #define BFAD_LUN_RESET_TMO 60 397725ccfdSJing Huang #define BFA_QUEUE_FULL_RAMP_UP_TIME 120 407725ccfdSJing Huang 417725ccfdSJing Huang /* 427725ccfdSJing Huang * itnim flags 437725ccfdSJing Huang */ 447725ccfdSJing Huang #define IO_DONE_BIT 0 457725ccfdSJing Huang 46*34f5b537SBart Van Assche /** 47*34f5b537SBart Van Assche * struct bfad_cmd_priv - private data per SCSI command. 48*34f5b537SBart Van Assche * @status: Lowest bit represents IO_DONE. The next seven bits hold a value of 49*34f5b537SBart Van Assche * type enum bfi_tskim_status. 50*34f5b537SBart Van Assche * @wq: Wait queue used to wait for completion of an operation. 51*34f5b537SBart Van Assche */ 52*34f5b537SBart Van Assche struct bfad_cmd_priv { 53*34f5b537SBart Van Assche unsigned long status; 54*34f5b537SBart Van Assche wait_queue_head_t *wq; 55*34f5b537SBart Van Assche }; 56*34f5b537SBart Van Assche 57*34f5b537SBart Van Assche static inline struct bfad_cmd_priv *bfad_priv(struct scsi_cmnd *cmd) 58*34f5b537SBart Van Assche { 59*34f5b537SBart Van Assche return scsi_cmd_priv(cmd); 60*34f5b537SBart Van Assche } 61*34f5b537SBart Van Assche 627725ccfdSJing Huang struct bfad_itnim_data_s { 637725ccfdSJing Huang struct bfad_itnim_s *itnim; 647725ccfdSJing Huang }; 657725ccfdSJing Huang 667725ccfdSJing Huang struct bfad_im_port_s { 677725ccfdSJing Huang struct bfad_s *bfad; 687725ccfdSJing Huang struct bfad_port_s *port; 697725ccfdSJing Huang struct work_struct port_delete_work; 707725ccfdSJing Huang int idr_id; 717725ccfdSJing Huang u16 cur_scsi_id; 72b504293fSJing Huang u16 flags; 737725ccfdSJing Huang struct list_head binding_list; 747725ccfdSJing Huang struct Scsi_Host *shost; 757725ccfdSJing Huang struct list_head itnim_mapped_list; 76b504293fSJing Huang struct fc_vport *fc_vport; 777725ccfdSJing Huang }; 787725ccfdSJing Huang 7948d83282SArnd Bergmann struct bfad_im_port_pointer { 8048d83282SArnd Bergmann struct bfad_im_port_s *p; 8148d83282SArnd Bergmann }; 8248d83282SArnd Bergmann 8348d83282SArnd Bergmann static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host) 8448d83282SArnd Bergmann { 8548d83282SArnd Bergmann struct bfad_im_port_pointer *im_portp = shost_priv(host); 8648d83282SArnd Bergmann return im_portp->p; 8748d83282SArnd Bergmann } 8848d83282SArnd Bergmann 897725ccfdSJing Huang enum bfad_itnim_state { 907725ccfdSJing Huang ITNIM_STATE_NONE, 917725ccfdSJing Huang ITNIM_STATE_ONLINE, 927725ccfdSJing Huang ITNIM_STATE_OFFLINE_PENDING, 937725ccfdSJing Huang ITNIM_STATE_OFFLINE, 947725ccfdSJing Huang ITNIM_STATE_TIMEOUT, 957725ccfdSJing Huang ITNIM_STATE_FREE, 967725ccfdSJing Huang }; 977725ccfdSJing Huang 987725ccfdSJing Huang /* 997725ccfdSJing Huang * Per itnim data structure 1007725ccfdSJing Huang */ 1017725ccfdSJing Huang struct bfad_itnim_s { 1027725ccfdSJing Huang struct list_head list_entry; 1037725ccfdSJing Huang struct bfa_fcs_itnim_s fcs_itnim; 1047725ccfdSJing Huang struct work_struct itnim_work; 1057725ccfdSJing Huang u32 flags; 1067725ccfdSJing Huang enum bfad_itnim_state state; 1077725ccfdSJing Huang struct bfad_im_s *im; 1087725ccfdSJing Huang struct bfad_im_port_s *im_port; 1097725ccfdSJing Huang struct bfad_rport_s *drv_rport; 1107725ccfdSJing Huang struct fc_rport *fc_rport; 1117725ccfdSJing Huang struct bfa_itnim_s *bfa_itnim; 1127725ccfdSJing Huang u16 scsi_tgt_id; 1135b7db7afSKrishna Gudipati u16 channel; 1147725ccfdSJing Huang u16 queue_work; 1157725ccfdSJing Huang unsigned long last_ramp_up_time; 1167725ccfdSJing Huang unsigned long last_queue_full_time; 1177725ccfdSJing Huang }; 1187725ccfdSJing Huang 1197725ccfdSJing Huang enum bfad_binding_type { 1207725ccfdSJing Huang FCP_PWWN_BINDING = 0x1, 1217725ccfdSJing Huang FCP_NWWN_BINDING = 0x2, 1227725ccfdSJing Huang FCP_FCID_BINDING = 0x3, 1237725ccfdSJing Huang }; 1247725ccfdSJing Huang 1257725ccfdSJing Huang struct bfad_fcp_binding { 1267725ccfdSJing Huang struct list_head list_entry; 1277725ccfdSJing Huang enum bfad_binding_type binding_type; 1287725ccfdSJing Huang u16 scsi_target_id; 1297725ccfdSJing Huang u32 fc_id; 1307725ccfdSJing Huang wwn_t nwwn; 1317725ccfdSJing Huang wwn_t pwwn; 1327725ccfdSJing Huang }; 1337725ccfdSJing Huang 1347725ccfdSJing Huang struct bfad_im_s { 1357725ccfdSJing Huang struct bfad_s *bfad; 1367725ccfdSJing Huang struct workqueue_struct *drv_workq; 137a36c61f9SKrishna Gudipati char drv_workq_name[KOBJ_NAME_LEN]; 1387826f304SKrishna Gudipati struct work_struct aen_im_notify_work; 1397725ccfdSJing Huang }; 1407725ccfdSJing Huang 1417826f304SKrishna Gudipati #define bfad_get_aen_entry(_drv, _entry) do { \ 1427826f304SKrishna Gudipati unsigned long _flags; \ 1437826f304SKrishna Gudipati spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \ 1447826f304SKrishna Gudipati bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \ 1457826f304SKrishna Gudipati if (_entry) \ 1467826f304SKrishna Gudipati list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \ 1477826f304SKrishna Gudipati spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \ 1487826f304SKrishna Gudipati } while (0) 1497826f304SKrishna Gudipati 1507826f304SKrishna Gudipati /* post fc_host vendor event */ 1516d4bc344SArnd Bergmann static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry, 1526d4bc344SArnd Bergmann struct bfad_s *drv, int cnt, 1536d4bc344SArnd Bergmann enum bfa_aen_category cat, 154761c830eSNathan Chancellor int evt) 1556d4bc344SArnd Bergmann { 1566d4bc344SArnd Bergmann struct timespec64 ts; 1576d4bc344SArnd Bergmann 1586d4bc344SArnd Bergmann ktime_get_real_ts64(&ts); 1596d4bc344SArnd Bergmann /* 1606d4bc344SArnd Bergmann * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit 1616d4bc344SArnd Bergmann * architectures, or in 2038 if user space interprets it 1626d4bc344SArnd Bergmann * as 'signed'. 1636d4bc344SArnd Bergmann */ 1646d4bc344SArnd Bergmann entry->aen_tv_sec = ts.tv_sec; 1656d4bc344SArnd Bergmann entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC; 1666d4bc344SArnd Bergmann entry->bfad_num = drv->inst_no; 1676d4bc344SArnd Bergmann entry->seq_num = cnt; 1686d4bc344SArnd Bergmann entry->aen_category = cat; 1696d4bc344SArnd Bergmann entry->aen_type = evt; 1706d4bc344SArnd Bergmann if (drv->bfad_flags & BFAD_FC4_PROBE_DONE) 1716d4bc344SArnd Bergmann queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work); 1726d4bc344SArnd Bergmann } 1737826f304SKrishna Gudipati 174f16a1750SMaggie Zhang struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port, 1757725ccfdSJing Huang struct bfad_s *); 176f16a1750SMaggie Zhang bfa_status_t bfad_thread_workq(struct bfad_s *bfad); 177f16a1750SMaggie Zhang void bfad_destroy_workq(struct bfad_im_s *im); 178f16a1750SMaggie Zhang void bfad_fc_host_init(struct bfad_im_port_s *im_port); 179f16a1750SMaggie Zhang void bfad_scsi_host_free(struct bfad_s *bfad, 1807725ccfdSJing Huang struct bfad_im_port_s *im_port); 181f16a1750SMaggie Zhang void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, 1827725ccfdSJing Huang struct scsi_device *sdev); 183f16a1750SMaggie Zhang void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev); 184f16a1750SMaggie Zhang struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id); 1857725ccfdSJing Huang 1867725ccfdSJing Huang extern struct scsi_host_template bfad_im_scsi_host_template; 1877725ccfdSJing Huang extern struct scsi_host_template bfad_im_vport_template; 1887725ccfdSJing Huang extern struct fc_function_template bfad_im_fc_function_template; 189b504293fSJing Huang extern struct fc_function_template bfad_im_vport_fc_function_template; 1907725ccfdSJing Huang extern struct scsi_transport_template *bfad_im_scsi_transport_template; 191b504293fSJing Huang extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template; 1927725ccfdSJing Huang 193e73af234SBart Van Assche extern const struct attribute_group *bfad_im_host_groups[]; 194e73af234SBart Van Assche extern const struct attribute_group *bfad_im_vport_groups[]; 195a36c61f9SKrishna Gudipati 196a36c61f9SKrishna Gudipati irqreturn_t bfad_intx(int irq, void *dev_id); 197a36c61f9SKrishna Gudipati 19875cc8cfcSJohannes Thumshirn int bfad_im_bsg_request(struct bsg_job *job); 19975cc8cfcSJohannes Thumshirn int bfad_im_bsg_timeout(struct bsg_job *job); 200b85daafeSKrishna Gudipati 2015b7db7afSKrishna Gudipati /* 2025b7db7afSKrishna Gudipati * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the 2035b7db7afSKrishna Gudipati * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan 2045b7db7afSKrishna Gudipati * 2055b7db7afSKrishna Gudipati * Internally iterate's over all the ITNIM's part of the im_port & set's the 2065b7db7afSKrishna Gudipati * sdev_bflags for the scsi_device associated with LUN #0. 2075b7db7afSKrishna Gudipati */ 2085b7db7afSKrishna Gudipati #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \ 2095b7db7afSKrishna Gudipati struct scsi_device *__sdev = NULL; \ 2105b7db7afSKrishna Gudipati struct bfad_itnim_s *__itnim = NULL; \ 2115b7db7afSKrishna Gudipati u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \ 2125b7db7afSKrishna Gudipati list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \ 2135b7db7afSKrishna Gudipati list_entry) { \ 2145b7db7afSKrishna Gudipati __sdev = scsi_device_lookup((__im_port)->shost, \ 2155b7db7afSKrishna Gudipati __itnim->channel, \ 2165b7db7afSKrishna Gudipati __itnim->scsi_tgt_id, 0); \ 2175b7db7afSKrishna Gudipati if (__sdev) { \ 2185b7db7afSKrishna Gudipati if ((__lunmask_cfg) == BFA_TRUE) \ 2195b7db7afSKrishna Gudipati __sdev->sdev_bflags |= scan_flags; \ 2205b7db7afSKrishna Gudipati else \ 2215b7db7afSKrishna Gudipati __sdev->sdev_bflags &= ~scan_flags; \ 2225b7db7afSKrishna Gudipati scsi_device_put(__sdev); \ 2235b7db7afSKrishna Gudipati } \ 2245b7db7afSKrishna Gudipati } \ 2255b7db7afSKrishna Gudipati } while (0) 2265b7db7afSKrishna Gudipati 2277725ccfdSJing Huang #endif 228