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 467725ccfdSJing Huang struct bfad_itnim_data_s { 477725ccfdSJing Huang struct bfad_itnim_s *itnim; 487725ccfdSJing Huang }; 497725ccfdSJing Huang 507725ccfdSJing Huang struct bfad_im_port_s { 517725ccfdSJing Huang struct bfad_s *bfad; 527725ccfdSJing Huang struct bfad_port_s *port; 537725ccfdSJing Huang struct work_struct port_delete_work; 547725ccfdSJing Huang int idr_id; 557725ccfdSJing Huang u16 cur_scsi_id; 56b504293fSJing Huang u16 flags; 577725ccfdSJing Huang struct list_head binding_list; 587725ccfdSJing Huang struct Scsi_Host *shost; 597725ccfdSJing Huang struct list_head itnim_mapped_list; 60b504293fSJing Huang struct fc_vport *fc_vport; 617725ccfdSJing Huang }; 627725ccfdSJing Huang 6348d83282SArnd Bergmann struct bfad_im_port_pointer { 6448d83282SArnd Bergmann struct bfad_im_port_s *p; 6548d83282SArnd Bergmann }; 6648d83282SArnd Bergmann 6748d83282SArnd Bergmann static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host) 6848d83282SArnd Bergmann { 6948d83282SArnd Bergmann struct bfad_im_port_pointer *im_portp = shost_priv(host); 7048d83282SArnd Bergmann return im_portp->p; 7148d83282SArnd Bergmann } 7248d83282SArnd Bergmann 737725ccfdSJing Huang enum bfad_itnim_state { 747725ccfdSJing Huang ITNIM_STATE_NONE, 757725ccfdSJing Huang ITNIM_STATE_ONLINE, 767725ccfdSJing Huang ITNIM_STATE_OFFLINE_PENDING, 777725ccfdSJing Huang ITNIM_STATE_OFFLINE, 787725ccfdSJing Huang ITNIM_STATE_TIMEOUT, 797725ccfdSJing Huang ITNIM_STATE_FREE, 807725ccfdSJing Huang }; 817725ccfdSJing Huang 827725ccfdSJing Huang /* 837725ccfdSJing Huang * Per itnim data structure 847725ccfdSJing Huang */ 857725ccfdSJing Huang struct bfad_itnim_s { 867725ccfdSJing Huang struct list_head list_entry; 877725ccfdSJing Huang struct bfa_fcs_itnim_s fcs_itnim; 887725ccfdSJing Huang struct work_struct itnim_work; 897725ccfdSJing Huang u32 flags; 907725ccfdSJing Huang enum bfad_itnim_state state; 917725ccfdSJing Huang struct bfad_im_s *im; 927725ccfdSJing Huang struct bfad_im_port_s *im_port; 937725ccfdSJing Huang struct bfad_rport_s *drv_rport; 947725ccfdSJing Huang struct fc_rport *fc_rport; 957725ccfdSJing Huang struct bfa_itnim_s *bfa_itnim; 967725ccfdSJing Huang u16 scsi_tgt_id; 975b7db7afSKrishna Gudipati u16 channel; 987725ccfdSJing Huang u16 queue_work; 997725ccfdSJing Huang unsigned long last_ramp_up_time; 1007725ccfdSJing Huang unsigned long last_queue_full_time; 1017725ccfdSJing Huang }; 1027725ccfdSJing Huang 1037725ccfdSJing Huang enum bfad_binding_type { 1047725ccfdSJing Huang FCP_PWWN_BINDING = 0x1, 1057725ccfdSJing Huang FCP_NWWN_BINDING = 0x2, 1067725ccfdSJing Huang FCP_FCID_BINDING = 0x3, 1077725ccfdSJing Huang }; 1087725ccfdSJing Huang 1097725ccfdSJing Huang struct bfad_fcp_binding { 1107725ccfdSJing Huang struct list_head list_entry; 1117725ccfdSJing Huang enum bfad_binding_type binding_type; 1127725ccfdSJing Huang u16 scsi_target_id; 1137725ccfdSJing Huang u32 fc_id; 1147725ccfdSJing Huang wwn_t nwwn; 1157725ccfdSJing Huang wwn_t pwwn; 1167725ccfdSJing Huang }; 1177725ccfdSJing Huang 1187725ccfdSJing Huang struct bfad_im_s { 1197725ccfdSJing Huang struct bfad_s *bfad; 1207725ccfdSJing Huang struct workqueue_struct *drv_workq; 121a36c61f9SKrishna Gudipati char drv_workq_name[KOBJ_NAME_LEN]; 1227826f304SKrishna Gudipati struct work_struct aen_im_notify_work; 1237725ccfdSJing Huang }; 1247725ccfdSJing Huang 1257826f304SKrishna Gudipati #define bfad_get_aen_entry(_drv, _entry) do { \ 1267826f304SKrishna Gudipati unsigned long _flags; \ 1277826f304SKrishna Gudipati spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \ 1287826f304SKrishna Gudipati bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \ 1297826f304SKrishna Gudipati if (_entry) \ 1307826f304SKrishna Gudipati list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \ 1317826f304SKrishna Gudipati spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \ 1327826f304SKrishna Gudipati } while (0) 1337826f304SKrishna Gudipati 1347826f304SKrishna Gudipati /* post fc_host vendor event */ 1356d4bc344SArnd Bergmann static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry, 1366d4bc344SArnd Bergmann struct bfad_s *drv, int cnt, 1376d4bc344SArnd Bergmann enum bfa_aen_category cat, 138761c830eSNathan Chancellor int evt) 1396d4bc344SArnd Bergmann { 1406d4bc344SArnd Bergmann struct timespec64 ts; 1416d4bc344SArnd Bergmann 1426d4bc344SArnd Bergmann ktime_get_real_ts64(&ts); 1436d4bc344SArnd Bergmann /* 1446d4bc344SArnd Bergmann * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit 1456d4bc344SArnd Bergmann * architectures, or in 2038 if user space interprets it 1466d4bc344SArnd Bergmann * as 'signed'. 1476d4bc344SArnd Bergmann */ 1486d4bc344SArnd Bergmann entry->aen_tv_sec = ts.tv_sec; 1496d4bc344SArnd Bergmann entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC; 1506d4bc344SArnd Bergmann entry->bfad_num = drv->inst_no; 1516d4bc344SArnd Bergmann entry->seq_num = cnt; 1526d4bc344SArnd Bergmann entry->aen_category = cat; 1536d4bc344SArnd Bergmann entry->aen_type = evt; 1546d4bc344SArnd Bergmann if (drv->bfad_flags & BFAD_FC4_PROBE_DONE) 1556d4bc344SArnd Bergmann queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work); 1566d4bc344SArnd Bergmann } 1577826f304SKrishna Gudipati 158f16a1750SMaggie Zhang struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port, 1597725ccfdSJing Huang struct bfad_s *); 160f16a1750SMaggie Zhang bfa_status_t bfad_thread_workq(struct bfad_s *bfad); 161f16a1750SMaggie Zhang void bfad_destroy_workq(struct bfad_im_s *im); 162f16a1750SMaggie Zhang void bfad_fc_host_init(struct bfad_im_port_s *im_port); 163f16a1750SMaggie Zhang void bfad_scsi_host_free(struct bfad_s *bfad, 1647725ccfdSJing Huang struct bfad_im_port_s *im_port); 165f16a1750SMaggie Zhang void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, 1667725ccfdSJing Huang struct scsi_device *sdev); 167f16a1750SMaggie Zhang void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev); 168f16a1750SMaggie Zhang struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id); 1697725ccfdSJing Huang 1707725ccfdSJing Huang extern struct scsi_host_template bfad_im_scsi_host_template; 1717725ccfdSJing Huang extern struct scsi_host_template bfad_im_vport_template; 1727725ccfdSJing Huang extern struct fc_function_template bfad_im_fc_function_template; 173b504293fSJing Huang extern struct fc_function_template bfad_im_vport_fc_function_template; 1747725ccfdSJing Huang extern struct scsi_transport_template *bfad_im_scsi_transport_template; 175b504293fSJing Huang extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template; 1767725ccfdSJing Huang 177*e73af234SBart Van Assche extern const struct attribute_group *bfad_im_host_groups[]; 178*e73af234SBart Van Assche extern const struct attribute_group *bfad_im_vport_groups[]; 179a36c61f9SKrishna Gudipati 180a36c61f9SKrishna Gudipati irqreturn_t bfad_intx(int irq, void *dev_id); 181a36c61f9SKrishna Gudipati 18275cc8cfcSJohannes Thumshirn int bfad_im_bsg_request(struct bsg_job *job); 18375cc8cfcSJohannes Thumshirn int bfad_im_bsg_timeout(struct bsg_job *job); 184b85daafeSKrishna Gudipati 1855b7db7afSKrishna Gudipati /* 1865b7db7afSKrishna Gudipati * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the 1875b7db7afSKrishna Gudipati * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan 1885b7db7afSKrishna Gudipati * 1895b7db7afSKrishna Gudipati * Internally iterate's over all the ITNIM's part of the im_port & set's the 1905b7db7afSKrishna Gudipati * sdev_bflags for the scsi_device associated with LUN #0. 1915b7db7afSKrishna Gudipati */ 1925b7db7afSKrishna Gudipati #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \ 1935b7db7afSKrishna Gudipati struct scsi_device *__sdev = NULL; \ 1945b7db7afSKrishna Gudipati struct bfad_itnim_s *__itnim = NULL; \ 1955b7db7afSKrishna Gudipati u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \ 1965b7db7afSKrishna Gudipati list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \ 1975b7db7afSKrishna Gudipati list_entry) { \ 1985b7db7afSKrishna Gudipati __sdev = scsi_device_lookup((__im_port)->shost, \ 1995b7db7afSKrishna Gudipati __itnim->channel, \ 2005b7db7afSKrishna Gudipati __itnim->scsi_tgt_id, 0); \ 2015b7db7afSKrishna Gudipati if (__sdev) { \ 2025b7db7afSKrishna Gudipati if ((__lunmask_cfg) == BFA_TRUE) \ 2035b7db7afSKrishna Gudipati __sdev->sdev_bflags |= scan_flags; \ 2045b7db7afSKrishna Gudipati else \ 2055b7db7afSKrishna Gudipati __sdev->sdev_bflags &= ~scan_flags; \ 2065b7db7afSKrishna Gudipati scsi_device_put(__sdev); \ 2075b7db7afSKrishna Gudipati } \ 2085b7db7afSKrishna Gudipati } \ 2095b7db7afSKrishna Gudipati } while (0) 2105b7db7afSKrishna Gudipati 2117725ccfdSJing Huang #endif 212