Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * QLogic iSCSI HBA Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c)  2003-2013 QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/iscsi_boot_sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <scsi/scsicam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include "ql4_def.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include "ql4_version.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include "ql4_glbl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "ql4_dbg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "ql4_inline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "ql4_83xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * Driver version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) static char qla4xxx_version_str[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * SRB allocation cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static struct kmem_cache *srb_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * Module parameter information and variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static int ql4xdisablesysfsboot = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) MODULE_PARM_DESC(ql4xdisablesysfsboot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 		 " Set to disable exporting boot targets to sysfs.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 		 "\t\t  0 - Export boot targets\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 		 "\t\t  1 - Do not export boot targets (Default)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) int ql4xdontresethba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) MODULE_PARM_DESC(ql4xdontresethba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 		 " Don't reset the HBA for driver recovery.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		 "\t\t  0 - It will reset HBA (Default)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 		 "\t\t  1 - It will NOT reset HBA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) int ql4xextended_error_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) MODULE_PARM_DESC(ql4xextended_error_logging,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 		 " Option to enable extended error logging.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 		 "\t\t  0 - no logging (Default)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 		 "\t\t  2 - debug logging");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) int ql4xenablemsix = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) MODULE_PARM_DESC(ql4xenablemsix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		 " Set to enable MSI or MSI-X interrupt mechanism.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 		 "\t\t  0 = enable INTx interrupt mechanism.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		 "\t\t  1 = enable MSI-X interrupt mechanism (Default).\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		 "\t\t  2 = enable MSI interrupt mechanism.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define QL4_DEF_QDEPTH 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) MODULE_PARM_DESC(ql4xmaxqdepth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		 " Maximum queue depth to report for target devices.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		 "\t\t  Default: 32.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static int ql4xqfulltracking = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) MODULE_PARM_DESC(ql4xqfulltracking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		 " Enable or disable dynamic tracking and adjustment of\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		 "\t\t scsi device queue depth.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		 "\t\t  0 - Disable.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		 "\t\t  1 - Enable. (Default)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) MODULE_PARM_DESC(ql4xsess_recovery_tmo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		" Target Session Recovery Timeout.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		"\t\t  Default: 120 sec.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) int ql4xmdcapmask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) module_param(ql4xmdcapmask, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) MODULE_PARM_DESC(ql4xmdcapmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		 " Set the Minidump driver capture mask level.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		 "\t\t  Default is 0 (firmware default capture mask)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		 "\t\t  Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) int ql4xenablemd = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) MODULE_PARM_DESC(ql4xenablemd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		 " Set to enable minidump.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		 "\t\t  0 - disable minidump\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		 "\t\t  1 - enable minidump (Default)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  * SCSI host template entry points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * iSCSI template entry points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 				     enum iscsi_param param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 				  enum iscsi_param param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static int qla4xxx_host_get_param(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 				  enum iscsi_host_param param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 				   uint32_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 				   enum iscsi_param_type param_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 				   int param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 						 struct sockaddr *dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 						 int non_blocking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 				enum iscsi_param param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static struct iscsi_cls_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 			     struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 			     uint64_t transport_fd, int is_leading);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static struct iscsi_cls_session *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 			uint16_t qdepth, uint32_t initial_cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static void qla4xxx_task_work(struct work_struct *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static int qla4xxx_task_xmit(struct iscsi_task *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static void qla4xxx_task_cleanup(struct iscsi_task *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 				   struct iscsi_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 			     uint32_t iface_type, uint32_t payload_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 			     uint32_t pid, struct sockaddr *dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 				 uint32_t *num_entries, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void  *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 				  int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)  * SCSI host template entry points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) static int qla4xxx_slave_alloc(struct scsi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static umode_t qla4_attr_is_visible(int param_type, int param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  * iSCSI Flash DDB sysfs entry points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			    struct iscsi_bus_flash_conn *fnode_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 			    void *data, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 			    int param, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 				 int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 				   struct iscsi_bus_flash_conn *fnode_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 				    struct iscsi_bus_flash_conn *fnode_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)     QLA82XX_LEGACY_INTR_CONFIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) static const uint32_t qla4_82xx_reg_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	QLA82XX_PEG_HALT_STATUS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	QLA82XX_PEG_HALT_STATUS2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	QLA82XX_PEG_ALIVE_COUNTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	QLA82XX_CRB_DRV_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	QLA82XX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	QLA82XX_CRB_DRV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	QLA82XX_CRB_DRV_SCRATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	QLA82XX_CRB_DEV_PART_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	QLA82XX_CRB_DRV_IDC_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	QLA82XX_FW_VERSION_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	QLA82XX_FW_VERSION_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	QLA82XX_FW_VERSION_SUB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	CRB_CMDPEG_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	CRB_TEMP_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static const uint32_t qla4_83xx_reg_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	QLA83XX_PEG_HALT_STATUS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	QLA83XX_PEG_HALT_STATUS2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	QLA83XX_PEG_ALIVE_COUNTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	QLA83XX_CRB_DRV_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	QLA83XX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	QLA83XX_CRB_DRV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	QLA83XX_CRB_DRV_SCRATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	QLA83XX_CRB_DEV_PART_INFO1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	QLA83XX_CRB_IDC_VER_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	QLA83XX_FW_VER_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	QLA83XX_FW_VER_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	QLA83XX_FW_VER_SUB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	QLA83XX_CMDPEG_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	QLA83XX_ASIC_TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) static struct scsi_host_template qla4xxx_driver_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.module			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	.name			= DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	.proc_name		= DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	.queuecommand		= qla4xxx_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	.eh_abort_handler	= qla4xxx_eh_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	.eh_device_reset_handler = qla4xxx_eh_device_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	.eh_target_reset_handler = qla4xxx_eh_target_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	.eh_host_reset_handler	= qla4xxx_eh_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	.eh_timed_out		= qla4xxx_eh_cmd_timed_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	.slave_alloc		= qla4xxx_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	.change_queue_depth	= scsi_change_queue_depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	.this_id		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	.cmd_per_lun		= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	.sg_tablesize		= SG_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	.max_sectors		= 0xFFFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	.shost_attrs		= qla4xxx_host_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	.host_reset		= qla4xxx_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	.vendor_id		= SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static struct iscsi_transport qla4xxx_iscsi_transport = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	.owner			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	.name			= DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	.caps			= CAP_TEXT_NEGO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 				  CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 				  CAP_DATADGST | CAP_LOGIN_OFFLOAD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 				  CAP_MULTI_R2T,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	.attr_is_visible	= qla4_attr_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	.create_session         = qla4xxx_session_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	.destroy_session        = qla4xxx_session_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	.start_conn             = qla4xxx_conn_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	.create_conn            = qla4xxx_conn_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	.bind_conn              = qla4xxx_conn_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	.stop_conn              = iscsi_conn_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	.destroy_conn           = qla4xxx_conn_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	.set_param              = iscsi_set_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	.get_conn_param		= qla4xxx_conn_get_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	.get_session_param	= qla4xxx_session_get_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	.get_ep_param           = qla4xxx_get_ep_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	.ep_connect		= qla4xxx_ep_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	.ep_poll		= qla4xxx_ep_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	.ep_disconnect		= qla4xxx_ep_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	.get_stats		= qla4xxx_conn_get_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	.send_pdu		= iscsi_conn_send_pdu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	.xmit_task		= qla4xxx_task_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	.cleanup_task		= qla4xxx_task_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.alloc_pdu		= qla4xxx_alloc_pdu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.get_host_param		= qla4xxx_host_get_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	.set_iface_param	= qla4xxx_iface_set_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.get_iface_param	= qla4xxx_get_iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.bsg_request		= qla4xxx_bsg_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.send_ping		= qla4xxx_send_ping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.get_chap		= qla4xxx_get_chap_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	.delete_chap		= qla4xxx_delete_chap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	.set_chap		= qla4xxx_set_chap_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	.get_flashnode_param	= qla4xxx_sysfs_ddb_get_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	.set_flashnode_param	= qla4xxx_sysfs_ddb_set_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.new_flashnode		= qla4xxx_sysfs_ddb_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	.del_flashnode		= qla4xxx_sysfs_ddb_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	.login_flashnode	= qla4xxx_sysfs_ddb_login,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	.logout_flashnode	= qla4xxx_sysfs_ddb_logout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	.logout_flashnode_sid	= qla4xxx_sysfs_ddb_logout_sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	.get_host_stats		= qla4xxx_get_host_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) static struct scsi_transport_template *qla4xxx_scsi_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	u32 reg_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	int rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	if (is_qla8022(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		reg_val = readl(&ha->qla4_82xx_reg->host_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	else if (is_qla8032(ha) || is_qla8042(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		reg_val = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (reg_val == QL4_ISP_REG_DISCONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			     uint32_t iface_type, uint32_t payload_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			     uint32_t pid, struct sockaddr *dst_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	struct sockaddr_in *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	struct sockaddr_in6 *addr6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	uint32_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	uint8_t ipaddr[IPv6_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	memset(ipaddr, 0, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	/* IPv4 to IPv4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	    (dst_addr->sa_family == AF_INET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		addr = (struct sockaddr_in *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 				  "dest: %pI4\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 				  &ha->ip_config.ip_address, ipaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 					 ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		if (rval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	} else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		   (dst_addr->sa_family == AF_INET6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		/* IPv6 to IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		addr6 = (struct sockaddr_in6 *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		options |= PING_IPV6_PROTOCOL_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		/* Ping using LinkLocal address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		if ((iface_num == 0) || (iface_num == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 					  "src: %pI6 dest: %pI6\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 					  &ha->ip_config.ipv6_link_local_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 					  ipaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			options |= PING_IPV6_LINKLOCAL_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			rval = qla4xxx_ping_iocb(ha, options, payload_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 						 pid, ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 				   "not supported\n", __func__, iface_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			rval = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			goto exit_send_ping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		 * If ping using LinkLocal address fails, try ping using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		 * IPv6 address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			options &= ~PING_IPV6_LINKLOCAL_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			if (iface_num == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				options |= PING_IPV6_ADDR0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 				DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 						  "Ping src: %pI6 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 						  "dest: %pI6\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 						  &ha->ip_config.ipv6_addr0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 						  ipaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			} else if (iface_num == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 				options |= PING_IPV6_ADDR1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 				DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 						  "Ping src: %pI6 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 						  "dest: %pI6\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 						  &ha->ip_config.ipv6_addr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 						  ipaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			rval = qla4xxx_ping_iocb(ha, options, payload_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 						 pid, ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			if (rval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		rval = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) exit_send_ping:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) static umode_t qla4_attr_is_visible(int param_type, int param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	switch (param_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	case ISCSI_HOST_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		case ISCSI_HOST_PARAM_IPADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		case ISCSI_HOST_PARAM_PORT_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		case ISCSI_HOST_PARAM_PORT_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	case ISCSI_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		case ISCSI_PARAM_PERSISTENT_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		case ISCSI_PARAM_PERSISTENT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		case ISCSI_PARAM_TARGET_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		case ISCSI_PARAM_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		case ISCSI_PARAM_TARGET_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		case ISCSI_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		case ISCSI_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		case ISCSI_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		case ISCSI_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		case ISCSI_PARAM_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		case ISCSI_PARAM_IFACE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		case ISCSI_PARAM_CHAP_OUT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		case ISCSI_PARAM_CHAP_IN_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		case ISCSI_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		case ISCSI_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		case ISCSI_PARAM_USERNAME_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		case ISCSI_PARAM_PASSWORD_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		case ISCSI_PARAM_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		case ISCSI_PARAM_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		case ISCSI_PARAM_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		case ISCSI_PARAM_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		case ISCSI_PARAM_DEF_TIME2WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		case ISCSI_PARAM_DEF_TIME2RETAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		case ISCSI_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		case ISCSI_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		case ISCSI_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		case ISCSI_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		case ISCSI_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		case ISCSI_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		case ISCSI_PARAM_MAX_SEGMENT_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		case ISCSI_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		case ISCSI_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		case ISCSI_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		case ISCSI_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		case ISCSI_PARAM_TCP_XMIT_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		case ISCSI_PARAM_TCP_RECV_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		case ISCSI_PARAM_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		case ISCSI_PARAM_IPV6_TC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		case ISCSI_PARAM_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		case ISCSI_PARAM_KEEPALIVE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		case ISCSI_PARAM_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		case ISCSI_PARAM_ISID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		case ISCSI_PARAM_TSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		case ISCSI_PARAM_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		case ISCSI_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		case ISCSI_PARAM_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		case ISCSI_PARAM_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		case ISCSI_PARAM_LOCAL_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	case ISCSI_NET_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		case ISCSI_NET_PARAM_IPV6_ROUTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		case ISCSI_NET_PARAM_VLAN_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		case ISCSI_NET_PARAM_VLAN_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		case ISCSI_NET_PARAM_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		case ISCSI_NET_PARAM_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		case ISCSI_NET_PARAM_IPADDR_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		case ISCSI_NET_PARAM_DELAYED_ACK_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		case ISCSI_NET_PARAM_TCP_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		case ISCSI_NET_PARAM_CACHE_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		case ISCSI_NET_PARAM_IPV4_TOS_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		case ISCSI_NET_PARAM_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		case ISCSI_NET_PARAM_REDIRECT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		case ISCSI_NET_PARAM_IPV4_TTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		case ISCSI_NET_PARAM_IPV6_MLD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	case ISCSI_IFACE_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		case ISCSI_IFACE_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		case ISCSI_IFACE_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		case ISCSI_IFACE_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		case ISCSI_IFACE_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		case ISCSI_IFACE_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		case ISCSI_IFACE_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		case ISCSI_IFACE_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		case ISCSI_IFACE_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	case ISCSI_FLASHNODE_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		case ISCSI_FLASHNODE_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		case ISCSI_FLASHNODE_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		case ISCSI_FLASHNODE_ENTRY_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		case ISCSI_FLASHNODE_HDR_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		case ISCSI_FLASHNODE_DATA_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		case ISCSI_FLASHNODE_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		case ISCSI_FLASHNODE_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		case ISCSI_FLASHNODE_DATASEQ_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		case ISCSI_FLASHNODE_PDU_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		case ISCSI_FLASHNODE_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		case ISCSI_FLASHNODE_SNACK_REQ_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		case ISCSI_FLASHNODE_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		case ISCSI_FLASHNODE_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		case ISCSI_FLASHNODE_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		case ISCSI_FLASHNODE_DEF_TIME2WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		case ISCSI_FLASHNODE_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		case ISCSI_FLASHNODE_KEEPALIVE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		case ISCSI_FLASHNODE_ISID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		case ISCSI_FLASHNODE_TSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		case ISCSI_FLASHNODE_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		case ISCSI_FLASHNODE_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		case ISCSI_FLASHNODE_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		case ISCSI_FLASHNODE_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		case ISCSI_FLASHNODE_REDIRECT_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		case ISCSI_FLASHNODE_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		case ISCSI_FLASHNODE_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		case ISCSI_FLASHNODE_IPV6_TC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		case ISCSI_FLASHNODE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		case ISCSI_FLASHNODE_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		case ISCSI_FLASHNODE_TCP_XMIT_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		case ISCSI_FLASHNODE_TCP_RECV_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		case ISCSI_FLASHNODE_CHAP_OUT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		case ISCSI_FLASHNODE_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		case ISCSI_FLASHNODE_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		case ISCSI_FLASHNODE_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		case ISCSI_FLASHNODE_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		case ISCSI_FLASHNODE_IS_BOOT_TGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  * qla4xxx_create chap_list - Create CHAP list from FLASH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  * Read flash and make a list of CHAP entries, during login when a CHAP entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  * is received, it will be checked in this list. If entry exist then the CHAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)  * entry index is set in the DDB. If CHAP entry does not exist in this list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)  * then a new entry is added in FLASH in CHAP table and the index obtained is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628)  * used in the DDB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	int rval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	uint8_t *chap_flash_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	uint32_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	dma_addr_t chap_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	uint32_t chap_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (is_qla40XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		chap_size = MAX_CHAP_ENTRIES_40XX *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			    sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	else	/* Single region contains CHAP info for both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		 * ports which is divided into half for each port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		chap_size = ha->hw.flt_chap_size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 					     &chap_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	if (!chap_flash_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		offset = FLASH_CHAP_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		if (ha->port_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			offset += chap_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (rval != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		goto exit_chap_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (ha->chap_list == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		ha->chap_list = vmalloc(chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (ha->chap_list == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		goto exit_chap_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	memset(ha->chap_list, 0, chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	memcpy(ha->chap_list, chap_flash_data, chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) exit_chap_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 				     int16_t chap_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 				     struct ql4_chap_table **chap_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	int rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	int max_chap_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	if (!ha->chap_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		goto exit_get_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 				   sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (chap_index > max_chap_entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		goto exit_get_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	*chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	if ((*chap_entry)->cookie !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	     __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		*chap_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) exit_get_chap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718)  * qla4xxx_find_free_chap_index - Find the first free chap index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720)  * @chap_index: CHAP index to be returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722)  * Find the first free chap index available in the chap table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724)  * Note: Caller should acquire the chap lock before getting here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 					uint16_t *chap_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	int i, rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	int free_index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	int max_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct ql4_chap_table *chap_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 						sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	if (!ha->chap_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		goto exit_find_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	for (i = 0; i < max_chap_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		chap_table = (struct ql4_chap_table *)ha->chap_list + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		if ((chap_table->cookie !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		    __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		   (i > MAX_RESRV_CHAP_IDX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 				free_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	if (free_index != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		*chap_index = free_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) exit_find_chap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 				  uint32_t *num_entries, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	struct ql4_chap_table *chap_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	struct iscsi_chap_rec *chap_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	int max_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int valid_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	int ret = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 					sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 			__func__, *num_entries, chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		goto exit_get_chap_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	qla4xxx_create_chap_list(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	chap_rec = (struct iscsi_chap_rec *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	mutex_lock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	for (i = chap_tbl_idx; i < max_chap_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		chap_table = (struct ql4_chap_table *)ha->chap_list + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		if (chap_table->cookie !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		    __constant_cpu_to_le16(CHAP_VALID_COOKIE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		chap_rec->chap_tbl_idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		strlcpy(chap_rec->username, chap_table->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			ISCSI_CHAP_AUTH_NAME_MAX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		strlcpy(chap_rec->password, chap_table->secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			QL4_CHAP_MAX_SECRET_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		chap_rec->password_length = chap_table->secret_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		if (chap_table->flags & BIT_7) /* local */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			chap_rec->chap_type = CHAP_TYPE_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		if (chap_table->flags & BIT_6) /* peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			chap_rec->chap_type = CHAP_TYPE_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		chap_rec++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		valid_chap_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		if (valid_chap_entries == *num_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	mutex_unlock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) exit_get_chap_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			__func__,  valid_chap_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	*num_entries = valid_chap_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) static int __qla4xxx_is_chap_active(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	uint16_t *chap_tbl_idx = (uint16_t *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	if (!iscsi_is_session_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		goto exit_is_chap_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	cls_session = iscsi_dev_to_session(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (iscsi_session_chkready(cls_session))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		goto exit_is_chap_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) exit_is_chap_active:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 				  uint16_t chap_tbl_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 				    __qla4xxx_is_chap_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	struct ql4_chap_table *chap_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	dma_addr_t chap_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	int max_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	uint32_t chap_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	if (chap_table == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 				   sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (chap_tbl_idx > max_chap_entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		goto exit_delete_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	/* Check if chap index is in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	 * If chap is in use don't delet chap entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			   "delete from flash\n", chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		goto exit_delete_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	chap_size = sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (is_qla40XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		/* flt_chap_size is CHAP table size for both ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		 * so divide it by 2 to calculate the offset for second port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		if (ha->port_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			offset += (ha->hw.flt_chap_size / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		offset += (chap_tbl_idx * chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		goto exit_delete_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 			  __le16_to_cpu(chap_table->cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		goto exit_delete_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	offset = FLASH_CHAP_OFFSET |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			(chap_tbl_idx * sizeof(struct ql4_chap_table));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 				FLASH_OPT_RMW_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (ret == QLA_SUCCESS && ha->chap_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		mutex_lock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		/* Update ha chap_list cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			chap_table, sizeof(struct ql4_chap_table));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		mutex_unlock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (ret != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		ret =  -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) exit_delete_chap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)  * qla4xxx_set_chap_entry - Make chap entry with given information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  * @shost: pointer to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)  * @data: chap info - credentials, index and type to make chap entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955)  * @len: length of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  * Add or update chap entry with the given information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	struct iscsi_chap_rec chap_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	struct ql4_chap_table *chap_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	struct iscsi_param_info *param_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	int max_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	int rem = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	memset(&chap_rec, 0, sizeof(chap_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	nla_for_each_attr(attr, data, len, rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		param_info = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		switch (param_info->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		case ISCSI_CHAP_PARAM_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		case ISCSI_CHAP_PARAM_CHAP_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			chap_rec.chap_type = param_info->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		case ISCSI_CHAP_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			size = min_t(size_t, sizeof(chap_rec.username),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 				     param_info->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 			memcpy(chap_rec.username, param_info->value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		case ISCSI_CHAP_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			size = min_t(size_t, sizeof(chap_rec.password),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 				     param_info->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			memcpy(chap_rec.password, param_info->value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		case ISCSI_CHAP_PARAM_PASSWORD_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			chap_rec.password_length = param_info->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 				   "%s: No such sysfs attribute\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			goto exit_set_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	if (chap_rec.chap_type == CHAP_TYPE_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		type = BIDI_CHAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		type = LOCAL_CHAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 				   sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	mutex_lock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (chap_rec.chap_tbl_idx < max_chap_entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 					       &chap_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			if (!(type == qla4xxx_get_chap_type(chap_entry))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 					   "Type mismatch for CHAP entry %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 					   chap_rec.chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 				rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 				goto exit_unlock_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 			/* If chap index is in use then don't modify it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			rc = qla4xxx_is_chap_active(shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 						    chap_rec.chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 				ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 					   "CHAP entry %d is in use\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 					   chap_rec.chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 				rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 				goto exit_unlock_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 			goto exit_unlock_chap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			      chap_rec.chap_tbl_idx, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) exit_unlock_chap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	mutex_unlock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) exit_set_chap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	struct iscsi_offload_host_stats *host_stats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	int host_stats_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	int ddb_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	struct ql_iscsi_stats *ql_iscsi_stats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	int stats_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	dma_addr_t iscsi_stats_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	host_stats_size = sizeof(struct iscsi_offload_host_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (host_stats_size != len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			   __func__, len, host_stats_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		goto exit_host_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	host_stats = (struct iscsi_offload_host_stats *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		goto exit_host_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 					    &iscsi_stats_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	if (!ql_iscsi_stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			   "Unable to allocate memory for iscsi stats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		goto exit_host_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	ret =  qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 				     iscsi_stats_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			   "Unable to retrieve iscsi stats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		goto exit_host_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	host_stats->mactx_multicast_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	host_stats->mactx_broadcast_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	host_stats->mactx_pause_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 			le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	host_stats->mactx_control_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 			le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	host_stats->mactx_deferral =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 			le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	host_stats->mactx_excess_deferral =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 			le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	host_stats->mactx_late_collision =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 			le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	host_stats->mactx_abort	= le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	host_stats->mactx_single_collision =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	host_stats->mactx_multiple_collision =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	host_stats->mactx_collision =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	host_stats->mactx_frames_dropped =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	host_stats->mactx_jumbo_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	host_stats->macrx_unknown_control_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	host_stats->macrx_pause_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	host_stats->macrx_control_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	host_stats->macrx_dribble =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 			le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	host_stats->macrx_frame_length_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	host_stats->macrx_carrier_sense_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	host_stats->macrx_frame_discarded =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	host_stats->macrx_frames_dropped =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	host_stats->mac_encoding_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 			le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	host_stats->macrx_length_error_large =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 			le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	host_stats->macrx_length_error_small =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	host_stats->macrx_multicast_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 			le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	host_stats->macrx_broadcast_frames =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	host_stats->iptx_fragments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	host_stats->iprx_fragments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	host_stats->ip_datagram_reassembly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	host_stats->ip_invalid_address_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 			le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	host_stats->ip_error_packets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 			le64_to_cpu(ql_iscsi_stats->ip_error_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	host_stats->ip_fragrx_overlap =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 			le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	host_stats->ip_fragrx_outoforder =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 			le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	host_stats->ip_datagram_reassembly_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	host_stats->ipv6tx_packets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 			le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	host_stats->ipv6tx_fragments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	host_stats->ipv6rx_packets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 			le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	host_stats->ipv6rx_fragments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	host_stats->ipv6_datagram_reassembly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 			le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	host_stats->ipv6_invalid_address_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	host_stats->ipv6_error_packets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 			le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	host_stats->ipv6_fragrx_overlap =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 			le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	host_stats->ipv6_fragrx_outoforder =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	host_stats->ipv6_datagram_reassembly_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	host_stats->tcptx_segments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 			le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	host_stats->tcptx_bytes	= le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	host_stats->tcprx_segments =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	host_stats->tcp_duplicate_ack_retx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 			le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	host_stats->tcp_retx_timer_expired =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 			le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	host_stats->tcprx_duplicate_ack	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	host_stats->tcprx_pure_ackr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	host_stats->tcptx_delayed_ack =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	host_stats->tcptx_pure_ack =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 			le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	host_stats->tcprx_segment_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	host_stats->tcprx_segment_outoforder =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	host_stats->tcprx_window_probe =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	host_stats->tcprx_window_update =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 			le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	host_stats->tcptx_window_probe_persist =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	host_stats->ecc_error_correction =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 			le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	host_stats->iscsi_data_bytes_tx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	host_stats->iscsi_data_bytes_rx	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	host_stats->iscsi_io_completed =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	host_stats->iscsi_unexpected_io_rx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	host_stats->iscsi_format_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	host_stats->iscsi_hdr_digest_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 			le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	host_stats->iscsi_data_digest_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 			le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	host_stats->iscsi_sequence_error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) exit_host_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	if (ql_iscsi_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		dma_free_coherent(&ha->pdev->dev, stats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 				  ql_iscsi_stats, iscsi_stats_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 				   enum iscsi_param_type param_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 				   int param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	int ival;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	char *pval = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	int len = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	if (param_type == ISCSI_NET_PARAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 			len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 			len = sprintf(buf, "%pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 				      &ha->ip_config.subnet_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 				OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 					 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 				OP_STATE(ha->ip_config.ipv6_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 					 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			len = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 				      (ha->ip_config.tcp_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				       TCPOPT_DHCP_ENABLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 				      "dhcp" : "static");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			if (iface->iface_num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 				len = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 					      &ha->ip_config.ipv6_addr0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			if (iface->iface_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 				len = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 					      &ha->ip_config.ipv6_addr1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 			len = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 				      &ha->ip_config.ipv6_link_local_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		case ISCSI_NET_PARAM_IPV6_ROUTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			len = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 				      &ha->ip_config.ipv6_default_router_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			pval = (ha->ip_config.ipv6_addl_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 				IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 				"nd" : "static";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 			pval = (ha->ip_config.ipv6_addl_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 				IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 				"auto" : "static";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		case ISCSI_NET_PARAM_VLAN_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 				ival = ha->ip_config.ipv4_vlan_tag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 				       ISCSI_MAX_VLAN_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 				ival = ha->ip_config.ipv6_vlan_tag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 				       ISCSI_MAX_VLAN_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 			len = sprintf(buf, "%d\n", ival);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		case ISCSI_NET_PARAM_VLAN_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 				ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 				       ISCSI_MAX_VLAN_PRIORITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 				ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 				       ISCSI_MAX_VLAN_PRIORITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 			len = sprintf(buf, "%d\n", ival);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 				OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 					 IPOPT_VLAN_TAGGING_ENABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 				OP_STATE(ha->ip_config.ipv6_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 					 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		case ISCSI_NET_PARAM_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		case ISCSI_NET_PARAM_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 					      ha->ip_config.ipv4_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 					      ha->ip_config.ipv6_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		case ISCSI_NET_PARAM_IPADDR_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				pval = iscsi_get_ipaddress_state_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 						ha->ip_config.ipv4_addr_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 				if (iface->iface_num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 					pval = iscsi_get_ipaddress_state_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 						ha->ip_config.ipv6_addr0_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 				else if (iface->iface_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 					pval = iscsi_get_ipaddress_state_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 						ha->ip_config.ipv6_addr1_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 			pval = iscsi_get_ipaddress_state_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 					ha->ip_config.ipv6_link_local_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			pval = iscsi_get_router_state_name(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 				      ha->ip_config.ipv6_default_router_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		case ISCSI_NET_PARAM_DELAYED_ACK_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 				OP_STATE(~ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 					 TCPOPT_DELAYED_ACK_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 				OP_STATE(~ha->ip_config.ipv6_tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 					 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 				OP_STATE(~ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 					 TCPOPT_NAGLE_ALGO_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 				OP_STATE(~ha->ip_config.ipv6_tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 					 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 				OP_STATE(~ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 					 TCPOPT_WINDOW_SCALE_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 				OP_STATE(~ha->ip_config.ipv6_tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 					 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 					 pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		case ISCSI_NET_PARAM_TCP_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 					      ha->ip_config.tcp_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 					      ha->ip_config.ipv6_tcp_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 				ival = (ha->ip_config.tcp_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 					TCPOPT_TIMER_SCALE) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 				ival = (ha->ip_config.ipv6_tcp_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 					IPV6_TCPOPT_TIMER_SCALE) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			len = sprintf(buf, "%d\n", ival);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 				OP_STATE(ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 					 TCPOPT_TIMESTAMP_ENABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 				OP_STATE(ha->ip_config.ipv6_tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 					 IPV6_TCPOPT_TIMESTAMP_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		case ISCSI_NET_PARAM_CACHE_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 					      ha->ip_config.ipv4_cache_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 				len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 					      ha->ip_config.ipv6_cache_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 			OP_STATE(ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 				 TCPOPT_DNS_SERVER_IP_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 			OP_STATE(ha->ip_config.tcp_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 				 TCPOPT_SLP_DA_INFO_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		case ISCSI_NET_PARAM_IPV4_TOS_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 				 IPOPT_IPV4_TOS_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		case ISCSI_NET_PARAM_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				 IPOPT_GRAT_ARP_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 		case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 			OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 				 pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			pval = (ha->ip_config.ipv4_alt_cid_len) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			       (char *)ha->ip_config.ipv4_alt_cid : "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 				 IPOPT_REQ_VID_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 				 IPOPT_USE_VID_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 			pval = (ha->ip_config.ipv4_vid_len) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 			       (char *)ha->ip_config.ipv4_vid : "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				 IPOPT_LEARN_IQN_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 			OP_STATE(~ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 				 IPOPT_FRAGMENTATION_DISABLE, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 				 IPOPT_IN_FORWARD_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		case ISCSI_NET_PARAM_REDIRECT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 			if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 				OP_STATE(ha->ip_config.ipv4_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 					 IPOPT_ARP_REDIRECT_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 				OP_STATE(ha->ip_config.ipv6_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 					 IPV6_OPT_REDIRECT_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		case ISCSI_NET_PARAM_IPV4_TTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 			len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 			OP_STATE(ha->ip_config.ipv6_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 				 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		case ISCSI_NET_PARAM_IPV6_MLD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 			OP_STATE(ha->ip_config.ipv6_addl_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				 IPV6_ADDOPT_MLD_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 			len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 				      ha->ip_config.ipv6_traffic_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 				      ha->ip_config.ipv6_hop_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 				      ha->ip_config.ipv6_nd_reach_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 				      ha->ip_config.ipv6_nd_rexmit_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 				      ha->ip_config.ipv6_nd_stale_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 				      ha->ip_config.ipv6_dup_addr_detect_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 		case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 				      ha->ip_config.ipv6_gw_advrt_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 			len = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	} else if (param_type == ISCSI_IFACE_PARAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 			len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		case ISCSI_IFACE_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 				 ISCSIOPTS_HEADER_DIGEST_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		case ISCSI_IFACE_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 				 ISCSIOPTS_DATA_DIGEST_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		case ISCSI_IFACE_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 				 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 				 ISCSIOPTS_INITIAL_R2T_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 				 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 		case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 				 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		case ISCSI_IFACE_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 				      (ha->ip_config.iscsi_options &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 				       ISCSIOPTS_ERL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 			len = sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 				      ha->ip_config.iscsi_max_pdu_size *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 				      BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		case ISCSI_IFACE_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			len = sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 				      ha->ip_config.iscsi_first_burst_len *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 				      BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		case ISCSI_IFACE_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 				      ha->ip_config.iscsi_max_outstnd_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		case ISCSI_IFACE_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 			len = sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 				      ha->ip_config.iscsi_max_burst_len *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 				      BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 				 ISCSIOPTS_CHAP_AUTH_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 				 ISCSIOPTS_BIDI_CHAP_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 				 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 				 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			OP_STATE(ha->ip_config.iscsi_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 				 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 			len = sprintf(buf, "%s\n", pval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		case ISCSI_IFACE_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 			len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 			len = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) static struct iscsi_endpoint *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 		   int non_blocking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	struct qla_endpoint *qla_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	struct sockaddr_in *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	struct sockaddr_in6 *addr6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	if (!shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		pr_err("%s: shost is NULL\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	ha = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	memset(qla_ep, 0, sizeof(struct qla_endpoint));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	if (dst_addr->sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		addr = (struct sockaddr_in *)&qla_ep->dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 				  (char *)&addr->sin_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	} else if (dst_addr->sa_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		memcpy(&qla_ep->dst_addr, dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		       sizeof(struct sockaddr_in6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 				  (char *)&addr6->sin6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	qla_ep->host = shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	return ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	struct qla_endpoint *qla_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	ha = to_qla_host(qla_ep->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	struct qla_endpoint *qla_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	ha = to_qla_host(qla_ep->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 			  ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	iscsi_destroy_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 				enum iscsi_param param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	struct qla_endpoint *qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	struct sockaddr *dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	if (!qla_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	ha = to_qla_host(qla_ep->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 			  ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		if (!dst_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		return iscsi_conn_get_addr_param((struct sockaddr_storage *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 						 &qla_ep->dst_addr, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 				   struct iscsi_stats *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	struct ql_iscsi_stats *ql_iscsi_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	int stats_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	dma_addr_t iscsi_stats_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	cls_sess = iscsi_conn_to_session(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 			  ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	/* Allocate memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 					    &iscsi_stats_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	if (!ql_iscsi_stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 			   "Unable to allocate memory for iscsi stats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		goto exit_get_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	ret =  qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 				     iscsi_stats_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 			   "Unable to retrieve iscsi stats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		goto free_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	/* octets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	/* xmit pdus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	/* recv pdus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	stats->logoutrsp_pdus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) free_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 			  iscsi_stats_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) exit_get_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	struct iscsi_cls_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	enum blk_eh_timer_return ret = BLK_EH_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	spin_lock_irqsave(&session->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	if (session->state == ISCSI_SESSION_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		ret = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	spin_unlock_irqrestore(&session->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	struct iscsi_cls_host *ihost = shost->shost_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	qla4xxx_get_firmware_state(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 	switch (ha->addl_fw_state & 0x0F00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	case FW_ADDSTATE_LINK_SPEED_10MBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		speed = ISCSI_PORT_SPEED_10MBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	case FW_ADDSTATE_LINK_SPEED_100MBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 		speed = ISCSI_PORT_SPEED_100MBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	case FW_ADDSTATE_LINK_SPEED_1GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		speed = ISCSI_PORT_SPEED_1GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	case FW_ADDSTATE_LINK_SPEED_10GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		speed = ISCSI_PORT_SPEED_10GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	ihost->port_speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) static void qla4xxx_set_port_state(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	struct iscsi_cls_host *ihost = shost->shost_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	uint32_t state = ISCSI_PORT_STATE_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	if (test_bit(AF_LINK_UP, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		state = ISCSI_PORT_STATE_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	ihost->port_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) static int qla4xxx_host_get_param(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 				  enum iscsi_host_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	case ISCSI_HOST_PARAM_IPADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		len = sprintf(buf, "%s\n", ha->name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	case ISCSI_HOST_PARAM_PORT_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		qla4xxx_set_port_state(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 		len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	case ISCSI_HOST_PARAM_PORT_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		qla4xxx_set_port_speed(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	if (ha->iface_ipv4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	/* IPv4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	ha->iface_ipv4 = iscsi_create_iface(ha->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 					    &qla4xxx_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 					    ISCSI_IFACE_TYPE_IPV4, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	if (!ha->iface_ipv4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 		ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 			   "iface0.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	if (!ha->iface_ipv6_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		/* IPv6 iface-0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 						      &qla4xxx_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 						      ISCSI_IFACE_TYPE_IPV6, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 						      0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	if (!ha->iface_ipv6_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 			   "iface0.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	if (!ha->iface_ipv6_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		/* IPv6 iface-1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 		ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 						      &qla4xxx_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 						      ISCSI_IFACE_TYPE_IPV6, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 						      0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	if (!ha->iface_ipv6_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 			   "iface1.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		qla4xxx_create_ipv4_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		qla4xxx_create_ipv6_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	if (ha->iface_ipv4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 		iscsi_destroy_iface(ha->iface_ipv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		ha->iface_ipv4 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	if (ha->iface_ipv6_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		iscsi_destroy_iface(ha->iface_ipv6_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		ha->iface_ipv6_0 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	if (ha->iface_ipv6_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		iscsi_destroy_iface(ha->iface_ipv6_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 		ha->iface_ipv6_1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	qla4xxx_destroy_ipv4_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	qla4xxx_destroy_ipv6_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 			     struct iscsi_iface_param_info *iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 			     struct addr_ctrl_blk *init_fw_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	 * iface_num 1 is valid only for IPv6 Addr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 			/* IPv6 Addr 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 			memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 			       sizeof(init_fw_cb->ipv6_addr1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 			/* IPv6 Addr 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 			memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 			       sizeof(init_fw_cb->ipv6_addr0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		       sizeof(init_fw_cb->ipv6_if_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	case ISCSI_NET_PARAM_IPV6_ROUTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		       sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		/* Autocfg applies to even interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 			init_fw_cb->ipv6_addtl_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 				cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 				  ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 			init_fw_cb->ipv6_addtl_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 				cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 				  IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 			ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 				   "Invalid autocfg setting for IPv6 addr\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 		/* Autocfg applies to even interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 		if (iface_param->value[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 		    ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 			init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 					IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		else if (iface_param->value[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 			 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 			init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 				       ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 			ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 				   "Invalid autocfg setting for IPv6 linklocal addr\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		/* Autocfg applies to even interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 			memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 			       sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 			init_fw_cb->ipv6_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 				cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 			qla4xxx_create_ipv6_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 			init_fw_cb->ipv6_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 				cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 					    0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 			qla4xxx_destroy_ipv6_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	case ISCSI_NET_PARAM_VLAN_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 		if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 		init_fw_cb->ipv6_vlan_tag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 				cpu_to_be16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 			init_fw_cb->ipv6_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 				cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 			init_fw_cb->ipv6_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 				cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 	case ISCSI_NET_PARAM_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		init_fw_cb->eth_mtu_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	case ISCSI_NET_PARAM_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		/* Autocfg applies to even interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 		init_fw_cb->ipv6_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	case ISCSI_NET_PARAM_DELAYED_ACK_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 			init_fw_cb->ipv6_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 				cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 			init_fw_cb->ipv6_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 				cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 					    0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 			init_fw_cb->ipv6_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 				cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 			init_fw_cb->ipv6_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 				cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 			init_fw_cb->ipv6_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 				cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 			init_fw_cb->ipv6_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 				cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	case ISCSI_NET_PARAM_TCP_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 	case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		init_fw_cb->ipv6_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 					cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 		init_fw_cb->ipv6_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 				cpu_to_le16((iface_param->value[0] << 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 					    IPV6_TCPOPT_TIMER_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 	case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			init_fw_cb->ipv6_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 				cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 			init_fw_cb->ipv6_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 				cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 			init_fw_cb->ipv6_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 				cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 			init_fw_cb->ipv6_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 				cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	case ISCSI_NET_PARAM_REDIRECT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 			init_fw_cb->ipv6_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 				cpu_to_le16(IPV6_OPT_REDIRECT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 			init_fw_cb->ipv6_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 				cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	case ISCSI_NET_PARAM_IPV6_MLD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 			init_fw_cb->ipv6_addtl_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 				cpu_to_le16(IPV6_ADDOPT_MLD_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 			init_fw_cb->ipv6_addtl_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 				cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		init_fw_cb->ipv6_flow_lbl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 		init_fw_cb->ipv6_traffic_class = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		init_fw_cb->ipv6_hop_limit = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		init_fw_cb->ipv6_nd_reach_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 				cpu_to_le32(*(uint32_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		init_fw_cb->ipv6_nd_rexmit_timer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 				cpu_to_le32(*(uint32_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		init_fw_cb->ipv6_nd_stale_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 				cpu_to_le32(*(uint32_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		init_fw_cb->ipv6_gw_advrt_mtu =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 				cpu_to_le32(*(uint32_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 			   iface_param->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 			     struct iscsi_iface_param_info *iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 			     struct addr_ctrl_blk *init_fw_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		memcpy(init_fw_cb->ipv4_addr, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		       sizeof(init_fw_cb->ipv4_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		memcpy(init_fw_cb->ipv4_subnet,	iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 		       sizeof(init_fw_cb->ipv4_subnet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 		memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 		       sizeof(init_fw_cb->ipv4_gw_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 					cpu_to_le16(TCPOPT_DHCP_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 					cpu_to_le16(~TCPOPT_DHCP_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 			ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 		if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 				cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 			qla4xxx_create_ipv4_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 				cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 					    0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 			qla4xxx_destroy_ipv4_iface(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	case ISCSI_NET_PARAM_VLAN_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 		if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 		init_fw_cb->ipv4_vlan_tag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 				cpu_to_be16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 		if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 					cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 					cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	case ISCSI_NET_PARAM_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		init_fw_cb->eth_mtu_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	case ISCSI_NET_PARAM_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 		init_fw_cb->ipv4_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	case ISCSI_NET_PARAM_DELAYED_ACK_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 				cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 				cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 					    0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 				cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 				cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 				cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 				cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	case ISCSI_NET_PARAM_TCP_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 		init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 		init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 				cpu_to_le16((iface_param->value[0] << 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 					    TCPOPT_TIMER_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 				cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 				cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 				cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 				cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 			init_fw_cb->ipv4_tcp_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 				cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 			init_fw_cb->ipv4_tcp_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 				cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	case ISCSI_NET_PARAM_IPV4_TOS_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 				cpu_to_le16(IPOPT_IPV4_TOS_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 				cpu_to_le16(~IPOPT_IPV4_TOS_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	case ISCSI_NET_PARAM_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 		init_fw_cb->ipv4_tos = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 					cpu_to_le16(IPOPT_GRAT_ARP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 					cpu_to_le16(~IPOPT_GRAT_ARP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 				cpu_to_le16(IPOPT_ALT_CID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 				cpu_to_le16(~IPOPT_ALT_CID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 		memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		       (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 		init_fw_cb->ipv4_dhcp_alt_cid_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 					strlen(init_fw_cb->ipv4_dhcp_alt_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 					cpu_to_le16(IPOPT_REQ_VID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 					cpu_to_le16(~IPOPT_REQ_VID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 					cpu_to_le16(IPOPT_USE_VID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 					cpu_to_le16(~IPOPT_USE_VID_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 		memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		       (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		init_fw_cb->ipv4_dhcp_vid_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 					strlen(init_fw_cb->ipv4_dhcp_vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 					cpu_to_le16(IPOPT_LEARN_IQN_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 					cpu_to_le16(~IPOPT_LEARN_IQN_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 	case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 				cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 				cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 				cpu_to_le16(IPOPT_IN_FORWARD_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 				cpu_to_le16(~IPOPT_IN_FORWARD_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	case ISCSI_NET_PARAM_REDIRECT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 			init_fw_cb->ipv4_ip_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 				cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 			init_fw_cb->ipv4_ip_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 				cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	case ISCSI_NET_PARAM_IPV4_TTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 		init_fw_cb->ipv4_ttl = iface_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 		ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 			   iface_param->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 				    struct iscsi_iface_param_info *iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 				    struct addr_ctrl_blk *init_fw_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 	switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 	case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 		init_fw_cb->def_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	case ISCSI_IFACE_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 				cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 				cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	case ISCSI_IFACE_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 				cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 				cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 	case ISCSI_IFACE_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 				cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 				cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 				cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 				cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 				cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 				cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 	case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 				cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 				cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	case ISCSI_IFACE_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 		init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 						      ISCSIOPTS_ERL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 		init_fw_cb->iscsi_max_pdu_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 				cpu_to_le32(*(uint32_t *)iface_param->value) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 				BYTE_UNITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	case ISCSI_IFACE_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		init_fw_cb->iscsi_fburst_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 				cpu_to_le32(*(uint32_t *)iface_param->value) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 				BYTE_UNITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	case ISCSI_IFACE_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		init_fw_cb->iscsi_max_outstnd_r2t =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 				cpu_to_le16(*(uint16_t *)iface_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 	case ISCSI_IFACE_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 		init_fw_cb->iscsi_max_burst_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 				cpu_to_le32(*(uint32_t *)iface_param->value) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 				BYTE_UNITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 				cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 				cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 				cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 				cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 	case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 				cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 				cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 				cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 				cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 	case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 		if (iface_param->iface_num & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 		if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 			init_fw_cb->iscsi_opts |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 				cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 			init_fw_cb->iscsi_opts &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 				cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 		ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 			   iface_param->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	struct addr_ctrl_blk_def *acb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	acb = (struct addr_ctrl_blk_def *)init_fw_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	memset(acb->reserved1, 0, sizeof(acb->reserved1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	memset(acb->reserved2, 0, sizeof(acb->reserved2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	memset(acb->reserved3, 0, sizeof(acb->reserved3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	memset(acb->reserved4, 0, sizeof(acb->reserved4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	memset(acb->reserved5, 0, sizeof(acb->reserved5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 	memset(acb->reserved6, 0, sizeof(acb->reserved6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	memset(acb->reserved7, 0, sizeof(acb->reserved7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	memset(acb->reserved8, 0, sizeof(acb->reserved8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	memset(acb->reserved9, 0, sizeof(acb->reserved9));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	memset(acb->reserved10, 0, sizeof(acb->reserved10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 	memset(acb->reserved11, 0, sizeof(acb->reserved11));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 	memset(acb->reserved12, 0, sizeof(acb->reserved12));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	memset(acb->reserved13, 0, sizeof(acb->reserved13));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 	memset(acb->reserved14, 0, sizeof(acb->reserved14));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	memset(acb->reserved15, 0, sizeof(acb->reserved15));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	int rval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	struct iscsi_iface_param_info *iface_param = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	struct addr_ctrl_blk *init_fw_cb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 	dma_addr_t init_fw_cb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	uint32_t mbox_cmd[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 	uint32_t mbox_sts[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 	uint32_t rem = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 	init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 					sizeof(struct addr_ctrl_blk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 					&init_fw_cb_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	if (!init_fw_cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 		ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	memset(&mbox_cmd, 0, sizeof(mbox_cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	memset(&mbox_sts, 0, sizeof(mbox_sts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 		ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 		goto exit_init_fw_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	nla_for_each_attr(attr, data, len, rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 		iface_param = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		if (iface_param->param_type == ISCSI_NET_PARAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 			switch (iface_param->iface_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 			case ISCSI_IFACE_TYPE_IPV4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 				switch (iface_param->iface_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 				case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 					qla4xxx_set_ipv4(ha, iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 							 init_fw_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 				/* Cannot have more than one IPv4 interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 					ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 						   "Invalid IPv4 iface number = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 						   iface_param->iface_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 			case ISCSI_IFACE_TYPE_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 				switch (iface_param->iface_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 				case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 				case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 					qla4xxx_set_ipv6(ha, iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 							 init_fw_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 				/* Cannot have more than two IPv6 interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 					ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 						   "Invalid IPv6 iface number = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 						   iface_param->iface_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 				ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 					   "Invalid iface type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 		} else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 				qla4xxx_set_iscsi_param(ha, iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 							init_fw_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 				 sizeof(struct addr_ctrl_blk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 				 FLASH_OPT_RMW_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 		ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 		goto exit_init_fw_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	rval = qla4xxx_disable_acb(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 		ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 		goto exit_init_fw_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	wait_for_completion_timeout(&ha->disable_acb_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 				    DISABLE_ACB_TOV * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	qla4xxx_initcb_to_acb(init_fw_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 		ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 		goto exit_init_fw_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 	qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 				  init_fw_cb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) exit_init_fw_cb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 			  init_fw_cb, init_fw_cb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 				     enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	struct iscsi_session *sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	struct ddb_entry *ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	struct scsi_qla_host *ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	struct ql4_chap_table chap_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 	int rval, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	uint16_t idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	memset(&chap_tbl, 0, sizeof(chap_tbl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 	case ISCSI_PARAM_CHAP_IN_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 		rval = qla4xxx_get_chap_index(ha, sess->username_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 					      sess->password_in, BIDI_CHAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 					      &idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		if (rval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 			len = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 			len = sprintf(buf, "%hu\n", idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 	case ISCSI_PARAM_CHAP_OUT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 		if (ddb_entry->ddb_type == FLASH_DDB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 			if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 				idx = ddb_entry->chap_tbl_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 				rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 				rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 			rval = qla4xxx_get_chap_index(ha, sess->username,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 						      sess->password,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 						      LOCAL_CHAP, &idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 		if (rval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 			len = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 			len = sprintf(buf, "%hu\n", idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	case ISCSI_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	case ISCSI_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 		/* First, populate session username and password for FLASH DDB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		 * if not already done. This happens when session login fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		 * for a FLASH DDB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 		if (ddb_entry->ddb_type == FLASH_DDB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 		    ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		    !sess->username && !sess->password) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 			idx = ddb_entry->chap_tbl_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 			rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 							    chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 							    idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 			if (!rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 				iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 						(char *)chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 						strlen((char *)chap_tbl.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 				iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 						(char *)chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 						chap_tbl.secret_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 		return iscsi_session_get_param(cls_sess, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 				  enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 	struct qla_conn *qla_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	struct sockaddr *dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 	qla_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 	case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 		return iscsi_conn_get_addr_param((struct sockaddr_storage *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 						 dst_addr, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		return iscsi_conn_get_param(cls_conn, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 	uint32_t mbx_sts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 	uint16_t tmp_ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) get_ddb_index:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 	if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 				  "Free DDB index not available\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		goto exit_get_ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 	if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 		goto get_ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 			  "Found a free DDB index at %d\n", tmp_ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 	ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 	if (ret == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 		if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 			ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 				   "DDB index = %d not available trying next\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 				   tmp_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 			goto get_ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 				  "Free FW DDB not available\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 	*ddb_index = tmp_ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) exit_get_ddb_index:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 				   struct ddb_entry *ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 				   char *existing_ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 				   char *user_ipaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 	uint8_t dst_ipaddr[IPv6_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 	char formatted_ipaddr[DDB_IPADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 	int status = QLA_SUCCESS, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 	if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 		ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 			       '\0', NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 		if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 			status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 			goto out_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 		ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 		ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 			       '\0', NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 			status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 			goto out_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 		ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	if (strcmp(existing_ipaddr, formatted_ipaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) out_match:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 				      struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	int idx = 0, max_ddbs, rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 	struct iscsi_session *sess, *existing_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	struct iscsi_conn *conn, *existing_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 	if (sess->targetname == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 	    conn->persistent_address == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	    conn->persistent_port == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 	for (idx = 0; idx < max_ddbs; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 		ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 		if (ddb_entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 		if (ddb_entry->ddb_type != FLASH_DDB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 		existing_sess = ddb_entry->sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 		existing_conn = ddb_entry->conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 		if (existing_sess->targetname == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 		    existing_conn->persistent_address == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 		    existing_conn->persistent_port == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 				  "IQN = %s User IQN = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 				  existing_sess->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 				  sess->targetname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 				  "IP = %s User IP = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 				  existing_conn->persistent_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 				  conn->persistent_address));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 				  "Port = %d User Port = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 				  existing_conn->persistent_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 				  conn->persistent_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 		if (strcmp(existing_sess->targetname, sess->targetname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 		rval = qla4xxx_match_ipaddress(ha, ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 					existing_conn->persistent_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 					conn->persistent_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 		if (rval == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 		if (existing_conn->persistent_port != conn->persistent_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	if (idx == max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 			  "Match found in fwdb sessions\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) static struct iscsi_cls_session *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) qla4xxx_session_create(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 			uint16_t cmds_max, uint16_t qdepth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 			uint32_t initial_cmdsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 	struct qla_endpoint *qla_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 	uint16_t ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 		printk(KERN_ERR "qla4xxx: missing ep.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 	qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	ha = to_qla_host(qla_ep->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 			  ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 	ret = qla4xxx_get_ddb_index(ha, &ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 	if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 	cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 				       cmds_max, sizeof(struct ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 				       sizeof(struct ql4_task_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 				       initial_cmdsn, ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 	if (!cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 	ddb_entry->fw_ddb_index = ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 	ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 	ddb_entry->ha = ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 	ddb_entry->sess = cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 	ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 	ddb_entry->ddb_change = qla4xxx_ddb_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 	clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 	cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 	ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	ha->tot_ddbs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	return cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 	unsigned long flags, wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 			  ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 		goto destroy_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 	wtime = jiffies + (HZ * LOGOUT_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 		ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 					      fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 					      NULL, NULL, &ddb_state, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 					      NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 			goto destroy_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 		if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 		    (ddb_state == DDB_DS_SESSION_FAILED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 			goto destroy_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 		schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	} while ((time_after(wtime, jiffies)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) destroy_session:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 	if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 		clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	qla4xxx_free_ddb(ha, ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 	iscsi_session_teardown(cls_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) static struct iscsi_cls_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 				    conn_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 	if (!cls_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 		pr_info("%s: Can not create connection for conn_idx = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 			__func__, conn_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	ddb_entry->conn = cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 			  conn_idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 	return cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 			     struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 			     uint64_t transport_fd, int is_leading)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 	struct qla_conn *qla_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 			  cls_session->sid, cls_conn->cid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 	if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 	ep = iscsi_lookup_endpoint(transport_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 	if (!ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 	qla_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 	qla_conn->qla_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 	struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 	uint32_t mbx_sts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 			  cls_sess->sid, cls_conn->cid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 	/* Check if we have  matching FW DDB, if yes then do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 	 * login to this target. This could cause target to logout previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	 * connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	ret = qla4xxx_match_fwdb_session(ha, cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 	if (ret == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 			   "Session already exist in FW.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 		ret = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 		goto exit_conn_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 		goto exit_conn_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 	ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 		/* If iscsid is stopped and started then no need to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 		* set param again since ddb state will be already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 		* active and FW does not allow set ddb to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 		* active session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 		if (mbx_sts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 			if (ddb_entry->fw_ddb_device_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 						DDB_DS_SESSION_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 				ddb_entry->unblock_sess(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 				goto exit_set_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 		ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 			   __func__, ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 		goto exit_conn_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 	status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 	if (status == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 		ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 			   sess->targetname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 		goto exit_conn_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 	if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 		ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 	DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 		      ddb_entry->fw_ddb_device_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) exit_set_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) exit_conn_start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 	struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 	int options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 			  cls_conn->cid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 	options = LOGOUT_OPTION_CLOSE_SESSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 	if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 		ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) static void qla4xxx_task_work(struct work_struct *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 	struct ql4_task_data *task_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 	struct passthru_status *sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	struct iscsi_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 	uint8_t *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 	uint32_t data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 	int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	itt_t itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 	task_data = container_of(wdata, struct ql4_task_data, task_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	ha = task_data->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	task = task_data->task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	sts = &task_data->sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 	hdr_len = sizeof(struct iscsi_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 	DEBUG3(printk(KERN_INFO "Status returned\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 	DEBUG3(qla4xxx_dump_buffer(sts, 64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	DEBUG3(printk(KERN_INFO "Response buffer"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 	conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	switch (sts->completionStatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 	case PASSTHRU_STATUS_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 		hdr = (struct iscsi_hdr *)task_data->resp_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 		/* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 		itt = sts->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 		hdr->itt = itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 		data = task_data->resp_buffer + hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 		data_len = task_data->resp_len - hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 		iscsi_complete_pdu(conn, hdr, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 		ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 			   sts->completionStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 	struct ql4_task_data *task_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 	int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 	sess = task->conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 	task_data = task->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 	memset(task_data, 0, sizeof(struct ql4_task_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 	if (task->sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 			   "%s: SCSI Commands not implemented\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 	hdr_len = sizeof(struct iscsi_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 	task_data->ha = ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 	task_data->task = task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	if (task->data_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 		task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 						     task->data_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 						     DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 		      __func__, task->conn->max_recv_dlength, hdr_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 	task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 	task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 						    task_data->resp_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 						    &task_data->resp_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 						    GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 	if (!task_data->resp_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 		goto exit_alloc_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 	task_data->req_len = task->data_count + hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 	task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 						   task_data->req_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 						   &task_data->req_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 						   GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	if (!task_data->req_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 		goto exit_alloc_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 	task->hdr = task_data->req_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	INIT_WORK(&task_data->task_work, qla4xxx_task_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) exit_alloc_pdu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 	if (task_data->resp_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 		dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 				  task_data->resp_buffer, task_data->resp_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 	if (task_data->req_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 		dma_free_coherent(&ha->pdev->dev, task_data->req_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 				  task_data->req_buffer, task_data->req_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) static void qla4xxx_task_cleanup(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 	struct ql4_task_data *task_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 	int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	hdr_len = sizeof(struct iscsi_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	sess = task->conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 	task_data = task->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 	if (task->data_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 		dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 				 task->data_count, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 		      __func__, task->conn->max_recv_dlength, hdr_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 	dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 			  task_data->resp_buffer, task_data->resp_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 	dma_free_coherent(&ha->pdev->dev, task_data->req_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 			  task_data->req_buffer, task_data->req_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) static int qla4xxx_task_xmit(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 	struct scsi_cmnd *sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 	struct iscsi_session *sess = task->conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 	struct ddb_entry *ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 	struct scsi_qla_host *ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 	if (!sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		return qla4xxx_send_passthru0(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 	ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 		   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 					 struct iscsi_bus_flash_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 					 struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 	unsigned long options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 	conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 	if (test_bit(OPT_IPV6_DEVICE, &options)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 		rc = iscsi_switch_str_param(&sess->portal_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 					    PORTAL_TYPE_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 			goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		rc = iscsi_switch_str_param(&sess->portal_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 					    PORTAL_TYPE_IPV4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 			goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 	sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 					      &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 	sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 	sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 	options = le16_to_cpu(fw_ddb_entry->iscsi_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 	conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 	conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 	sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 	sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 	sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 					    &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 	sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 	sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 	sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 					     &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 	sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 	sess->discovery_auth_optional =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 			test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 	if (test_bit(ISCSIOPT_ERL1, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 		sess->erl |= BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 	if (test_bit(ISCSIOPT_ERL0, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 		sess->erl |= BIT_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 	options = le16_to_cpu(fw_ddb_entry->tcp_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 	conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 	conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 	conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 	if (test_bit(TCPOPT_TIMER_SCALE3, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 		conn->tcp_timer_scale |= BIT_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 	if (test_bit(TCPOPT_TIMER_SCALE2, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 		conn->tcp_timer_scale |= BIT_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 	if (test_bit(TCPOPT_TIMER_SCALE1, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 		conn->tcp_timer_scale |= BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 	conn->tcp_timer_scale >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 	conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 	options = le16_to_cpu(fw_ddb_entry->ip_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 	conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 	conn->max_recv_dlength = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 			  le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 	conn->max_xmit_dlength = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 			  le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 	sess->first_burst = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 			       le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 	sess->max_burst = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 				 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 	sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 	sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 	sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 	sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 	conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 	conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 	conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 	conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 	conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 	conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 	conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 	conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 	sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 	sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 	sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 	sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 	sess->default_taskmgmt_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 				le16_to_cpu(fw_ddb_entry->def_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 	conn->port = le16_to_cpu(fw_ddb_entry->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 	conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 	if (!conn->ipaddress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 		goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 	conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 	if (!conn->redirect_ipaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 		goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 	memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 	memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 	if (test_bit(OPT_IPV6_DEVICE, &options)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 		conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 		conn->link_local_ipv6_addr = kmemdup(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 					fw_ddb_entry->link_local_ipv6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 					IPv6_ADDR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 		if (!conn->link_local_ipv6_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 			goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 		conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 	if (fw_ddb_entry->iscsi_name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 		rc = iscsi_switch_str_param(&sess->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 					    (char *)fw_ddb_entry->iscsi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 			goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 	if (fw_ddb_entry->iscsi_alias[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 		rc = iscsi_switch_str_param(&sess->targetalias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 					    (char *)fw_ddb_entry->iscsi_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 			goto exit_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 	COPY_ISID(sess->isid, fw_ddb_entry->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) exit_copy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 				       struct iscsi_bus_flash_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 				       struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 	uint16_t options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 	SET_BITVAL(conn->is_fw_assigned_ipv6,  options, BIT_11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 	if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 		options |= BIT_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 		options &= ~BIT_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 	SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 	SET_BITVAL(sess->discovery_sess, options, BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 	SET_BITVAL(sess->entry_state, options, BIT_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 	fw_ddb_entry->options = cpu_to_le16(options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 	options = le16_to_cpu(fw_ddb_entry->iscsi_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 	SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 	SET_BITVAL(conn->datadgst_en, options, BIT_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 	SET_BITVAL(sess->imm_data_en, options, BIT_11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 	SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 	SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 	SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 	SET_BITVAL(sess->chap_auth_en, options, BIT_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 	SET_BITVAL(conn->snack_req_en, options, BIT_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 	SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 	SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 	SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 	SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 	fw_ddb_entry->iscsi_options = cpu_to_le16(options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 	options = le16_to_cpu(fw_ddb_entry->tcp_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 	SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 	SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 	SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 	SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 	SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 	fw_ddb_entry->tcp_options = cpu_to_le16(options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 	options = le16_to_cpu(fw_ddb_entry->ip_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 	SET_BITVAL(conn->fragment_disable, options, BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 	fw_ddb_entry->ip_options = cpu_to_le16(options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 	fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 	fw_ddb_entry->iscsi_max_rcv_data_seg_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 			       cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 	fw_ddb_entry->iscsi_max_snd_data_seg_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 			       cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 	fw_ddb_entry->iscsi_first_burst_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 				cpu_to_le16(sess->first_burst / BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 	fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 					    BYTE_UNITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 	fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 	fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 	fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 	fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 	fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 	fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 	fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 	fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 	fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 	fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 	fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 	fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 	fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 	fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 	fw_ddb_entry->port = cpu_to_le16(conn->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 	fw_ddb_entry->def_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 				cpu_to_le16(sess->default_taskmgmt_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 	if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 		fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 	if (conn->ipaddress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 		memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 		       sizeof(fw_ddb_entry->ip_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 	if (conn->redirect_ipaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 		memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 		       sizeof(fw_ddb_entry->tgt_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 	if (conn->link_local_ipv6_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 		memcpy(fw_ddb_entry->link_local_ipv6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 		       conn->link_local_ipv6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 		       sizeof(fw_ddb_entry->link_local_ipv6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 	if (sess->targetname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 		memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 		       sizeof(fw_ddb_entry->iscsi_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 	if (sess->targetalias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 		memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 		       sizeof(fw_ddb_entry->iscsi_alias));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 	COPY_ISID(fw_ddb_entry->isid, sess->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 					     struct iscsi_session *sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 					     struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 	unsigned long options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 	uint16_t ddb_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 	uint16_t disc_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 	char ip_addr[DDB_IPADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 	conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 	sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 					      &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 	sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 	options = le16_to_cpu(fw_ddb_entry->iscsi_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 	sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 	sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 					    &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 	sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 	sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 					     &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 	sess->discovery_auth_optional =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 			test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 	if (test_bit(ISCSIOPT_ERL1, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 		sess->erl |= BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 	if (test_bit(ISCSIOPT_ERL0, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 		sess->erl |= BIT_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	options = le16_to_cpu(fw_ddb_entry->tcp_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 	if (test_bit(TCPOPT_TIMER_SCALE3, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 		conn->tcp_timer_scale |= BIT_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 	if (test_bit(TCPOPT_TIMER_SCALE2, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 		conn->tcp_timer_scale |= BIT_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 	if (test_bit(TCPOPT_TIMER_SCALE1, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 		conn->tcp_timer_scale |= BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	conn->tcp_timer_scale >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 	conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 	options = le16_to_cpu(fw_ddb_entry->ip_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 	conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 	conn->max_recv_dlength = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 			  le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 	conn->max_xmit_dlength = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 			  le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 	sess->first_burst = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 			       le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 	sess->max_burst = BYTE_UNITS *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 				 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 	sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 	sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 	conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 	conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 	conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 	conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 	conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 	conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 	conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 	conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 	sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 	COPY_ISID(sess->isid, fw_ddb_entry->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 	if (ddb_link == DDB_ISNS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		disc_parent = ISCSI_DISC_PARENT_ISNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 	else if (ddb_link == DDB_NO_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 		disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 	else if (ddb_link < MAX_DDB_ENTRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 		disc_parent = ISCSI_DISC_PARENT_SENDTGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 		disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 			iscsi_get_discovery_parent_name(disc_parent), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 	iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 			(char *)fw_ddb_entry->iscsi_alias, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 	if (options & DDB_OPT_IPV6_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		memset(ip_addr, 0, sizeof(ip_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 		sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 		iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 				(char *)ip_addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 				     struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 				     struct iscsi_cls_session *cls_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 				     struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 	int buflen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 	struct ql4_chap_table chap_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 	char ip_addr[DDB_IPADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 	uint16_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 	memset(&chap_tbl, 0, sizeof(chap_tbl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 	ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 	qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 	sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 	conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 	memset(ip_addr, 0, sizeof(ip_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 	if (options & DDB_OPT_IPV6_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 		iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 		memset(ip_addr, 0, sizeof(ip_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 		sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 		iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 		sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 	iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 			(char *)ip_addr, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 	iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 			(char *)fw_ddb_entry->iscsi_name, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 			(char *)ha->name_string, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 	if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 		if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 						   chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 						   ddb_entry->chap_tbl_idx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 			iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 					(char *)chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 					strlen((char *)chap_tbl.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 			iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 					(char *)chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 					chap_tbl.secret_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 					     struct ddb_entry *ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 		goto exit_session_conn_fwddb_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 	if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 				    fw_ddb_entry_dma, NULL, NULL, &ddb_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 				    NULL, NULL, NULL) == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 		DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 				  "get_ddb_entry for fw_ddb_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 				  ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 				  ddb_entry->fw_ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 		goto exit_session_conn_fwddb_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 	cls_sess = ddb_entry->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	cls_conn = ddb_entry->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 	/* Update params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 	qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) exit_session_conn_fwddb_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 				       struct ddb_entry *ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 		goto exit_session_conn_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 	if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 				    fw_ddb_entry_dma, NULL, NULL, &ddb_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 				    NULL, NULL, NULL) == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 		DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 				  "get_ddb_entry for fw_ddb_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 				  ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 				  ddb_entry->fw_ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 		goto exit_session_conn_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 	cls_sess = ddb_entry->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 	cls_conn = ddb_entry->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 	/* Update timers after login */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 	ddb_entry->default_relogin_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 		(le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 		 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 		 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 	ddb_entry->default_time2wait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 				le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 	/* Update params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 	ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 	qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 	memcpy(sess->initiatorname, ha->name_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 	       min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) exit_session_conn_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001)  * Timer routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) static void qla4xxx_timer(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) static void qla4xxx_start_timer(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 				unsigned long interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 	DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 		     __func__, ha->host->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 	timer_setup(&ha->timer, qla4xxx_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 	ha->timer.expires = jiffies + interval * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 	add_timer(&ha->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 	ha->timer_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 	del_timer_sync(&ha->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 	ha->timer_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) /***
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023)  * qla4xxx_mark_device_missing - blocks the session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024)  * @cls_session: Pointer to the session to be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025)  * @ddb_entry: Pointer to device database entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027)  * This routine marks a device missing and close connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 	iscsi_block_session(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035)  * qla4xxx_mark_all_devices_missing - mark all devices as missing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038)  * This routine marks a device missing and resets the relogin retry count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 	iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 				       struct ddb_entry *ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 				       struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 	struct srb *srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 	if (!srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 		return srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 	kref_init(&srb->srb_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 	srb->ha = ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 	srb->ddb = ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 	srb->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 	srb->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 	CMD_SP(cmd) = (void *)srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 	return srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 	struct scsi_cmnd *cmd = srb->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 	if (srb->flags & SRB_DMA_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 		scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 		srb->flags &= ~SRB_DMA_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 	CMD_SP(cmd) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) void qla4xxx_srb_compl(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 	struct srb *srb = container_of(ref, struct srb, srb_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 	struct scsi_cmnd *cmd = srb->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 	struct scsi_qla_host *ha = srb->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 	qla4xxx_srb_free_dma(ha, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 	mempool_free(srb, ha->srb_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 	cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090)  * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091)  * @host: scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092)  * @cmd: Pointer to Linux's SCSI command structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094)  * Remarks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095)  * This routine is invoked by Linux to send a SCSI command to the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096)  * The mid-level driver tries to ensure that queuecommand never gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097)  * invoked concurrently with itself or the interrupt handler (although
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098)  * the interrupt handler may call this routine as part of request-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099)  * completion handling).   Unfortunely, it sometimes calls the scheduler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100)  * in interrupt context which is a big NO! NO!.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 	struct ddb_entry *ddb_entry = cmd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 	struct iscsi_cls_session *sess = ddb_entry->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 	struct srb *srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 	if (test_bit(AF_EEH_BUSY, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 		if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 			cmd->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 			cmd->result = DID_REQUEUE << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 		goto qc_fail_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 		cmd->result = DID_IMM_RETRY << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 		goto qc_fail_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 	rval = iscsi_session_chkready(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 		cmd->result = rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 		goto qc_fail_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 	if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 	    test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 	    test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 	    test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 	    test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	    !test_bit(AF_ONLINE, &ha->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 	    !test_bit(AF_LINK_UP, &ha->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 	    test_bit(AF_LOOPBACK, &ha->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 	    test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 	    test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	    test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 		goto qc_host_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 	srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 	if (!srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 		goto qc_host_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 	rval = qla4xxx_send_command_to_isp(ha, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	if (rval != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 		goto qc_host_busy_free_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) qc_host_busy_free_sp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 	qla4xxx_srb_free_dma(ha, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 	mempool_free(srb, ha->srb_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) qc_host_busy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 	return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) qc_fail_command:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 	cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166)  * qla4xxx_mem_free - frees memory allocated to adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169)  * Frees memory previously allocated by qla4xxx_mem_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) static void qla4xxx_mem_free(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 	if (ha->queues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 		dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 				  ha->queues_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 	if (ha->fw_dump)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 		vfree(ha->fw_dump);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 	ha->queues_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 	ha->queues = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 	ha->queues_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 	ha->request_ring = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 	ha->request_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 	ha->response_ring = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	ha->response_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 	ha->shadow_regs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 	ha->shadow_regs_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 	ha->fw_dump = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 	ha->fw_dump_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 	/* Free srb pool. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 	mempool_destroy(ha->srb_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 	ha->srb_mempool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 	dma_pool_destroy(ha->chap_dma_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 	if (ha->chap_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 		vfree(ha->chap_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	ha->chap_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 	dma_pool_destroy(ha->fw_ddb_dma_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 	/* release io space registers  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 	if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 		if (ha->nx_pcibase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 			iounmap(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 			    (struct device_reg_82xx __iomem *)ha->nx_pcibase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 	} else if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 		if (ha->nx_pcibase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 			iounmap(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 			    (struct device_reg_83xx __iomem *)ha->nx_pcibase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 	} else if (ha->reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 		iounmap(ha->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 	if (ha->reset_tmplt.buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 		vfree(ha->reset_tmplt.buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 	pci_release_regions(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224)  * qla4xxx_mem_alloc - allocates memory for use by adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)  * @ha: Pointer to host adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227)  * Allocates DMA memory for request and response queues. Also allocates memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228)  * for srbs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 	unsigned long align;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 	/* Allocate contiguous block of DMA memory for queues. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 	ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 			  (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 			  sizeof(struct shadow_regs) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 			  MEM_ALIGN_VALUE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 			  (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 	ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 					&ha->queues_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 	if (ha->queues == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 		    "Memory Allocation failed - queues.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 		goto mem_alloc_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 	 * As per RISC alignment requirements -- the bus-address must be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 	 * multiple of the request-ring size (in bytes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 	align = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 		align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 					   (MEM_ALIGN_VALUE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 	/* Update request and response queue pointers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 	ha->request_dma = ha->queues_dma + align;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 	ha->request_ring = (struct queue_entry *) (ha->queues + align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 	ha->response_dma = ha->queues_dma + align +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 		(REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 	ha->response_ring = (struct queue_entry *) (ha->queues + align +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 						    (REQUEST_QUEUE_DEPTH *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 						     QUEUE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 	ha->shadow_regs_dma = ha->queues_dma + align +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 		(REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 		(RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 	ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 						  (REQUEST_QUEUE_DEPTH *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 						   QUEUE_SIZE) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 						  (RESPONSE_QUEUE_DEPTH *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 						   QUEUE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 	/* Allocate memory for srb pool. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 	ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 					 mempool_free_slab, srb_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 	if (ha->srb_mempool == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 		    "Memory Allocation failed - SRB Pool.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 		goto mem_alloc_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 					    CHAP_DMA_BLOCK_SIZE, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 	if (ha->chap_dma_pool == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 		    "%s: chap_dma_pool allocation failed..\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 		goto mem_alloc_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 	ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 					      DDB_DMA_BLOCK_SIZE, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 	if (ha->fw_ddb_dma_pool == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 			   "%s: fw_ddb_dma_pool allocation failed..\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 		goto mem_alloc_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) mem_alloc_error_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 	return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311)  * qla4_8xxx_check_temp - Check the ISP82XX temperature.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312)  * @ha: adapter block pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314)  * Note: The caller should not hold the idc lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 	uint32_t temp, temp_state, temp_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 	temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 	temp_state = qla82xx_get_temp_state(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 	temp_val = qla82xx_get_temp_val(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 	if (temp_state == QLA82XX_TEMP_PANIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 		ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 			   " exceeds maximum allowed. Hardware has been shut"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 			   " down.\n", temp_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 		status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 	} else if (temp_state == QLA82XX_TEMP_WARN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 		if (ha->temperature == QLA82XX_TEMP_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 			ql4_printk(KERN_WARNING, ha, "Device temperature %d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 				   " degrees C exceeds operating range."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 				   " Immediate action needed.\n", temp_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 		if (ha->temperature == QLA82XX_TEMP_WARN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 			ql4_printk(KERN_INFO, ha, "Device temperature is"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 				   " now %d degrees C in normal range.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 				   temp_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 	ha->temperature = temp_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347)  * qla4_8xxx_check_fw_alive  - Check firmware health
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350)  * Context: Interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 	uint32_t fw_heartbeat_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 	fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 						   QLA8XXX_PEG_ALIVE_COUNTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 	/* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 	if (fw_heartbeat_counter == 0xffffffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 		DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 		    "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 		    ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 	if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 		ha->seconds_since_last_heartbeat++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 		/* FW not alive after 2 seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 		if (ha->seconds_since_last_heartbeat == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 			ha->seconds_since_last_heartbeat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 			qla4_8xxx_dump_peg_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 			status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 		ha->seconds_since_last_heartbeat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 	ha->fw_heartbeat_counter = fw_heartbeat_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 	uint32_t halt_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 	int halt_status_unrecoverable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 	halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 	if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 		ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 		qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 				CRB_NIU_XG_PAUSE_CTL_P0 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 				CRB_NIU_XG_PAUSE_CTL_P1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 		if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 			ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 		if (halt_status & HALT_STATUS_UNRECOVERABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 			halt_status_unrecoverable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 	} else if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 		if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 			ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 		else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 			halt_status_unrecoverable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 	 * Since we cannot change dev_state in interrupt context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 	 * set appropriate DPC flag then wakeup DPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 	if (halt_status_unrecoverable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 		set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 		ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 		set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 	qla4xxx_mailbox_premature_completion(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 	qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425)  * qla4_8xxx_watchdog - Poll dev state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428)  * Context: Interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	uint32_t dev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 	uint32_t idc_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 	if (is_qla8032(ha) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 	    (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 		WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 			  __func__, ha->func_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 	/* don't poll if reset is going on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 	if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	    test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 	    test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 		dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 		if (qla4_8xxx_check_temp(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 			if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 				ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 				qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 						CRB_NIU_XG_PAUSE_CTL_P0 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 						CRB_NIU_XG_PAUSE_CTL_P1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 			set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 			qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 		} else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 			   !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 			ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 			if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 				idc_ctrl = qla4_83xx_rd_reg(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 							QLA83XX_IDC_DRV_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 				if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 					ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 						   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 					qla4xxx_mailbox_premature_completion(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 									    ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 			if ((is_qla8032(ha) || is_qla8042(ha)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 			    (is_qla8022(ha) && !ql4xdontresethba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 				set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 				qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 		} else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 		    !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 			ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 			    __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 			set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 			qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 		} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 			/* Check firmware health */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 			if (qla4_8xxx_check_fw_alive(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 				qla4_8xxx_process_fw_error(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 	if (!(ddb_entry->ddb_type == FLASH_DDB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 	if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 	    !iscsi_is_session_online(cls_sess)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 		if (atomic_read(&ddb_entry->retry_relogin_timer) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 		    INVALID_ENTRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 			if (atomic_read(&ddb_entry->retry_relogin_timer) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 					0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 				atomic_set(&ddb_entry->retry_relogin_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 					   INVALID_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 				set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 				set_bit(DF_RELOGIN, &ddb_entry->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 				DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 				       "%s: index [%d] login device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 					__func__, ddb_entry->fw_ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 				atomic_dec(&ddb_entry->retry_relogin_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 	/* Wait for relogin to timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 	if (atomic_read(&ddb_entry->relogin_timer) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 	    (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 		 * If the relogin times out and the device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 		 * still NOT ONLINE then try and relogin again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 		if (!iscsi_is_session_online(cls_sess)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 			/* Reset retry relogin timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 			atomic_inc(&ddb_entry->relogin_retry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 			DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 				"%s: index[%d] relogin timed out-retrying"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 				" relogin (%d), retry (%d)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 				ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 				atomic_read(&ddb_entry->relogin_retry_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 				ddb_entry->default_time2wait + 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 			set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 			atomic_set(&ddb_entry->retry_relogin_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 				   ddb_entry->default_time2wait + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546)  * qla4xxx_timer - checks every second for work to do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547)  * @t: Context to obtain pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) static void qla4xxx_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 	struct scsi_qla_host *ha = from_timer(ha, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 	int start_dpc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 	uint16_t w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 	iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 	/* If we are in the middle of AER/EEH processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 	 * skip any processing and reschedule the timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 	if (test_bit(AF_EEH_BUSY, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 		mod_timer(&ha->timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 	/* Hardware read to trigger an EEH error during mailbox waits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 	if (!pci_channel_offline(ha->pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 		pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 		qla4_8xxx_watchdog(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 		/* Check for heartbeat interval. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 		if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 		    ha->heartbeat_interval != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 			ha->seconds_since_last_heartbeat++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 			if (ha->seconds_since_last_heartbeat >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 			    ha->heartbeat_interval + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 				set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 	/* Process any deferred work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 	if (!list_empty(&ha->work_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) 		start_dpc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 	/* Wakeup the dpc routine for this adapter, if needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 	if (start_dpc ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 	     test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 	     test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 	     test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 	     test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 	     test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 	     test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 	     test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 	     test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 	     test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 	     test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 	     test_bit(DPC_AEN, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 		DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 			      " - dpc flags = 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 			      ha->host_no, __func__, ha->dpc_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 		qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 	/* Reschedule timer thread to call us back in one second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 	mod_timer(&ha->timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 	DEBUG2(ha->seconds_since_last_intr++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613)  * qla4xxx_cmd_wait - waits for all outstanding commands to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616)  * This routine stalls the driver until all outstanding commands are returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617)  * Caller must release the Hardware Lock prior to calling this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 	uint32_t index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 	struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 	uint32_t wtmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 	if (is_qla40XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 		wtmo = WAIT_CMD_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 		wtmo = ha->nx_reset_timeout / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 	wtime = jiffies + (wtmo * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 			  "Wait up to %u seconds for cmds to complete\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 			  wtmo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 	while (!time_after_eq(jiffies, wtime)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 		/* Find a command that hasn't completed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 		for (index = 0; index < ha->host->can_queue; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 			cmd = scsi_host_find_tag(ha->host, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 			 * We cannot just check if the index is valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 			 * becase if we are run from the scsi eh, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 			 * the scsi/block layer is going to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 			 * the tag from being released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 			if (cmd != NULL && CMD_SP(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 		/* If No Commands are pending, wait is complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 		if (index == ha->host->can_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 			return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 		msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 	/* If we timed out on waiting for commands to come back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 	 * return ERROR. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 	return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) int qla4xxx_hw_reset(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 	uint32_t ctrl_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 	DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 	if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 	 * If the SCSI Reset Interrupt bit is set, clear it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 	 * Otherwise, the Soft Reset won't work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 	ctrl_status = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 		writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 	/* Issue Soft Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 	writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 	readl(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694)  * qla4xxx_soft_reset - performs soft reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) int qla4xxx_soft_reset(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 	uint32_t max_wait_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 	uint32_t ctrl_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 	status = qla4xxx_hw_reset(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 	if (status != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 	status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 	/* Wait until the Network Reset Intr bit is cleared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 	max_wait_time = RESET_INTR_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 		ctrl_status = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 		if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 		msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 	} while ((--max_wait_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 	if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 		DEBUG2(printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 			      "scsi%ld: Network Reset Intr not cleared by "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 			      "Network function, clearing it now!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 			      ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 		writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 		readl(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 	/* Wait until the firmware tells us the Soft Reset is done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 	max_wait_time = SOFT_RESET_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 		ctrl_status = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 		if ((ctrl_status & CSR_SOFT_RESET) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 			status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 		msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 	} while ((--max_wait_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 	 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 	 * after the soft reset has taken place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 	ctrl_status = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 	if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 		writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 		readl(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 	/* If soft reset fails then most probably the bios on other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 	 * function is also enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 	 * Since the initialization is sequential the other fn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 	 * wont be able to acknowledge the soft reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 	 * Issue a force soft reset to workaround this scenario.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 	if (max_wait_time == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 		/* Issue Force Soft Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 		writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 		readl(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 		/* Wait until the firmware tells us the Soft Reset is done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 		max_wait_time = SOFT_RESET_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 			spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 			ctrl_status = readw(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 			spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 			if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 				status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 			msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 		} while ((--max_wait_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792)  * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794)  * @res: returned scsi status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796)  * This routine is called just prior to a HARD RESET to return all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797)  * outstanding commands back to the Operating System.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798)  * Caller should make sure that the following locks are released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799)  * before this calling routine: Hardware lock, and io_request_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 	struct srb *srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 	for (i = 0; i < ha->host->can_queue; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 		srb = qla4xxx_del_from_active_array(ha, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 		if (srb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 			srb->cmd->result = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 			kref_put(&srb->srb_ref, qla4xxx_srb_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 	clear_bit(AF_ONLINE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 	/* Disable the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 	ql4_printk(KERN_INFO, ha, "Disabling the board\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 	qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 	qla4xxx_mark_all_devices_missing(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 	clear_bit(AF_INIT_DONE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 	ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 	if (ddb_entry->ddb_type == FLASH_DDB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 		iscsi_block_session(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 		iscsi_session_failure(cls_session->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 				      ISCSI_ERR_CONN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847)  * qla4xxx_recover_adapter - recovers adapter after a fatal error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) 	int status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 	uint8_t reset_chip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) 	uint32_t dev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 	unsigned long wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 	/* Stall incoming I/O until we are done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 	scsi_block_requests(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 	clear_bit(AF_ONLINE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 	clear_bit(AF_LINK_UP, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 	set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 	if ((is_qla8032(ha) || is_qla8042(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 	    !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 		ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 		/* disable pause frame for ISP83xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 		qla4_83xx_disable_pause(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 	iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 	if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 		reset_chip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 	/* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	 * do not reset adapter, jump to initialize_adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 	if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 		status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 		goto recover_ha_init_adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	/* For the ISP-8xxx adapter, issue a stop_firmware if invoked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 	 * from eh_host_reset or ioctl module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 	if (is_qla80XX(ha) && !reset_chip &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 	    test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 		    "scsi%ld: %s - Performing stop_firmware...\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 		    ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 		status = ha->isp_ops->reset_firmware(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 		if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 			ha->isp_ops->disable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 			qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 			qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 			/* If the stop_firmware fails then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 			 * reset the entire chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 			reset_chip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 			clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 			set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 	/* Issue full chip reset if recovering from a catastrophic error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 	 * or if stop_firmware fails for ISP-8xxx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) 	 * This is the default case for ISP-4xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 	if (is_qla40XX(ha) || reset_chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 		if (is_qla40XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 			goto chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 		/* Check if 8XXX firmware is alive or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 		 * We may have arrived here from NEED_RESET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 		 * detection only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 		if (test_bit(AF_FW_RECOVERY, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 			goto chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 		wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 		while (time_before(jiffies, wait)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 			if (qla4_8xxx_check_fw_alive(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 				qla4xxx_mailbox_premature_completion(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 			set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) 			schedule_timeout(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) chip_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 		if (!test_bit(AF_FW_RECOVERY, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 			qla4xxx_cmd_wait(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 		qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 		    "scsi%ld: %s - Performing chip reset..\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 		    ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) 		status = ha->isp_ops->reset_chip(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) 		qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 	/* Flush any pending ddb changed AENs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) 	qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) recover_ha_init_adapter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 	/* Upon successful firmware/chip reset, re-initialize the adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 	if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 		/* For ISP-4xxx, force function 1 to always initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 		 * before function 3 to prevent both funcions from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 		 * stepping on top of the other */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 		if (is_qla40XX(ha) && (ha->mac_index == 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) 			ssleep(6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) 		/* NOTE: AF_ONLINE flag set upon successful completion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) 		 * qla4xxx_initialize_adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 		status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 		if (is_qla80XX(ha) && (status == QLA_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 			status = qla4_8xxx_check_init_adapter_retry(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) 			if (status == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) 				ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 					   ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 				qla4xxx_dead_adapter_cleanup(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 				clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) 				clear_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 				clear_bit(DPC_RESET_HA_FW_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) 					  &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) 				goto exit_recover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) 	/* Retry failed adapter initialization, if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) 	 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) 	 * case to prevent ping-pong resets between functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 	if (!test_bit(AF_ONLINE, &ha->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 	    !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 		/* Adapter initialization failed, see if we can retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 		 * resetting the ha.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 		 * Since we don't want to block the DPC for too long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) 		 * with multiple resets in the same thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 		 * utilize DPC to retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 		if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 			dev_state = qla4_8xxx_rd_direct(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) 							QLA8XXX_CRB_DEV_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 			if (dev_state == QLA8XXX_DEV_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 				ql4_printk(KERN_INFO, ha, "%s: don't retry "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 					   "recover adapter. H/W is in Failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) 					   "state\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 				qla4xxx_dead_adapter_cleanup(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) 				clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 				clear_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) 				clear_bit(DPC_RESET_HA_FW_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 						&ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 				status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 				goto exit_recover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 		if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 			ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 			DEBUG2(printk("scsi%ld: recover adapter - retrying "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 				      "(%d) more times\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 				      ha->retry_reset_ha_cnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 			set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 			status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 			if (ha->retry_reset_ha_cnt > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) 				/* Schedule another Reset HA--DPC will retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 				ha->retry_reset_ha_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 				DEBUG2(printk("scsi%ld: recover adapter - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 					      "retry remaining %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 					      ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 					      ha->retry_reset_ha_cnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 				status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 			if (ha->retry_reset_ha_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 				/* Recover adapter retries have been exhausted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 				 * Adapter DEAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 				DEBUG2(printk("scsi%ld: recover adapter "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 					      "failed - board disabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 					      ha->host_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 				qla4xxx_dead_adapter_cleanup(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 				clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 				clear_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 				clear_bit(DPC_RESET_HA_FW_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 					  &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 				status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 		clear_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 		clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 		clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) exit_recover:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 	ha->adapter_error_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 	if (test_bit(AF_ONLINE, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 		ha->isp_ops->enable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 	scsi_unblock_requests(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 	clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 	DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) 	    status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 	if (!iscsi_is_session_online(cls_session)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 		if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 			ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 				   " unblock session\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 				   ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 			iscsi_unblock_session(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 			/* Trigger relogin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 			if (ddb_entry->ddb_type == FLASH_DDB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 				if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 				      test_bit(DF_DISABLE_RELOGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 					       &ddb_entry->flags)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 					qla4xxx_arm_relogin_timer(ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 				iscsi_session_failure(cls_session->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 						      ISCSI_ERR_CONN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 	ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 		   " unblock session\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 		   ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 	iscsi_unblock_session(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 	/* Start scan target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 	if (test_bit(AF_ONLINE, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 		ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 			   " start scan\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 			   ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 		scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 	ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 		   " unblock user space session\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 		   ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 	if (!iscsi_is_session_online(cls_session)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 		iscsi_conn_start(ddb_entry->conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) 		iscsi_conn_login_event(ddb_entry->conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 				       ISCSI_CONN_STATE_LOGGED_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 			   "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 			   ha->host_no, __func__, ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) 			   cls_session->sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 		status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 	iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 	uint16_t relogin_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 	relogin_timer = max(ddb_entry->default_relogin_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 			    (uint16_t)RELOGIN_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 	atomic_set(&ddb_entry->relogin_timer, relogin_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 			  "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 			  ddb_entry->fw_ddb_index, relogin_timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 	qla4xxx_login_flash_ddb(cls_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 	if (!(ddb_entry->ddb_type == FLASH_DDB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 	if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) 	if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 	    !iscsi_is_session_online(cls_sess)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 				  "relogin issued\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 		qla4xxx_relogin_flash_ddb(cls_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 	if (ha->dpc_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 		queue_work(ha->dpc_thread, &ha->dpc_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) static struct qla4_work_evt *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 		   enum qla4_work_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 	struct qla4_work_evt *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 	uint32_t size = sizeof(struct qla4_work_evt) + data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 	e = kzalloc(size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) 	if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) 	INIT_LIST_HEAD(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) 	e->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) 	return e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) static void qla4xxx_post_work(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 			     struct qla4_work_evt *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 	spin_lock_irqsave(&ha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 	list_add_tail(&e->list, &ha->work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 	spin_unlock_irqrestore(&ha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) 	qla4xxx_wake_dpc(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 			  enum iscsi_host_event_code aen_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 			  uint32_t data_size, uint8_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 	struct qla4_work_evt *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 	e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 	if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 	e->u.aen.code = aen_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 	e->u.aen.data_size = data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 	memcpy(e->u.aen.data, data, data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 	qla4xxx_post_work(ha, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 			       uint32_t status, uint32_t pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 			       uint32_t data_size, uint8_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) 	struct qla4_work_evt *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) 	e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 	if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 	e->u.ping.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 	e->u.ping.pid = pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 	e->u.ping.data_size = data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 	memcpy(e->u.ping.data, data, data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 	qla4xxx_post_work(ha, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) static void qla4xxx_do_work(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 	struct qla4_work_evt *e, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 	LIST_HEAD(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 	spin_lock_irqsave(&ha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) 	list_splice_init(&ha->work_list, &work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 	spin_unlock_irqrestore(&ha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 	list_for_each_entry_safe(e, tmp, &work, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 		list_del_init(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 		switch (e->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 		case QLA4_EVENT_AEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 			iscsi_post_host_event(ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 					      &qla4xxx_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 					      e->u.aen.code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 					      e->u.aen.data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 					      e->u.aen.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 		case QLA4_EVENT_PING_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) 			iscsi_ping_comp_event(ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 					      &qla4xxx_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) 					      e->u.ping.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 					      e->u.ping.pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) 					      e->u.ping.data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 					      e->u.ping.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 			ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 				   "supported", e->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) 		kfree(e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300)  * qla4xxx_do_dpc - dpc routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301)  * @work: Context to obtain pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303)  * This routine is a task that is schedule by the interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304)  * to perform the background processing for interrupts.  We put it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305)  * on a task queue that is consumed whenever the scheduler runs; that's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306)  * so you can do anything (i.e. put the process to sleep etc).  In fact,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307)  * the mid-level tries to sleep when it reaches the driver threshold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308)  * "host->can_queue". This can cause a panic if we were in our interrupt code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) static void qla4xxx_do_dpc(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 	struct scsi_qla_host *ha =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 		container_of(work, struct scsi_qla_host, dpc_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 	int status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 			  "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 			  ha->host_no, __func__, ha->flags, ha->dpc_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 	/* Initialization not yet finished. Don't do anything yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 	if (!test_bit(AF_INIT_DONE, &ha->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) 	if (test_bit(AF_EEH_BUSY, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 		DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 		    ha->host_no, __func__, ha->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 	/* post events to application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 	qla4xxx_do_work(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) 	if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) 		if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 			if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 				ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 					   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) 				/* disable pause frame for ISP83xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 				qla4_83xx_disable_pause(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) 					    QLA8XXX_DEV_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) 			ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 			qla4_8xxx_device_state_handler(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 		if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 			if (is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 				if (ha->idc_info.info2 &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 				    ENABLE_INTERNAL_LOOPBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 					ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) 						   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) 					status = qla4_84xx_config_acb(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) 							    ACB_CONFIG_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) 					if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 						ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 							   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 			qla4_83xx_post_idc_ack(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 			clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 		if (is_qla8042(ha) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 		    test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) 			ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 			if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) 			    QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 				ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) 					   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) 			clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) 		if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) 			qla4_8xxx_need_qsnt_handler(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 	if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 	    (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 	    test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 	    test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 		if ((is_qla8022(ha) && ql4xdontresethba) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 		    ((is_qla8032(ha) || is_qla8042(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 		     qla4_83xx_idc_dontreset(ha))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 			DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 			    ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 			clear_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 			clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 			clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 			goto dpc_post_reset_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 		if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 		    test_bit(DPC_RESET_HA, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 			qla4xxx_recover_adapter(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 		if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 			uint8_t wait_time = RESET_INTR_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 			while ((readw(&ha->reg->ctrl_status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 				(CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 				if (--wait_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 				msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 			if (wait_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 				DEBUG2(printk("scsi%ld: %s: SR|FSR "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 					      "bit not cleared-- resetting\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 					      ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 			qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 			if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 				qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 				status = qla4xxx_recover_adapter(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 			clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 			if (status == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 				ha->isp_ops->enable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) dpc_post_reset_ha:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 	/* ---- process AEN? --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 	if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 		qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 	/* ---- Get DHCP IP Address? --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 	if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 		qla4xxx_get_dhcp_ip_address(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 	/* ---- relogin device? --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 	if (adapter_up(ha) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) 	    test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 		iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 	/* ---- link change? --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 	if (!test_bit(AF_LOOPBACK, &ha->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 	    test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 		if (!test_bit(AF_LINK_UP, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 			/* ---- link down? --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 			qla4xxx_mark_all_devices_missing(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 			/* ---- link up? --- *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 			 * F/W will auto login to all devices ONLY ONCE after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 			 * link up during driver initialization and runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 			 * fatal error recovery.  Therefore, the driver must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 			 * manually relogin to devices when recovering from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 			 * connection failures, logouts, expired KATO, etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 			if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 				qla4xxx_build_ddb_list(ha, ha->is_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) 				iscsi_host_for_each_session(ha->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 						qla4xxx_login_flash_ddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 				qla4xxx_relogin_all_devices(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 	if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) 		if (qla4xxx_sysfs_ddb_export(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 			ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471)  * qla4xxx_free_adapter - release the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 	qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 	/* Turn-off interrupts on the card. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 	ha->isp_ops->disable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 		writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 		       &ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 		readl(&ha->reg->ctrl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 	} else if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 		writel(0, &ha->qla4_82xx_reg->host_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 		readl(&ha->qla4_82xx_reg->host_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 	} else if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 		writel(0, &ha->qla4_83xx_reg->risc_intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 		readl(&ha->qla4_83xx_reg->risc_intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 	/* Remove timer thread, if present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) 	if (ha->timer_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) 		qla4xxx_stop_timer(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) 	/* Kill the kernel thread for this host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 	if (ha->dpc_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) 		destroy_workqueue(ha->dpc_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 	/* Kill the kernel thread for this host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) 	if (ha->task_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) 		destroy_workqueue(ha->task_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) 	/* Put firmware in known state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 	ha->isp_ops->reset_firmware(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 	if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 		ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 		qla4_8xxx_clear_drv_active(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 		ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 	/* Detach interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 	qla4xxx_free_irqs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) 	/* free extra memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 	qla4xxx_mem_free(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 	unsigned long mem_base, mem_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 	struct pci_dev *pdev = ha->pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 	status = pci_request_regions(pdev, DRIVER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 		    "scsi(%ld) Failed to reserve PIO regions (%s) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) 		    "status=%d\n", ha->host_no, pci_name(pdev), status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) 	DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	    __func__, pdev->revision));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 	ha->revision_id = pdev->revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 	/* remap phys address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 	mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 	mem_len = pci_resource_len(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 	DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 	    __func__, mem_base, mem_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 	/* mapping of pcibase pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 	ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 	if (!ha->nx_pcibase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 		    "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 		pci_release_regions(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 	/* Mapping of IO base pointer, door bell read and write pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 	/* mapping of IO base pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 	if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 		ha->qla4_82xx_reg = (struct device_reg_82xx  __iomem *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 				    ((uint8_t *)ha->nx_pcibase + 0xbc000 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 				     (ha->pdev->devfn << 11));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 		ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 				    QLA82XX_CAM_RAM_DB2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 	} else if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 		ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) 				    ((uint8_t *)ha->nx_pcibase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) iospace_error_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) /***
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574)  * qla4xxx_iospace_config - maps registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577)  * This routines maps HBA's registers from the pci address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578)  * into the kernel virtual address space for memory mapped i/o.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) int qla4xxx_iospace_config(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 	unsigned long pio, pio_len, pio_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) 	unsigned long mmio, mmio_len, mmio_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 	pio = pci_resource_start(ha->pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 	pio_len = pci_resource_len(ha->pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 	pio_flags = pci_resource_flags(ha->pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 	if (pio_flags & IORESOURCE_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 		if (pio_len < MIN_IOBASE_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 			ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 				"Invalid PCI I/O region size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 			pio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 		ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 		pio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 	/* Use MMIO operations for all accesses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 	mmio = pci_resource_start(ha->pdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 	mmio_len = pci_resource_len(ha->pdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 	mmio_flags = pci_resource_flags(ha->pdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 	if (!(mmio_flags & IORESOURCE_MEM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 		    "region #0 not an MMIO resource, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 	if (mmio_len < MIN_IOBASE_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 		    "Invalid PCI mem region size, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 	if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 		    "Failed to reserve PIO/MMIO regions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 	ha->pio_address = pio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 	ha->pio_length = pio_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 	ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 	if (!ha->reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 		    "cannot remap MMIO, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 		goto iospace_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) iospace_error_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) static struct isp_operations qla4xxx_isp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) 	.iospace_config         = qla4xxx_iospace_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 	.pci_config             = qla4xxx_pci_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) 	.disable_intrs          = qla4xxx_disable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) 	.enable_intrs           = qla4xxx_enable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) 	.start_firmware         = qla4xxx_start_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) 	.intr_handler           = qla4xxx_intr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) 	.interrupt_service_routine = qla4xxx_interrupt_service_routine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) 	.reset_chip             = qla4xxx_soft_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) 	.reset_firmware         = qla4xxx_hw_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) 	.queue_iocb             = qla4xxx_queue_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 	.complete_iocb          = qla4xxx_complete_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 	.rd_shdw_req_q_out      = qla4xxx_rd_shdw_req_q_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 	.rd_shdw_rsp_q_in       = qla4xxx_rd_shdw_rsp_q_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 	.get_sys_info           = qla4xxx_get_sys_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 	.queue_mailbox_command	= qla4xxx_queue_mbox_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) 	.process_mailbox_interrupt = qla4xxx_process_mbox_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) static struct isp_operations qla4_82xx_isp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 	.iospace_config         = qla4_8xxx_iospace_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 	.pci_config             = qla4_8xxx_pci_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 	.disable_intrs          = qla4_82xx_disable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 	.enable_intrs           = qla4_82xx_enable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 	.start_firmware         = qla4_8xxx_load_risc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 	.restart_firmware	= qla4_82xx_try_start_fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 	.intr_handler           = qla4_82xx_intr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 	.interrupt_service_routine = qla4_82xx_interrupt_service_routine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 	.need_reset		= qla4_8xxx_need_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 	.reset_chip             = qla4_82xx_isp_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 	.reset_firmware         = qla4_8xxx_stop_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 	.queue_iocb             = qla4_82xx_queue_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 	.complete_iocb          = qla4_82xx_complete_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 	.rd_shdw_req_q_out      = qla4_82xx_rd_shdw_req_q_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 	.rd_shdw_rsp_q_in       = qla4_82xx_rd_shdw_rsp_q_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) 	.get_sys_info           = qla4_8xxx_get_sys_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 	.rd_reg_direct		= qla4_82xx_rd_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 	.wr_reg_direct		= qla4_82xx_wr_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 	.rd_reg_indirect	= qla4_82xx_md_rd_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 	.wr_reg_indirect	= qla4_82xx_md_wr_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 	.idc_lock		= qla4_82xx_idc_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 	.idc_unlock		= qla4_82xx_idc_unlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 	.rom_lock_recovery	= qla4_82xx_rom_lock_recovery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 	.queue_mailbox_command	= qla4_82xx_queue_mbox_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 	.process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) static struct isp_operations qla4_83xx_isp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 	.iospace_config		= qla4_8xxx_iospace_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 	.pci_config		= qla4_8xxx_pci_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 	.disable_intrs		= qla4_83xx_disable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 	.enable_intrs		= qla4_83xx_enable_intrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) 	.start_firmware		= qla4_8xxx_load_risc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 	.restart_firmware	= qla4_83xx_start_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 	.intr_handler		= qla4_83xx_intr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 	.interrupt_service_routine = qla4_83xx_interrupt_service_routine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 	.need_reset		= qla4_8xxx_need_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) 	.reset_chip		= qla4_83xx_isp_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 	.reset_firmware		= qla4_8xxx_stop_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 	.queue_iocb		= qla4_83xx_queue_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 	.complete_iocb		= qla4_83xx_complete_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 	.rd_shdw_req_q_out	= qla4xxx_rd_shdw_req_q_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 	.rd_shdw_rsp_q_in	= qla4xxx_rd_shdw_rsp_q_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) 	.get_sys_info		= qla4_8xxx_get_sys_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) 	.rd_reg_direct		= qla4_83xx_rd_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) 	.wr_reg_direct		= qla4_83xx_wr_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) 	.rd_reg_indirect	= qla4_83xx_rd_reg_indirect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) 	.wr_reg_indirect	= qla4_83xx_wr_reg_indirect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 	.idc_lock		= qla4_83xx_drv_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 	.idc_unlock		= qla4_83xx_drv_unlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 	.rom_lock_recovery	= qla4_83xx_rom_lock_recovery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 	.queue_mailbox_command	= qla4_83xx_queue_mbox_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 	.process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 	return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 	return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 	return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 	return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 	struct scsi_qla_host *ha = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 	case ISCSI_BOOT_ETH_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) 		rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) 	case ISCSI_BOOT_ETH_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) 		rc = sprintf(str, "0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 	case ISCSI_BOOT_ETH_MAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) 		rc = sysfs_format_mac(str, ha->my_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 				      MAC_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 		rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) 	case ISCSI_BOOT_ETH_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) 	case ISCSI_BOOT_ETH_MAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) 	case ISCSI_BOOT_ETH_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 		rc = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) 	struct scsi_qla_host *ha = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) 	case ISCSI_BOOT_INI_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 		rc = sprintf(str, "%s\n", ha->name_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 		rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 	case ISCSI_BOOT_INI_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 		rc = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 	struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 	case ISCSI_BOOT_TGT_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 		rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 	case ISCSI_BOOT_TGT_IP_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 		if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 			rc = sprintf(buf, "%pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 				     &boot_conn->dest_ipaddr.ip_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 			rc = sprintf(str, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 				     &boot_conn->dest_ipaddr.ip_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 	case ISCSI_BOOT_TGT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 			rc = sprintf(str, "%d\n", boot_conn->dest_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 	case ISCSI_BOOT_TGT_CHAP_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 		rc = sprintf(str,  "%.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 			     boot_conn->chap.target_chap_name_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 			     (char *)&boot_conn->chap.target_chap_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 	case ISCSI_BOOT_TGT_CHAP_SECRET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 		rc = sprintf(str,  "%.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 			     boot_conn->chap.target_secret_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 			     (char *)&boot_conn->chap.target_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) 	case ISCSI_BOOT_TGT_REV_CHAP_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 		rc = sprintf(str,  "%.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) 			     boot_conn->chap.intr_chap_name_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) 			     (char *)&boot_conn->chap.intr_chap_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 	case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 		rc = sprintf(str,  "%.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 			     boot_conn->chap.intr_secret_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 			     (char *)&boot_conn->chap.intr_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 	case ISCSI_BOOT_TGT_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 		rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 	case ISCSI_BOOT_TGT_NIC_ASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 		rc = sprintf(str, "0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 		rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) 	struct scsi_qla_host *ha = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 	struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) 	return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 	struct scsi_qla_host *ha = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 	struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 	return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 	case ISCSI_BOOT_TGT_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 	case ISCSI_BOOT_TGT_IP_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 	case ISCSI_BOOT_TGT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 	case ISCSI_BOOT_TGT_CHAP_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 	case ISCSI_BOOT_TGT_CHAP_SECRET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 	case ISCSI_BOOT_TGT_REV_CHAP_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 	case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 	case ISCSI_BOOT_TGT_NIC_ASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 	case ISCSI_BOOT_TGT_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 		rc = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) static void qla4xxx_boot_release(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 	struct scsi_qla_host *ha = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 	scsi_host_put(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 	dma_addr_t buf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) 	uint32_t addr, pri_addr, sec_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 	uint32_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 	uint16_t func_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 	uint8_t val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 	uint8_t *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 	size_t size = 13 * sizeof(uint8_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 	int ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 	func_num = PCI_FUNC(ha->pdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 	ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 		   __func__, ha->pdev->device, func_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 		if (func_num == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 			addr = NVRAM_PORT0_BOOT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 			pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 			sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 		} else if (func_num == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 			addr = NVRAM_PORT1_BOOT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 			pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 			sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 			goto exit_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 		/* Check Boot Mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) 		val = rd_nvram_byte(ha, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 		if (!(val & 0x07)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 			DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 					  "options : 0x%x\n", __func__, val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 			goto exit_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 		/* get primary valid target index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 		val = rd_nvram_byte(ha, pri_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 		if (val & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 			ddb_index[0] = (val & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 		/* get secondary valid target index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 		val = rd_nvram_byte(ha, sec_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 		if (val & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 			ddb_index[1] = (val & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 		goto exit_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 	} else if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 		buf = dma_alloc_coherent(&ha->pdev->dev, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 					 &buf_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 		if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 			DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 					  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 					   __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 			goto exit_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 		if (ha->port_num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 			offset = BOOT_PARAM_OFFSET_PORT0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 		else if (ha->port_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 			offset = BOOT_PARAM_OFFSET_PORT1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 			goto exit_boot_info_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) 		addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 		       offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) 		if (qla4xxx_get_flash(ha, buf_dma, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) 				      13 * sizeof(uint8_t)) != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 			DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 					  " failed\n", ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 			goto exit_boot_info_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 		/* Check Boot Mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 		if (!(buf[1] & 0x07)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 			DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 					  " : 0x%x\n", buf[1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 			goto exit_boot_info_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 		/* get primary valid target index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 		if (buf[2] & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 			ddb_index[0] = buf[2] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 		/* get secondary valid target index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 		if (buf[11] & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) 			ddb_index[1] = buf[11] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 		goto exit_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 			  " target ID %d\n", __func__, ddb_index[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 			  ddb_index[1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) exit_boot_info_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 	dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) exit_boot_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 	ha->pri_ddb_idx = ddb_index[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 	ha->sec_ddb_idx = ddb_index[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020)  * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022)  * @username: CHAP username to be returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023)  * @password: CHAP password to be returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025)  * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026)  * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027)  * So from the CHAP cache find the first BIDI CHAP entry and set it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028)  * to the boot record in sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 			    char *password)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 	int i, ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 	int max_chap_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 	struct ql4_chap_table *chap_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 		max_chap_entries = (ha->hw.flt_chap_size / 2) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 						sizeof(struct ql4_chap_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 		max_chap_entries = MAX_CHAP_ENTRIES_40XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 	if (!ha->chap_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 		ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 	mutex_lock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 	for (i = 0; i < max_chap_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) 		chap_table = (struct ql4_chap_table *)ha->chap_list + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 		if (chap_table->cookie !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 		    __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 		if (chap_table->flags & BIT_7) /* local */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 		if (!(chap_table->flags & BIT_6)) /* Not BIDI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 		strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 		strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 	mutex_unlock(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 				   struct ql4_boot_session_info *boot_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 				   uint16_t ddb_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 	struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) 	uint16_t idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 	uint16_t options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 	int ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) 				  "%s: Unable to allocate dma buffer.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 	if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 				   fw_ddb_entry_dma, ddb_index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 				  "index [%d]\n", __func__, ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 		goto exit_boot_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 	/* Update target name and IP from DDB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 	memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 	       min(sizeof(boot_sess->target_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 		   sizeof(fw_ddb_entry->iscsi_name)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 	if (options & DDB_OPT_IPV6_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 		memcpy(&boot_conn->dest_ipaddr.ip_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 		       &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 		boot_conn->dest_ipaddr.ip_type = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 		memcpy(&boot_conn->dest_ipaddr.ip_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 		       &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 	boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 	/* update chap information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 	idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 	if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options))	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 		DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 		ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 				       target_chap_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 				       (char *)&boot_conn->chap.target_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) 				       idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 			ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 			goto exit_boot_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) 		boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 		boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 	if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) 		DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 		ret = qla4xxx_get_bidi_chap(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 				    (char *)&boot_conn->chap.intr_chap_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 				    (char *)&boot_conn->chap.intr_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) 			ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 			ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) 			goto exit_boot_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) 		boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) 		boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) exit_boot_target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 	dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 			  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) 	uint16_t ddb_index[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) 	int ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 	memset(ddb_index, 0, sizeof(ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) 	ddb_index[0] = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) 	ddb_index[1] = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) 	ret = get_fw_boot_info(ha, ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 				"%s: No boot target configured.\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 	if (ql4xdisablesysfsboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 		return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 	if (ddb_index[0] == 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) 		goto sec_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 	rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) 				      ddb_index[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) 				  "configured\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) sec_target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 	if (ddb_index[1] == 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 		goto exit_get_boot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 				      ddb_index[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 				  " configured\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) exit_get_boot_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 	struct iscsi_boot_kobj *boot_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 	if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 	if (ql4xdisablesysfsboot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 			   "%s: syfsboot disabled - driver will trigger login "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 			   "and publish session for discovery .\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 		return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 	ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 	if (!ha->boot_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 		goto kset_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 	if (!scsi_host_get(ha->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 		goto kset_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 	boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 					     qla4xxx_show_boot_tgt_pri_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 					     qla4xxx_tgt_get_attr_visibility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 					     qla4xxx_boot_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 	if (!boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 		goto put_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 	if (!scsi_host_get(ha->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 		goto kset_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 	boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 					     qla4xxx_show_boot_tgt_sec_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) 					     qla4xxx_tgt_get_attr_visibility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 					     qla4xxx_boot_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 	if (!boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) 		goto put_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 	if (!scsi_host_get(ha->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 		goto kset_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 	boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 					       qla4xxx_show_boot_ini_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 					       qla4xxx_ini_get_attr_visibility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 					       qla4xxx_boot_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 	if (!boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 		goto put_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 	if (!scsi_host_get(ha->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) 		goto kset_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 	boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) 					       qla4xxx_show_boot_eth_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) 					       qla4xxx_eth_get_attr_visibility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 					       qla4xxx_boot_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 	if (!boot_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) 		goto put_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) put_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 	scsi_host_put(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) kset_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 	iscsi_boot_destroy_kset(ha->boot_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 				  struct ql4_tuple_ddb *tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 	DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 	cls_sess = ddb_entry->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 	cls_conn = ddb_entry->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 	tddb->tpgt = sess->tpgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 	tddb->port = conn->persistent_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 	strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 	strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 				      struct ql4_tuple_ddb *tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 				      uint8_t *flash_isid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 	uint16_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 	tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 	memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 	       min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 	if (options & DDB_OPT_IPV6_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 		sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 		sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 	tddb->port = le16_to_cpu(fw_ddb_entry->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 	if (flash_isid == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 		memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 		       sizeof(tddb->isid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 		memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 				     struct ql4_tuple_ddb *old_tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 				     struct ql4_tuple_ddb *new_tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 				     uint8_t is_isid_compare)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 	if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 	if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 	if (old_tddb->port != new_tddb->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 	/* For multi sessions, driver generates the ISID, so do not compare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 	 * ISID in reset path since it would be a comparison between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 	 * driver generated ISID and firmware generated ISID. This could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 	 * lead to adding duplicated DDBs in the list as driver generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 	 * ISID would not match firmware generated ISID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 	if (is_isid_compare) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 			"%s: old ISID [%pmR] New ISID [%pmR]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 			__func__, old_tddb->isid, new_tddb->isid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 		if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 			   sizeof(old_tddb->isid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 			return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 			  "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 			  old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 			  old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 			  new_tddb->ip_addr, new_tddb->iscsi_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) 				     struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 				     uint32_t *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) 	struct ql4_tuple_ddb *fw_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 	struct ql4_tuple_ddb *tmp_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 	int ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) 	fw_tddb = vzalloc(sizeof(*fw_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 	if (!fw_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 		DEBUG2(ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) 				  "Memory Allocation failed.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 		goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) 	if (!tmp_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 		DEBUG2(ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 				  "Memory Allocation failed.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 		goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 	qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 	for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 		ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 		if (ddb_entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 		qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 		if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 			ret = QLA_SUCCESS; /* found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 			if (index != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 				*index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 			goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) exit_check:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 	if (fw_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 		vfree(fw_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 	if (tmp_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 		vfree(tmp_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410)  * qla4xxx_check_existing_isid - check if target with same isid exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411)  *				 in target list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412)  * @list_nt: list of target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413)  * @isid: isid to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415)  * This routine return QLA_SUCCESS if target with same isid exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 	struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 	list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 		fw_ddb_entry = &nt_ddb_idx->fw_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 		if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 			   sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 			return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 	return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434)  * qla4xxx_update_isid - compare ddbs and updated isid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436)  * @list_nt: list of nt target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437)  * @fw_ddb_entry: firmware ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439)  * This routine update isid if ddbs have same iqn, same isid and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440)  * different IP addr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441)  * Return QLA_SUCCESS if isid is updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) static int qla4xxx_update_isid(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 			       struct list_head *list_nt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 			       struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 	uint8_t base_value, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 	base_value = fw_ddb_entry->isid[1] & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 		fw_ddb_entry->isid[1] = (base_value | (i << 5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 		if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463)  * qla4xxx_should_update_isid - check if isid need to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465)  * @old_tddb: ddb tuple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466)  * @new_tddb: ddb tuple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468)  * Return QLA_SUCCESS if different IP, different PORT, same iqn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469)  * same isid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 				      struct ql4_tuple_ddb *old_tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 				      struct ql4_tuple_ddb *new_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 	if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 		/* Same ip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 		if (old_tddb->port == new_tddb->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 			return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 	if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 		/* different iqn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 	if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 		   sizeof(old_tddb->isid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 		/* different isid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494)  * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496)  * @list_nt: list of nt target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497)  * @fw_ddb_entry: firmware ddb entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499)  * This routine check if fw_ddb_entry already exists in list_nt to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500)  * duplicate ddb in list_nt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501)  * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502)  * Note: This function also update isid of DDB if required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 				       struct list_head *list_nt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 				       struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 	struct qla_ddb_index  *nt_ddb_idx, *nt_ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 	struct ql4_tuple_ddb *fw_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) 	struct ql4_tuple_ddb *tmp_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 	int rval, ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 	fw_tddb = vzalloc(sizeof(*fw_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 	if (!fw_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 		DEBUG2(ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 				  "Memory Allocation failed.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 		goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 	if (!tmp_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 		DEBUG2(ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 				  "Memory Allocation failed.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 		ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 		goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 	qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) 	list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 		qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 					  nt_ddb_idx->flash_isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 		ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 		/* found duplicate ddb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 		if (ret == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 			goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) 	list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 		qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 		ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 		if (ret == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 			rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 			if (rval == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 				ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 				ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 			goto exit_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) exit_check:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 	if (fw_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) 		vfree(fw_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 	if (tmp_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 		vfree(tmp_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 	struct qla_ddb_index  *ddb_idx, *ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 	list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 		list_del_init(&ddb_idx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 		vfree(ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) 					struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 	struct sockaddr_in *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 	struct sockaddr_in6 *addr6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 	struct sockaddr *t_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 	struct sockaddr_storage *dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 	char *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 	/* TODO: need to destroy on unload iscsi_endpoint*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) 	dst_addr = vmalloc(sizeof(*dst_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) 	if (!dst_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 	if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) 		t_addr = (struct sockaddr *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 		t_addr->sa_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) 		addr6 = (struct sockaddr_in6 *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 		ip = (char *)&addr6->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) 		memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) 		addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) 		t_addr = (struct sockaddr *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) 		t_addr->sa_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) 		addr = (struct sockaddr_in *)dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) 		ip = (char *)&addr->sin_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 		memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) 		addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) 	ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 	vfree(dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) 	return ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 	if (ql4xdisablesysfsboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 		return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 	if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) 					  struct ddb_entry *ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) 					  uint16_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) 	uint16_t def_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 	ddb_entry->ddb_type = FLASH_DDB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 	ddb_entry->fw_ddb_index = INVALID_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) 	ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 	ddb_entry->ha = ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) 	ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 	ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) 	ddb_entry->chap_tbl_idx = INVALID_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 	atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) 	atomic_set(&ddb_entry->relogin_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 	atomic_set(&ddb_entry->relogin_retry_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) 	def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) 	ddb_entry->default_relogin_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 		(def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) 		def_timeout : LOGIN_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) 	ddb_entry->default_time2wait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) 		le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) 	if (ql4xdisablesysfsboot &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) 	    (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) 		set_bit(DF_BOOT_TGT, &ddb_entry->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 	uint32_t idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 	uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 	uint32_t sts[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 	uint32_t ip_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 	wtime = jiffies + (HZ * IP_CONFIG_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) 		for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 			if (ip_idx[idx] == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 			ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 			if (ret == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 				ip_idx[idx] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) 			ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) 			DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 					  "Waiting for IP state for idx = %d, state = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) 					  ip_idx[idx], ip_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) 			if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) 			    ip_state == IP_ADDRSTATE_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) 			    ip_state == IP_ADDRSTATE_PREFERRED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) 			    ip_state == IP_ADDRSTATE_DEPRICATED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) 			    ip_state == IP_ADDRSTATE_DISABLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) 				ip_idx[idx] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 		/* Break if all IP states checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 		if ((ip_idx[0] == -1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) 		    (ip_idx[1] == -1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 		    (ip_idx[2] == -1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 		    (ip_idx[3] == -1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 		schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 	} while (time_after(wtime, jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 				  struct dev_db_entry *flash_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 	uint16_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 	size_t ip_len = IP_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 	options = le16_to_cpu(fw_ddb_entry->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) 	if (options & DDB_OPT_IPV6_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) 		ip_len = IPv6_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 	if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 	if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 		   sizeof(fw_ddb_entry->isid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 	if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 		   sizeof(fw_ddb_entry->port)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) 				     struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) 				     uint32_t fw_idx, uint32_t *flash_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) 	struct dev_db_entry *flash_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) 	dma_addr_t flash_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) 	uint32_t idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) 	int max_ddbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) 	int ret = QLA_ERROR, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) 	flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) 					 &flash_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 	if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) 		ql4_printk(KERN_ERR, ha, "Out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) 		goto exit_find_st_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 	status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 					  flash_ddb_entry_dma, fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) 	if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 		status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) 		if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) 			*flash_index = fw_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) 			ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) 			goto exit_find_st_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) 	for (idx = 0; idx < max_ddbs; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) 		status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) 						  flash_ddb_entry_dma, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) 		if (status == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 		status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 		if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) 			*flash_index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 			ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) 			goto exit_find_st_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) 	if (idx == max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) 		ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) 			   fw_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) exit_find_st_idx:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) 	if (flash_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) 		dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) 			      flash_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) 				  struct list_head *list_st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) 	struct qla_ddb_index  *st_ddb_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) 	int max_ddbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) 	int fw_idx_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) 	dma_addr_t fw_ddb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) 	uint32_t idx = 0, next_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) 	uint32_t flash_index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) 	uint16_t conn_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) 	fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) 				      &fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) 	if (fw_ddb_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) 		DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) 		goto exit_st_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) 	fw_idx_size = sizeof(struct qla_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) 	for (idx = 0; idx < max_ddbs; idx = next_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801) 		ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) 					      NULL, &next_idx, &state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) 					      &conn_err, NULL, &conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) 		/* Ignore DDB if invalid state (unassigned) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) 		if (state == DDB_DS_UNASSIGNED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) 			goto continue_next_st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) 		/* Check if ST, add to the list_st */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) 		if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) 			goto continue_next_st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) 		st_ddb_idx = vzalloc(fw_idx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) 		if (!st_ddb_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) 		ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) 						&flash_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) 		if (ret == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) 			ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) 				   "No flash entry for ST at idx [%d]\n", idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) 			st_ddb_idx->flash_ddb_idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) 			ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) 				   "ST at idx [%d] is stored at flash [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) 				   idx, flash_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) 			st_ddb_idx->flash_ddb_idx = flash_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) 		st_ddb_idx->fw_ddb_idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) 		list_add_tail(&st_ddb_idx->list, list_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) continue_next_st:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) 		if (next_idx == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) exit_st_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) 		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846)  * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848)  * @list_ddb: List from which failed ddb to be removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850)  * Iterate over the list of DDBs and find and remove DDBs that are either in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851)  * no connection active state or failed state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) 				      struct list_head *list_ddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) 	struct qla_ddb_index  *ddb_idx, *ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) 	uint32_t next_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) 	list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) 		ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) 					      NULL, 0, NULL, &next_idx, &state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) 					      &conn_err, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) 		if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) 		    state == DDB_DS_SESSION_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) 			list_del_init(&ddb_idx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) 			vfree(ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) 					 struct ddb_entry *ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) 					 struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) 	uint32_t max_ddbs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) 	uint16_t ddb_link = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) 	cls_sess = ddb_entry->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) 	ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) 	if (ddb_link < max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) 		sess->discovery_parent_idx = ddb_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) 		sess->discovery_parent_idx = DDB_NO_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) 				   struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) 				   int is_reset, uint16_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) 	uint16_t cmds_max = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) 	uint16_t conn_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) 	uint32_t initial_cmdsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909) 	int ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) 	struct ddb_entry *ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913) 	/* Create session object, with INVALID_ENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914) 	 * the targer_id would get set when we issue the login
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) 	cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) 				       cmds_max, sizeof(struct ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918) 				       sizeof(struct ql4_task_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) 				       initial_cmdsn, INVALID_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) 	if (!cls_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922) 		goto exit_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) 	 * so calling module_put function to decrement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) 	 * reference count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) 	 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) 	module_put(qla4xxx_iscsi_transport.owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) 	ddb_entry->sess = cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) 	cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) 	memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) 	       sizeof(struct dev_db_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938) 	qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940) 	cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) 	if (!cls_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) 		goto exit_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) 	ddb_entry->conn = cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949) 	/* Setup ep, for displaying attributes in sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) 	ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) 	if (ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) 		ep->conn = cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) 		cls_conn->ep = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) 		DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) 		ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957) 		goto exit_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) 	/* Update sess/conn params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) 	qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) 	qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) 	if (is_reset == RESET_ADAPTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) 		iscsi_block_session(cls_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966) 		/* Use the relogin path to discover new devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) 		 *  by short-circuting the logic of setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) 		 *  timer to relogin - instead set the flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969) 		 *  to initiate login right away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) 		set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) 		set_bit(DF_RELOGIN, &ddb_entry->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) exit_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979) static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980) 				       struct list_head *list_ddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) 				       struct dev_db_entry *fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983) 	struct qla_ddb_index  *ddb_idx, *ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) 	uint16_t ddb_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) 	ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) 	list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) 		if (ddb_idx->fw_ddb_idx == ddb_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) 			DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991) 					  "Updating NT parent idx from [%d] to [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) 					  ddb_link, ddb_idx->flash_ddb_idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) 			fw_ddb_entry->ddb_link =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994) 					    cpu_to_le16(ddb_idx->flash_ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000) static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) 				  struct list_head *list_nt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) 				  struct list_head *list_st,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) 				  int is_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) 	struct ddb_entry *ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007) 	dma_addr_t fw_ddb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) 	int max_ddbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009) 	int fw_idx_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) 	uint32_t idx = 0, next_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013) 	uint32_t ddb_idx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) 	uint16_t conn_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) 	uint16_t ddb_link = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016) 	struct qla_ddb_index  *nt_ddb_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) 	fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019) 				      &fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) 	if (fw_ddb_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) 		DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) 		goto exit_nt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) 	fw_idx_size = sizeof(struct qla_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028) 	for (idx = 0; idx < max_ddbs; idx = next_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029) 		ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) 					      NULL, &next_idx, &state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031) 					      &conn_err, NULL, &conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) 		if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) 			goto continue_next_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) 		/* Check if NT, then add to list it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039) 		if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) 			goto continue_next_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) 		ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) 		if (ddb_link < max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044) 			qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) 		if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047) 		    state == DDB_DS_SESSION_FAILED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) 		    (is_reset == INIT_ADAPTER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) 			goto continue_next_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) 				  "Adding  DDB to session = 0x%x\n", idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) 		if (is_reset == INIT_ADAPTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) 			nt_ddb_idx = vmalloc(fw_idx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) 			if (!nt_ddb_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059) 			nt_ddb_idx->fw_ddb_idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061) 			/* Copy original isid as it may get updated in function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) 			 * qla4xxx_update_isid(). We need original isid in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) 			 * function qla4xxx_compare_tuple_ddb to find duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064) 			 * target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) 			memcpy(&nt_ddb_idx->flash_isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) 			       &fw_ddb_entry->isid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) 			       sizeof(nt_ddb_idx->flash_isid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069) 			ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070) 							  fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) 			if (ret == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) 				/* free nt_ddb_idx and do not add to list_nt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) 				vfree(nt_ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) 				goto continue_next_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077) 			/* Copy updated isid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) 			memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) 			       sizeof(struct dev_db_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081) 			list_add_tail(&nt_ddb_idx->list, list_nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) 		} else if (is_reset == RESET_ADAPTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083) 			ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) 							&ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085) 			if (ret == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) 				ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) 								       ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088) 				if (ddb_entry != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089) 					qla4xxx_update_sess_disc_idx(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) 								     ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) 								  fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) 				goto continue_next_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7093) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7094) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7096) 		ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7097) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7098) 			goto exit_nt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7100) continue_next_nt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7101) 		if (next_idx == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7102) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7105) exit_nt_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7106) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7107) 		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7110) static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7111) 				      struct list_head *list_nt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7112) 				      uint16_t target_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7114) 	struct dev_db_entry *fw_ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7115) 	dma_addr_t fw_ddb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7116) 	int max_ddbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7117) 	int fw_idx_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7118) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7119) 	uint32_t idx = 0, next_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7120) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7121) 	uint16_t conn_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7122) 	struct qla_ddb_index  *nt_ddb_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7124) 	fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7125) 				      &fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7126) 	if (fw_ddb_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7127) 		DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7128) 		goto exit_new_nt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7130) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7131) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7132) 	fw_idx_size = sizeof(struct qla_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7134) 	for (idx = 0; idx < max_ddbs; idx = next_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7135) 		ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7136) 					      NULL, &next_idx, &state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7137) 					      &conn_err, NULL, &conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7138) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7139) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7141) 		/* Check if NT, then add it to list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7142) 		if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7143) 			goto continue_next_new_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7145) 		if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7146) 			goto continue_next_new_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7148) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7149) 				  "Adding  DDB to session = 0x%x\n", idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7151) 		nt_ddb_idx = vmalloc(fw_idx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7152) 		if (!nt_ddb_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7153) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7155) 		nt_ddb_idx->fw_ddb_idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7157) 		ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7158) 		if (ret == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7159) 			/* free nt_ddb_idx and do not add to list_nt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7160) 			vfree(nt_ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7161) 			goto continue_next_new_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7164) 		if (target_id < max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7165) 			fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7167) 		list_add_tail(&nt_ddb_idx->list, list_nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7169) 		ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7170) 					      idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7171) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7172) 			goto exit_new_nt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7174) continue_next_new_nt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7175) 		if (next_idx == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7176) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7179) exit_new_nt_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7180) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7181) 		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7184) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7185)  * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7186)  * @dev: dev associated with the sysfs entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7187)  * @data: pointer to flashnode session object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7189)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7190)  *	1: if flashnode entry is non-persistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7191)  *	0: if flashnode entry is persistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7192)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7193) static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7195) 	struct iscsi_bus_flash_session *fnode_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7197) 	if (!iscsi_flashnode_bus_match(dev, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7198) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7200) 	fnode_sess = iscsi_dev_to_flash_session(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7202) 	return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7205) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7206)  * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7207)  * @ha: pointer to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7208)  * @fw_ddb_entry: flash ddb data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7209)  * @idx: target index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7210)  * @user: if set then this call is made from userland else from kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7211)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7212)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7213)  * On sucess: QLA_SUCCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7214)  * On failure: QLA_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7215)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7216)  * This create separate sysfs entries for session and connection attributes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7217)  * the given fw ddb entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7218)  * If this is invoked as a result of a userspace call then the entry is marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7219)  * as nonpersistent using flash_state field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7220)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7221) static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7222) 					struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7223) 					uint16_t *idx, int user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7225) 	struct iscsi_bus_flash_session *fnode_sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7226) 	struct iscsi_bus_flash_conn *fnode_conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7227) 	int rc = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7229) 	fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7230) 						 &qla4xxx_iscsi_transport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7231) 	if (!fnode_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7232) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7233) 			   "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7234) 			   __func__, *idx, ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7235) 		goto exit_tgt_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7238) 	fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7239) 						 &qla4xxx_iscsi_transport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7240) 	if (!fnode_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7241) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7242) 			   "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7243) 			   __func__, *idx, ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7244) 		goto free_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7247) 	if (user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7248) 		fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7249) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7250) 		fnode_sess->flash_state = DEV_DB_PERSISTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7252) 		if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7253) 			fnode_sess->is_boot_target = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7254) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7255) 			fnode_sess->is_boot_target = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7258) 	rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7259) 					   fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7260) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7261) 		goto free_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7263) 	ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7264) 		   __func__, fnode_sess->dev.kobj.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7266) 	ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7267) 		   __func__, fnode_conn->dev.kobj.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7269) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7271) free_sess:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7272) 	iscsi_destroy_flashnode_sess(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7274) exit_tgt_create:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7275) 	return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7278) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7279)  * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7280)  * @shost: pointer to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7281)  * @buf: type of ddb entry (ipv4/ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7282)  * @len: length of buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7283)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7284)  * This creates new ddb entry in the flash by finding first free index and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7285)  * storing default ddb there. And then create sysfs entry for the new ddb entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7286)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7287) static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7288) 				 int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7290) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7291) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7292) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7293) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7294) 	uint16_t idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7295) 	uint16_t max_ddbs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7296) 	uint32_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7297) 	uint32_t rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7299) 	if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7300) 	    strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7301) 		DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7302) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7303) 		goto exit_ddb_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7306) 	max_ddbs =  is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7307) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7309) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7310) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7311) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7312) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7313) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7314) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7315) 		goto exit_ddb_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7318) 	dev = iscsi_find_flashnode_sess(ha->host, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7319) 					qla4xxx_sysfs_ddb_is_non_persistent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7320) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7321) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7322) 			   "%s: A non-persistent entry %s found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7323) 			   __func__, dev->kobj.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7324) 		put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7325) 		goto exit_ddb_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7328) 	/* Index 0 and 1 are reserved for boot target entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7329) 	for (idx = 2; idx < max_ddbs; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7330) 		if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7331) 					     fw_ddb_entry_dma, idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7332) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7335) 	if (idx == max_ddbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7336) 		goto exit_ddb_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7338) 	if (!strncasecmp("ipv6", buf, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7339) 		options |= IPV6_DEFAULT_DDB_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7341) 	rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7342) 	if (rval == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7343) 		goto exit_ddb_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7345) 	rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7347) exit_ddb_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7348) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7349) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7350) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7351) 	if (rval == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7352) 		return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7353) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7354) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7357) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7358)  * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7359)  * @fnode_sess: pointer to session attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7360)  * @fnode_conn: pointer to connection attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7362)  * This writes the contents of target ddb buffer to Flash with a valid cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7363)  * value in order to make the ddb entry persistent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7364)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7365) static int  qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7366) 				    struct iscsi_bus_flash_conn *fnode_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7368) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7369) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7370) 	uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7371) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7372) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7373) 	uint32_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7374) 	int rval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7376) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7377) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7378) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7379) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7380) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7381) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7382) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7383) 		goto exit_ddb_apply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7386) 	if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7387) 		options |= IPV6_DEFAULT_DDB_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7389) 	rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7390) 	if (rval == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7391) 		goto exit_ddb_apply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7393) 	dev_db_start_offset += (fnode_sess->target_id *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7394) 				sizeof(*fw_ddb_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7396) 	qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7397) 	fw_ddb_entry->cookie = DDB_VALID_COOKIE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7399) 	rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7400) 				 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7402) 	if (rval == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7403) 		fnode_sess->flash_state = DEV_DB_PERSISTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7404) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7405) 			   "%s: flash node %u of host %lu written to flash\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7406) 			   __func__, fnode_sess->target_id, ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7407) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7408) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7409) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7410) 			   "%s: Error while writing flash node %u of host %lu to flash\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7411) 			   __func__, fnode_sess->target_id, ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7414) exit_ddb_apply:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7415) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7416) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7417) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7418) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7421) static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7422) 					   struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7423) 					   uint16_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7425) 	struct dev_db_entry *ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7426) 	dma_addr_t ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7427) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7428) 	uint32_t mbx_sts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7429) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7430) 	uint16_t tmo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7431) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7433) 	ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7434) 				       &ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7435) 	if (!ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7436) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7437) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7438) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7439) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7442) 	memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7444) 	ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7445) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7446) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7447) 				  "%s: Unable to set ddb entry for index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7448) 				  __func__, idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7449) 		goto exit_ddb_conn_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7452) 	qla4xxx_conn_open(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7454) 	/* To ensure that sendtargets is done, wait for at least 12 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7455) 	tmo = ((ha->def_timeout > LOGIN_TOV) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7456) 	       (ha->def_timeout < LOGIN_TOV * 10) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7457) 	       ha->def_timeout : LOGIN_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7459) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7460) 			  "Default time to wait for login to ddb %d\n", tmo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7462) 	wtime = jiffies + (HZ * tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7463) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7464) 		ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7465) 					      NULL, &state, &conn_err, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7466) 					      NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7467) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7468) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7470) 		if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7471) 		    state == DDB_DS_SESSION_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7472) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7474) 		schedule_timeout_uninterruptible(HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7475) 	} while (time_after(wtime, jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7477) exit_ddb_conn_open:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7478) 	if (ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7479) 		dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7480) 				  ddb_entry, ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7481) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7484) static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7485) 				struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7486) 				uint16_t target_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7488) 	struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7489) 	struct list_head list_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7490) 	uint16_t ddb_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7491) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7493) 	if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7494) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7495) 			   "%s: A discovery already in progress!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7496) 		return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7499) 	INIT_LIST_HEAD(&list_nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7501) 	set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7503) 	ret = qla4xxx_get_ddb_index(ha, &ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7504) 	if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7505) 		goto exit_login_st_clr_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7507) 	ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7508) 	if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7509) 		goto exit_login_st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7511) 	qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7513) 	list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7514) 		list_del_init(&ddb_idx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7515) 		qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7516) 		vfree(ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7519) exit_login_st:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7520) 	if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7521) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7522) 			   "Unable to clear DDB index = 0x%x\n", ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7525) 	clear_bit(ddb_index, ha->ddb_idx_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7527) exit_login_st_clr_bit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7528) 	clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7529) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7532) static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7533) 				struct dev_db_entry *fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7534) 				uint16_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7536) 	int ret = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7538) 	ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7539) 	if (ret != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7540) 		ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7541) 					      idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7542) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7543) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7545) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7548) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7549)  * qla4xxx_sysfs_ddb_login - Login to the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7550)  * @fnode_sess: pointer to session attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7551)  * @fnode_conn: pointer to connection attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7552)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7553)  * This logs in to the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7554)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7555) static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7556) 				   struct iscsi_bus_flash_conn *fnode_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7558) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7559) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7560) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7561) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7562) 	uint32_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7563) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7565) 	if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7566) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7567) 			   "%s: Target info is not persistent\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7568) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7569) 		goto exit_ddb_login;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7572) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7573) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7574) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7575) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7576) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7577) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7578) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7579) 		goto exit_ddb_login;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7582) 	if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7583) 		options |= IPV6_DEFAULT_DDB_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7585) 	ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7586) 	if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7587) 		goto exit_ddb_login;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7589) 	qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7590) 	fw_ddb_entry->cookie = DDB_VALID_COOKIE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7592) 	if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7593) 		ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7594) 					   fnode_sess->target_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7595) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7596) 		ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7597) 					   fnode_sess->target_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7599) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7600) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7602) exit_ddb_login:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7603) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7604) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7605) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7606) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7609) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7610)  * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7611)  * @cls_sess: pointer to session to be logged out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7612)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7613)  * This performs session log out from the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7614)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7615) static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7617) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7618) 	struct ddb_entry *ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7619) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7620) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7621) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7622) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7623) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7624) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7625) 	int options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7626) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7628) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7629) 	ddb_entry = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7630) 	ha = ddb_entry->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7632) 	if (ddb_entry->ddb_type != FLASH_DDB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7633) 		ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7634) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7635) 		ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7636) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7639) 	if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7640) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7641) 			   "%s: Logout from boot target entry is not permitted.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7642) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7643) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7644) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7647) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7648) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7649) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7650) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7651) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7652) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7653) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7654) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7656) 	if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7657) 		goto ddb_logout_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7659) 	ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7660) 				      fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7661) 				      NULL, NULL, &ddb_state, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7662) 				      NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7663) 	if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7664) 		goto ddb_logout_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7666) 	if (ddb_state == DDB_DS_SESSION_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7667) 		goto ddb_logout_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7669) 	/* wait until next relogin is triggered using DF_RELOGIN and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7670) 	 * clear DF_RELOGIN to avoid invocation of further relogin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7671) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7672) 	wtime = jiffies + (HZ * RELOGIN_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7673) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7674) 		if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7675) 			goto ddb_logout_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7677) 		schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7678) 	} while ((time_after(wtime, jiffies)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7680) ddb_logout_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7681) 	atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7682) 	atomic_set(&ddb_entry->relogin_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7684) 	options = LOGOUT_OPTION_CLOSE_SESSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7685) 	qla4xxx_session_logout_ddb(ha, ddb_entry, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7687) 	memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7688) 	wtime = jiffies + (HZ * LOGOUT_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7689) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7690) 		ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7691) 					      fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7692) 					      NULL, NULL, &ddb_state, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7693) 					      NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7694) 		if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7695) 			goto ddb_logout_clr_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7697) 		if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7698) 		    (ddb_state == DDB_DS_SESSION_FAILED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7699) 			goto ddb_logout_clr_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7701) 		schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7702) 	} while ((time_after(wtime, jiffies)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7704) ddb_logout_clr_sess:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7705) 	qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7706) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7707) 	 * we have decremented the reference count of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7708) 	 * when we setup the session to have the driver unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7709) 	 * to be seamless without actually destroying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7710) 	 * session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7711) 	 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7712) 	try_module_get(qla4xxx_iscsi_transport.owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7713) 	iscsi_destroy_endpoint(ddb_entry->conn->ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7715) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7716) 	qla4xxx_free_ddb(ha, ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7717) 	clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7718) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7720) 	iscsi_session_teardown(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7722) 	clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7723) 	ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7725) exit_ddb_logout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7726) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7727) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7728) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7729) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7733)  * qla4xxx_sysfs_ddb_logout - Logout from the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7734)  * @fnode_sess: pointer to session attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7735)  * @fnode_conn: pointer to connection attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7736)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7737)  * This performs log out from the specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7738)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7739) static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7740) 				    struct iscsi_bus_flash_conn *fnode_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7742) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7743) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7744) 	struct ql4_tuple_ddb *flash_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7745) 	struct ql4_tuple_ddb *tmp_tddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7746) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7747) 	struct ddb_entry *ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7748) 	dma_addr_t fw_ddb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7749) 	uint32_t next_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7750) 	uint32_t state = 0, conn_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7751) 	uint16_t conn_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7752) 	int idx, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7753) 	int status, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7755) 	fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7756) 				      &fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7757) 	if (fw_ddb_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7758) 		ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7759) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7760) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7763) 	flash_tddb = vzalloc(sizeof(*flash_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7764) 	if (!flash_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7765) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7766) 			   "%s:Memory Allocation failed.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7767) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7768) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7771) 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7772) 	if (!tmp_tddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7773) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7774) 			   "%s:Memory Allocation failed.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7775) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7776) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7779) 	if (!fnode_sess->targetname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7780) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7781) 			   "%s:Cannot logout from SendTarget entry\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7782) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7783) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7784) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7787) 	if (fnode_sess->is_boot_target) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7788) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7789) 			   "%s: Logout from boot target entry is not permitted.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7790) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7791) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7792) 		goto exit_ddb_logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7795) 	strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7796) 		ISCSI_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7798) 	if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7799) 		sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7800) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7801) 		sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7803) 	flash_tddb->tpgt = fnode_sess->tpgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7804) 	flash_tddb->port = fnode_conn->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7806) 	COPY_ISID(flash_tddb->isid, fnode_sess->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7808) 	for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7809) 		ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7810) 		if (ddb_entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7811) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7813) 		if (ddb_entry->ddb_type != FLASH_DDB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7814) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7816) 		index = ddb_entry->sess->target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7817) 		status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7818) 						 fw_ddb_dma, NULL, &next_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7819) 						 &state, &conn_err, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7820) 						 &conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7821) 		if (status == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7822) 			ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7823) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7824) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7826) 		qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7828) 		status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7829) 						   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7830) 		if (status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7831) 			ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7832) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7833) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7836) 	if (idx == MAX_DDB_ENTRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7837) 		ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7839) exit_ddb_logout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7840) 	if (flash_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7841) 		vfree(flash_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7842) 	if (tmp_tddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7843) 		vfree(tmp_tddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7844) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7845) 		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7847) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7850) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7851) qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7852) 			    int param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7854) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7855) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7856) 	struct iscsi_bus_flash_conn *fnode_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7857) 	struct ql4_chap_table chap_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7858) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7859) 	int parent_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7860) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7862) 	dev = iscsi_find_flashnode_conn(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7863) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7864) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7866) 	fnode_conn = iscsi_dev_to_flash_conn(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7868) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7869) 	case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7870) 		rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7871) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7872) 	case ISCSI_FLASHNODE_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7873) 		rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7874) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7875) 	case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7876) 		rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7877) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7878) 	case ISCSI_FLASHNODE_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7879) 		rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7880) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7881) 	case ISCSI_FLASHNODE_ENTRY_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7882) 		rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7883) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7884) 	case ISCSI_FLASHNODE_HDR_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7885) 		rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7886) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7887) 	case ISCSI_FLASHNODE_DATA_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7888) 		rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7889) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7890) 	case ISCSI_FLASHNODE_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7891) 		rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7892) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7893) 	case ISCSI_FLASHNODE_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7894) 		rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7895) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7896) 	case ISCSI_FLASHNODE_DATASEQ_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7897) 		rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7898) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7899) 	case ISCSI_FLASHNODE_PDU_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7900) 		rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7901) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7902) 	case ISCSI_FLASHNODE_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7903) 		rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7904) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7905) 	case ISCSI_FLASHNODE_SNACK_REQ_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7906) 		rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7907) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7908) 	case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7909) 		rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7910) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7911) 	case ISCSI_FLASHNODE_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7912) 		rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7913) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7914) 	case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7915) 		rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7916) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7917) 	case ISCSI_FLASHNODE_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7918) 		rc = sprintf(buf, "%u\n", fnode_sess->erl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7919) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7920) 	case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7921) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7922) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7923) 	case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7924) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7925) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7926) 	case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7927) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7928) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7929) 	case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7930) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7931) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7932) 	case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7933) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7934) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7935) 	case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7936) 		rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7937) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7938) 	case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7939) 		rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7940) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7941) 	case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7942) 		rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7943) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7944) 	case ISCSI_FLASHNODE_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7945) 		rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7946) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7947) 	case ISCSI_FLASHNODE_DEF_TIME2WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7948) 		rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7949) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7950) 	case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7951) 		rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7952) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7953) 	case ISCSI_FLASHNODE_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7954) 		rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7955) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7956) 	case ISCSI_FLASHNODE_KEEPALIVE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7957) 		rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7958) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7959) 	case ISCSI_FLASHNODE_ISID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7960) 		rc = sprintf(buf, "%pm\n", fnode_sess->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7961) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7962) 	case ISCSI_FLASHNODE_TSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7963) 		rc = sprintf(buf, "%u\n", fnode_sess->tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7964) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7965) 	case ISCSI_FLASHNODE_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7966) 		rc = sprintf(buf, "%d\n", fnode_conn->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7967) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7968) 	case ISCSI_FLASHNODE_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7969) 		rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7970) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7971) 	case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7972) 		rc = sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7973) 			     fnode_sess->default_taskmgmt_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7974) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7975) 	case ISCSI_FLASHNODE_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7976) 		if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7977) 			rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7978) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7979) 			rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7980) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7981) 	case ISCSI_FLASHNODE_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7982) 		if (fnode_sess->targetalias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7983) 			rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7984) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7985) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7986) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7987) 	case ISCSI_FLASHNODE_REDIRECT_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7988) 		if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7989) 			rc = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7990) 				     fnode_conn->redirect_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7991) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7992) 			rc = sprintf(buf, "%pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7993) 				     fnode_conn->redirect_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7994) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7995) 	case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7996) 		rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7997) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7998) 	case ISCSI_FLASHNODE_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7999) 		rc = sprintf(buf, "%u\n", fnode_conn->local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8000) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8001) 	case ISCSI_FLASHNODE_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8002) 		rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8003) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8004) 	case ISCSI_FLASHNODE_IPV6_TC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8005) 		if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8006) 			rc = sprintf(buf, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8007) 				     fnode_conn->ipv6_traffic_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8008) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8009) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8010) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8011) 	case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8012) 		rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8013) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8014) 	case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8015) 		if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8016) 			rc = sprintf(buf, "%pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8017) 				     fnode_conn->link_local_ipv6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8018) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8019) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8020) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8021) 	case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8022) 		rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8023) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8024) 	case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8025) 		if (fnode_sess->discovery_parent_type == DDB_ISNS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8026) 			parent_type = ISCSI_DISC_PARENT_ISNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8027) 		else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8028) 			parent_type = ISCSI_DISC_PARENT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8029) 		else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8030) 			parent_type = ISCSI_DISC_PARENT_SENDTGT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8031) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8032) 			parent_type = ISCSI_DISC_PARENT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8034) 		rc = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8035) 			     iscsi_get_discovery_parent_name(parent_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8036) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8037) 	case ISCSI_FLASHNODE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8038) 		if (fnode_sess->targetname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8039) 			rc = sprintf(buf, "%s\n", fnode_sess->targetname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8040) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8041) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8042) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8043) 	case ISCSI_FLASHNODE_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8044) 		rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8045) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8046) 	case ISCSI_FLASHNODE_TCP_XMIT_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8047) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8048) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8049) 	case ISCSI_FLASHNODE_TCP_RECV_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8050) 		rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8051) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8052) 	case ISCSI_FLASHNODE_CHAP_OUT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8053) 		rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8054) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8055) 	case ISCSI_FLASHNODE_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8056) 		if (fnode_sess->chap_auth_en) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8057) 			qla4xxx_get_uni_chap_at_index(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8058) 						      chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8059) 						      chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8060) 						      fnode_sess->chap_out_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8061) 			rc = sprintf(buf, "%s\n", chap_tbl.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8062) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8063) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8064) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8065) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8066) 	case ISCSI_FLASHNODE_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8067) 		if (fnode_sess->chap_auth_en) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8068) 			qla4xxx_get_uni_chap_at_index(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8069) 						      chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8070) 						      chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8071) 						      fnode_sess->chap_out_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8072) 			rc = sprintf(buf, "%s\n", chap_tbl.secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8073) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8074) 			rc = sprintf(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8075) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8076) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8077) 	case ISCSI_FLASHNODE_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8078) 		rc = sprintf(buf, "%u\n", fnode_conn->statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8079) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8080) 	case ISCSI_FLASHNODE_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8081) 		rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8082) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8083) 	case ISCSI_FLASHNODE_IS_BOOT_TGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8084) 		rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8085) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8086) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8087) 		rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8088) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8089) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8091) 	put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8092) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8095) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8096)  * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8097)  * @fnode_sess: pointer to session attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8098)  * @fnode_conn: pointer to connection attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8099)  * @data: Parameters and their values to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8100)  * @len: len of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8102)  * This sets the parameter of flash ddb entry and writes them to flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8103)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8104) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8105) qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8106) 			    struct iscsi_bus_flash_conn *fnode_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8107) 			    void *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8109) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8110) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8111) 	struct iscsi_flashnode_param_info *fnode_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8112) 	struct ql4_chap_table chap_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8113) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8114) 	uint16_t chap_out_idx = INVALID_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8115) 	int rc = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8116) 	uint32_t rem = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8118) 	memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8119) 	nla_for_each_attr(attr, data, len, rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8120) 		fnode_param = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8122) 		switch (fnode_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8123) 		case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8124) 			fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8125) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8126) 		case ISCSI_FLASHNODE_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8127) 			memcpy(fnode_sess->portal_type, fnode_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8128) 			       strlen(fnode_sess->portal_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8129) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8130) 		case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8131) 			fnode_sess->auto_snd_tgt_disable =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8132) 							fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8133) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8134) 		case ISCSI_FLASHNODE_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8135) 			fnode_sess->discovery_sess = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8136) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8137) 		case ISCSI_FLASHNODE_ENTRY_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8138) 			fnode_sess->entry_state = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8139) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8140) 		case ISCSI_FLASHNODE_HDR_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8141) 			fnode_conn->hdrdgst_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8142) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8143) 		case ISCSI_FLASHNODE_DATA_DGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8144) 			fnode_conn->datadgst_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8145) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8146) 		case ISCSI_FLASHNODE_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8147) 			fnode_sess->imm_data_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8148) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8149) 		case ISCSI_FLASHNODE_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8150) 			fnode_sess->initial_r2t_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8151) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8152) 		case ISCSI_FLASHNODE_DATASEQ_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8153) 			fnode_sess->dataseq_inorder_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8154) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8155) 		case ISCSI_FLASHNODE_PDU_INORDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8156) 			fnode_sess->pdu_inorder_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8157) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8158) 		case ISCSI_FLASHNODE_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8159) 			fnode_sess->chap_auth_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8160) 			/* Invalidate chap index if chap auth is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8161) 			if (!fnode_sess->chap_auth_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8162) 				fnode_sess->chap_out_idx = INVALID_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8164) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8165) 		case ISCSI_FLASHNODE_SNACK_REQ_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8166) 			fnode_conn->snack_req_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8167) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8168) 		case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8169) 			fnode_sess->discovery_logout_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8170) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8171) 		case ISCSI_FLASHNODE_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8172) 			fnode_sess->bidi_chap_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8173) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8174) 		case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8175) 			fnode_sess->discovery_auth_optional =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8176) 							fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8177) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8178) 		case ISCSI_FLASHNODE_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8179) 			fnode_sess->erl = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8180) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8181) 		case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8182) 			fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8183) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8184) 		case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8185) 			fnode_conn->tcp_nagle_disable = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8186) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8187) 		case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8188) 			fnode_conn->tcp_wsf_disable = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8189) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8190) 		case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8191) 			fnode_conn->tcp_timer_scale = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8192) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8193) 		case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8194) 			fnode_conn->tcp_timestamp_en = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8196) 		case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8197) 			fnode_conn->fragment_disable = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8198) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8199) 		case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8200) 			fnode_conn->max_recv_dlength =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8201) 					*(unsigned *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8202) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8203) 		case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8204) 			fnode_conn->max_xmit_dlength =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8205) 					*(unsigned *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8206) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8207) 		case ISCSI_FLASHNODE_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8208) 			fnode_sess->first_burst =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8209) 					*(unsigned *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8210) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8211) 		case ISCSI_FLASHNODE_DEF_TIME2WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8212) 			fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8213) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8214) 		case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8215) 			fnode_sess->time2retain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8216) 						*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8217) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8218) 		case ISCSI_FLASHNODE_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8219) 			fnode_sess->max_r2t =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8220) 					*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8221) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8222) 		case ISCSI_FLASHNODE_KEEPALIVE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8223) 			fnode_conn->keepalive_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8224) 				*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8225) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8226) 		case ISCSI_FLASHNODE_ISID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8227) 			memcpy(fnode_sess->isid, fnode_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8228) 			       sizeof(fnode_sess->isid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8229) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8230) 		case ISCSI_FLASHNODE_TSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8231) 			fnode_sess->tsid = *(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8232) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8233) 		case ISCSI_FLASHNODE_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8234) 			fnode_conn->port = *(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8235) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8236) 		case ISCSI_FLASHNODE_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8237) 			fnode_sess->max_burst = *(unsigned *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8238) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8239) 		case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8240) 			fnode_sess->default_taskmgmt_timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8241) 						*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8242) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8243) 		case ISCSI_FLASHNODE_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8244) 			memcpy(fnode_conn->ipaddress, fnode_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8245) 			       IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8247) 		case ISCSI_FLASHNODE_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8248) 			rc = iscsi_switch_str_param(&fnode_sess->targetalias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8249) 						    (char *)fnode_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8250) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8251) 		case ISCSI_FLASHNODE_REDIRECT_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8252) 			memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8253) 			       IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8254) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8255) 		case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8256) 			fnode_conn->max_segment_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8257) 					*(unsigned *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8258) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8259) 		case ISCSI_FLASHNODE_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8260) 			fnode_conn->local_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8261) 						*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8262) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8263) 		case ISCSI_FLASHNODE_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8264) 			fnode_conn->ipv4_tos = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8265) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8266) 		case ISCSI_FLASHNODE_IPV6_TC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8267) 			fnode_conn->ipv6_traffic_class = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8268) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8269) 		case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8270) 			fnode_conn->ipv6_flow_label = fnode_param->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8271) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8272) 		case ISCSI_FLASHNODE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8273) 			rc = iscsi_switch_str_param(&fnode_sess->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8274) 						    (char *)fnode_param->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8275) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8276) 		case ISCSI_FLASHNODE_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8277) 			fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8278) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8279) 		case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8280) 			memcpy(fnode_conn->link_local_ipv6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8281) 			       fnode_param->value, IPv6_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8282) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8283) 		case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8284) 			fnode_sess->discovery_parent_idx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8285) 						*(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8286) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8287) 		case ISCSI_FLASHNODE_TCP_XMIT_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8288) 			fnode_conn->tcp_xmit_wsf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8289) 						*(uint8_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8290) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8291) 		case ISCSI_FLASHNODE_TCP_RECV_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8292) 			fnode_conn->tcp_recv_wsf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8293) 						*(uint8_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8294) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8295) 		case ISCSI_FLASHNODE_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8296) 			fnode_conn->statsn = *(uint32_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8297) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8298) 		case ISCSI_FLASHNODE_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8299) 			fnode_conn->exp_statsn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8300) 						*(uint32_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8301) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8302) 		case ISCSI_FLASHNODE_CHAP_OUT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8303) 			chap_out_idx = *(uint16_t *)fnode_param->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8304) 			if (!qla4xxx_get_uni_chap_at_index(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8305) 							   chap_tbl.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8306) 							   chap_tbl.secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8307) 							   chap_out_idx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8308) 				fnode_sess->chap_out_idx = chap_out_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8309) 				/* Enable chap auth if chap index is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8310) 				fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8311) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8312) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8313) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8314) 			ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8315) 				   "%s: No such sysfs attribute\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8316) 			rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8317) 			goto exit_set_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8318) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8321) 	rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8323) exit_set_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8324) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8327) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8328)  * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8329)  * @fnode_sess: pointer to session attrs of flash ddb entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8330)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8331)  * This invalidates the flash ddb entry at the given index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8332)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8333) static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8335) 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8336) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8337) 	uint32_t dev_db_start_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8338) 	uint32_t dev_db_end_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8339) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8340) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8341) 	uint16_t *ddb_cookie = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8342) 	size_t ddb_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8343) 	void *pddb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8344) 	int target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8345) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8347) 	if (fnode_sess->is_boot_target) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8348) 		rc = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8349) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8350) 				  "%s: Deletion of boot target entry is not permitted.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8351) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8352) 		goto exit_ddb_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8355) 	if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8356) 		goto sysfs_ddb_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8358) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8359) 		dev_db_start_offset = FLASH_OFFSET_DB_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8360) 		dev_db_end_offset = FLASH_OFFSET_DB_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8361) 		dev_db_start_offset += (fnode_sess->target_id *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8362) 				       sizeof(*fw_ddb_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8363) 		ddb_size = sizeof(*fw_ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8364) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8365) 		dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8366) 				      (ha->hw.flt_region_ddb << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8367) 		/* flt_ddb_size is DDB table size for both ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8368) 		 * so divide it by 2 to calculate the offset for second port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8369) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8370) 		if (ha->port_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8371) 			dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8373) 		dev_db_end_offset = dev_db_start_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8374) 				    (ha->hw.flt_ddb_size / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8376) 		dev_db_start_offset += (fnode_sess->target_id *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8377) 				       sizeof(*fw_ddb_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8378) 		dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8380) 		ddb_size = sizeof(*ddb_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8383) 	DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8384) 			  __func__, dev_db_start_offset, dev_db_end_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8386) 	if (dev_db_start_offset > dev_db_end_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8387) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8388) 		DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8389) 				  __func__, fnode_sess->target_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8390) 		goto exit_ddb_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8393) 	pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8394) 				  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8395) 	if (!pddb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8396) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8397) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8398) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8399) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8400) 		goto exit_ddb_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8403) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8404) 		fw_ddb_entry = pddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8405) 		memset(fw_ddb_entry, 0, ddb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8406) 		ddb_cookie = &fw_ddb_entry->cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8407) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8408) 		ddb_cookie = pddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8411) 	/* invalidate the cookie */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8412) 	*ddb_cookie = 0xFFEE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8413) 	qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8414) 			  ddb_size, FLASH_OPT_RMW_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8416) sysfs_ddb_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8417) 	target_id = fnode_sess->target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8418) 	iscsi_destroy_flashnode_sess(fnode_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8419) 	ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8420) 		   "%s: session and conn entries for flashnode %u of host %lu deleted\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8421) 		   __func__, target_id, ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8422) exit_ddb_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8423) 	if (pddb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8424) 		dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8425) 				  fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8426) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8429) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8430)  * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8431)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8432)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8433)  * Export the firmware DDB for all send targets and normal targets to sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8434)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8435) int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8437) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8438) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8439) 	uint16_t max_ddbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8440) 	uint16_t idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8441) 	int ret = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8443) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8444) 					  sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8445) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8446) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8447) 		DEBUG2(ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8448) 				  "%s: Unable to allocate dma buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8449) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8450) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8453) 	max_ddbs =  is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8454) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8456) 	for (idx = 0; idx < max_ddbs; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8457) 		if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8458) 					     idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8459) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8461) 		ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8462) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8463) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8464) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8465) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8468) 	dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8469) 			  fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8471) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8474) static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8476) 	iscsi_destroy_all_flashnode(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8479) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8480)  * qla4xxx_build_ddb_list - Build ddb list and setup sessions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8481)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8482)  * @is_reset: Is this init path or reset path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8484)  * Create a list of sendtargets (st) from firmware DDBs, issue send targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8485)  * using connection open, then create the list of normal targets (nt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8486)  * from firmware DDBs. Based on the list of nt setup session and connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8487)  * objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8488)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8489) void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8491) 	uint16_t tmo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8492) 	struct list_head list_st, list_nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8493) 	struct qla_ddb_index  *st_ddb_idx, *st_ddb_idx_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8494) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8496) 	if (!test_bit(AF_LINK_UP, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8497) 		set_bit(AF_BUILD_DDB_LIST, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8498) 		ha->is_reset = is_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8499) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8502) 	INIT_LIST_HEAD(&list_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8503) 	INIT_LIST_HEAD(&list_nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8505) 	qla4xxx_build_st_list(ha, &list_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8507) 	/* Before issuing conn open mbox, ensure all IPs states are configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8508) 	 * Note, conn open fails if IPs are not configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8509) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8510) 	qla4xxx_wait_for_ip_configuration(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8512) 	/* Go thru the STs and fire the sendtargets by issuing conn open mbx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8513) 	list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8514) 		qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8517) 	/* Wait to ensure all sendtargets are done for min 12 sec wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8518) 	tmo = ((ha->def_timeout > LOGIN_TOV) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8519) 	       (ha->def_timeout < LOGIN_TOV * 10) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8520) 	       ha->def_timeout : LOGIN_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8522) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8523) 			  "Default time to wait for build ddb %d\n", tmo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8525) 	wtime = jiffies + (HZ * tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8526) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8527) 		if (list_empty(&list_st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8528) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8530) 		qla4xxx_remove_failed_ddb(ha, &list_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8531) 		schedule_timeout_uninterruptible(HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8532) 	} while (time_after(wtime, jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8535) 	qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8537) 	qla4xxx_free_ddb_list(&list_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8538) 	qla4xxx_free_ddb_list(&list_nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8540) 	qla4xxx_free_ddb_index(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8543) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8544)  * qla4xxx_wait_login_resp_boot_tgt -  Wait for iSCSI boot target login
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8545)  * response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8546)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8547)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8548)  * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8549)  * set in DDB and we will wait for login response of boot targets during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8550)  * probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8551)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8552) static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8554) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8555) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8556) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8557) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8558) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8559) 	int max_ddbs, idx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8561) 	max_ddbs =  is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8562) 				     MAX_DEV_DB_ENTRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8564) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8565) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8566) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8567) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8568) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8569) 		goto exit_login_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8572) 	wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8574) 	for (idx = 0; idx < max_ddbs; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8575) 		ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8576) 		if (ddb_entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8577) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8579) 		if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8580) 			DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8581) 					  "%s: DDB index [%d]\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8582) 					  ddb_entry->fw_ddb_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8583) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8584) 				ret = qla4xxx_get_fwddb_entry(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8585) 						ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8586) 						fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8587) 						NULL, NULL, &ddb_state, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8588) 						NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8589) 				if (ret == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8590) 					goto exit_login_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8592) 				if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8593) 				    (ddb_state == DDB_DS_SESSION_FAILED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8594) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8596) 				schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8598) 			} while ((time_after(wtime, jiffies)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8600) 			if (!time_after(wtime, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8601) 				DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8602) 						  "%s: Login response wait timer expired\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8603) 						  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8604) 				 goto exit_login_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8605) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8606) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8609) exit_login_resp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8610) 	if (fw_ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8611) 		dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8612) 				  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8615) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8616)  * qla4xxx_probe_adapter - callback function to probe HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8617)  * @pdev: pointer to pci_dev structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8618)  * @ent: pointer to pci_device entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8619)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8620)  * This routine will probe for Qlogic 4xxx iSCSI host adapters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8621)  * It returns zero if successful. It also initializes all data necessary for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8622)  * the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8623)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8624) static int qla4xxx_probe_adapter(struct pci_dev *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8625) 				 const struct pci_device_id *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8627) 	int ret = -ENODEV, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8628) 	struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8629) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8630) 	uint8_t init_retry_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8631) 	char buf[34];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8632) 	struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8633) 	uint32_t dev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8635) 	if (pci_enable_device(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8636) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8638) 	host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8639) 	if (host == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8640) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8641) 		       "qla4xxx: Couldn't allocate host from scsi layer!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8642) 		goto probe_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8645) 	/* Clear our data area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8646) 	ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8647) 	memset(ha, 0, sizeof(*ha));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8649) 	/* Save the information from PCI BIOS.	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8650) 	ha->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8651) 	ha->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8652) 	ha->host_no = host->host_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8653) 	ha->func_num = PCI_FUNC(ha->pdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8655) 	pci_enable_pcie_error_reporting(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8657) 	/* Setup Runtime configurable options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8658) 	if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8659) 		ha->isp_ops = &qla4_82xx_isp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8660) 		ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8661) 		ha->qdr_sn_window = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8662) 		ha->ddr_mn_window = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8663) 		ha->curr_window = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8664) 		nx_legacy_intr = &legacy_intr[ha->func_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8665) 		ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8666) 		ha->nx_legacy_intr.tgt_status_reg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8667) 			nx_legacy_intr->tgt_status_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8668) 		ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8669) 		ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8670) 	} else if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8671) 		ha->isp_ops = &qla4_83xx_isp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8672) 		ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8673) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8674) 		ha->isp_ops = &qla4xxx_isp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8675) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8677) 	if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8678) 		rwlock_init(&ha->hw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8679) 		ha->pf_bit = ha->func_num << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8680) 		/* Set EEH reset type to fundamental if required by hba */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8681) 		pdev->needs_freset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8684) 	/* Configure PCI I/O space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8685) 	ret = ha->isp_ops->iospace_config(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8686) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8687) 		goto probe_failed_ioconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8689) 	ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8690) 		   pdev->device, pdev->irq, ha->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8692) 	qla4xxx_config_dma_addressing(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8694) 	/* Initialize lists and spinlocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8695) 	INIT_LIST_HEAD(&ha->free_srb_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8697) 	mutex_init(&ha->mbox_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8698) 	mutex_init(&ha->chap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8699) 	init_completion(&ha->mbx_intr_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8700) 	init_completion(&ha->disable_acb_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8701) 	init_completion(&ha->idc_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8702) 	init_completion(&ha->link_up_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8704) 	spin_lock_init(&ha->hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8705) 	spin_lock_init(&ha->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8707) 	/* Initialize work list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8708) 	INIT_LIST_HEAD(&ha->work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8710) 	/* Allocate dma buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8711) 	if (qla4xxx_mem_alloc(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8712) 		ql4_printk(KERN_WARNING, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8713) 		    "[ERROR] Failed to allocate memory for adapter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8715) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8716) 		goto probe_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8719) 	host->cmd_per_lun = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8720) 	host->max_channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8721) 	host->max_lun = MAX_LUNS - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8722) 	host->max_id = MAX_TARGETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8723) 	host->max_cmd_len = IOCB_MAX_CDB_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8724) 	host->can_queue = MAX_SRBS ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8725) 	host->transportt = qla4xxx_scsi_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8727) 	pci_set_drvdata(pdev, ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8729) 	ret = scsi_add_host(host, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8730) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8731) 		goto probe_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8733) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8734) 		qla4_8xxx_get_flash_info(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8736) 	if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8737) 		qla4_83xx_read_reset_template(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8738) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8739) 		 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8740) 		 * If DONRESET_BIT0 is set, drivers should not set dev_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8741) 		 * to NEED_RESET. But if NEED_RESET is set, drivers should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8742) 		 * should honor the reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8743) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8744) 		if (ql4xdontresethba == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8745) 			qla4_83xx_set_idc_dontreset(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8748) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8749) 	 * Initialize the Host adapter request/response queues and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8750) 	 * firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8751) 	 * NOTE: interrupts enabled upon successful completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8752) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8753) 	status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8755) 	/* Dont retry adapter initialization if IRQ allocation failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8756) 	if (is_qla80XX(ha) && (status == QLA_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8757) 		goto skip_retry_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8759) 	while ((!test_bit(AF_ONLINE, &ha->flags)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8760) 	    init_retry_count++ < MAX_INIT_RETRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8762) 		if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8763) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8764) 			dev_state = qla4_8xxx_rd_direct(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8765) 							QLA8XXX_CRB_DEV_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8766) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8767) 			if (dev_state == QLA8XXX_DEV_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8768) 				ql4_printk(KERN_WARNING, ha, "%s: don't retry "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8769) 				    "initialize adapter. H/W is in failed state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8770) 				    __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8771) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8772) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8773) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8774) 		DEBUG2(printk("scsi: %s: retrying adapter initialization "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8775) 			      "(%d)\n", __func__, init_retry_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8777) 		if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8778) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8780) 		status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8781) 		if (is_qla80XX(ha) && (status == QLA_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8782) 			if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8783) 				goto skip_retry_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8787) skip_retry_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8788) 	if (!test_bit(AF_ONLINE, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8789) 		ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8791) 		if ((is_qla8022(ha) && ql4xdontresethba) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8792) 		    ((is_qla8032(ha) || is_qla8042(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8793) 		     qla4_83xx_idc_dontreset(ha))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8794) 			/* Put the device in failed state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8795) 			DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8796) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8797) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8798) 					    QLA8XXX_DEV_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8799) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8800) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8801) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8802) 		goto remove_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8805) 	/* Startup the kernel thread for this host adapter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8806) 	DEBUG2(printk("scsi: %s: Starting kernel thread for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8807) 		      "qla4xxx_dpc\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8808) 	sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8809) 	ha->dpc_thread = create_singlethread_workqueue(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8810) 	if (!ha->dpc_thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8811) 		ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8812) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8813) 		goto remove_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8815) 	INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8817) 	ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8818) 				      ha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8819) 	if (!ha->task_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8820) 		ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8821) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8822) 		goto remove_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8825) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8826) 	 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8827) 	 * (which is called indirectly by qla4xxx_initialize_adapter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8828) 	 * so that irqs will be registered after crbinit but before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8829) 	 * mbx_intr_enable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8830) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8831) 	if (is_qla40XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8832) 		ret = qla4xxx_request_irqs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8833) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8834) 			ql4_printk(KERN_WARNING, ha, "Failed to reserve "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8835) 			    "interrupt %d already in use.\n", pdev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8836) 			goto remove_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8837) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8840) 	pci_save_state(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8841) 	ha->isp_ops->enable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8843) 	/* Start timer thread. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8844) 	qla4xxx_start_timer(ha, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8846) 	set_bit(AF_INIT_DONE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8848) 	qla4_8xxx_alloc_sysfs_attr(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8850) 	printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8851) 	       " QLogic iSCSI HBA Driver version: %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8852) 	       "  QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8853) 	       qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8854) 	       ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8855) 	       ha->fw_info.fw_patch, ha->fw_info.fw_build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8857) 	/* Set the driver version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8858) 	if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8859) 		qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8861) 	if (qla4xxx_setup_boot_info(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8862) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8863) 			   "%s: No iSCSI boot target configured\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8865) 	set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8866) 	/* Perform the build ddb list and login to each */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8867) 	qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8868) 	iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8869) 	qla4xxx_wait_login_resp_boot_tgt(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8871) 	qla4xxx_create_chap_list(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8873) 	qla4xxx_create_ifaces(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8874) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8876) remove_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8877) 	scsi_remove_host(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8879) probe_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8880) 	qla4xxx_free_adapter(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8882) probe_failed_ioconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8883) 	pci_disable_pcie_error_reporting(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8884) 	scsi_host_put(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8886) probe_disable_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8887) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8889) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8892) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8893)  * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8894)  * @ha: pointer to adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8895)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8896)  * Mark the other ISP-4xxx port to indicate that the driver is being removed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8897)  * so that the other port will not re-initialize while in the process of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8898)  * removing the ha due to driver unload or hba hotplug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8899)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8900) static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8902) 	struct scsi_qla_host *other_ha = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8903) 	struct pci_dev *other_pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8904) 	int fn = ISP4XXX_PCI_FN_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8906) 	/*iscsi function numbers for ISP4xxx is 1 and 3*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8907) 	if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8908) 		fn = ISP4XXX_PCI_FN_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8910) 	other_pdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8911) 		pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8912) 		ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8913) 		fn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8915) 	/* Get other_ha if other_pdev is valid and state is enable*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8916) 	if (other_pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8917) 		if (atomic_read(&other_pdev->enable_cnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8918) 			other_ha = pci_get_drvdata(other_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8919) 			if (other_ha) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8920) 				set_bit(AF_HA_REMOVAL, &other_ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8921) 				DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8922) 				    "Prevent %s reinit\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8923) 				    dev_name(&other_ha->pdev->dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8924) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8925) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8926) 		pci_dev_put(other_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8927) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8930) static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8931) 		struct ddb_entry *ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8933) 	struct dev_db_entry *fw_ddb_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8934) 	dma_addr_t fw_ddb_entry_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8935) 	unsigned long wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8936) 	uint32_t ddb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8937) 	int options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8938) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8940) 	options = LOGOUT_OPTION_CLOSE_SESSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8941) 	if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8942) 		ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8943) 		goto clear_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8946) 	fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8947) 					  &fw_ddb_entry_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8948) 	if (!fw_ddb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8949) 		ql4_printk(KERN_ERR, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8950) 			   "%s: Unable to allocate dma buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8951) 		goto clear_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8954) 	wtime = jiffies + (HZ * LOGOUT_TOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8955) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8956) 		status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8957) 						 fw_ddb_entry, fw_ddb_entry_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8958) 						 NULL, NULL, &ddb_state, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8959) 						 NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8960) 		if (status == QLA_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8961) 			goto free_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8963) 		if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8964) 		    (ddb_state == DDB_DS_SESSION_FAILED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8965) 			goto free_ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8967) 		schedule_timeout_uninterruptible(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8968) 	} while ((time_after(wtime, jiffies)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8970) free_ddb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8971) 	dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8972) 			  fw_ddb_entry, fw_ddb_entry_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8973) clear_ddb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8974) 	qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8977) static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8979) 	struct ddb_entry *ddb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8980) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8982) 	for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8984) 		ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8985) 		if ((ddb_entry != NULL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8986) 		    (ddb_entry->ddb_type == FLASH_DDB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8988) 			qla4xxx_destroy_ddb(ha, ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8989) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8990) 			 * we have decremented the reference count of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8991) 			 * when we setup the session to have the driver unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8992) 			 * to be seamless without actually destroying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8993) 			 * session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8994) 			 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8995) 			try_module_get(qla4xxx_iscsi_transport.owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8996) 			iscsi_destroy_endpoint(ddb_entry->conn->ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8997) 			qla4xxx_free_ddb(ha, ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8998) 			iscsi_session_teardown(ddb_entry->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8999) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9002) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9003)  * qla4xxx_remove_adapter - callback function to remove adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9004)  * @pdev: PCI device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9005)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9006) static void qla4xxx_remove_adapter(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9008) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9010) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9011) 	 * If the PCI device is disabled then it means probe_adapter had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9012) 	 * failed and resources already cleaned up on probe_adapter exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9013) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9014) 	if (!pci_is_enabled(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9015) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9017) 	ha = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9019) 	if (is_qla40XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9020) 		qla4xxx_prevent_other_port_reinit(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9022) 	/* destroy iface from sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9023) 	qla4xxx_destroy_ifaces(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9025) 	if ((!ql4xdisablesysfsboot) && ha->boot_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9026) 		iscsi_boot_destroy_kset(ha->boot_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9028) 	qla4xxx_destroy_fw_ddb_session(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9029) 	qla4_8xxx_free_sysfs_attr(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9031) 	qla4xxx_sysfs_ddb_remove(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9032) 	scsi_remove_host(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9034) 	qla4xxx_free_adapter(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9036) 	scsi_host_put(ha->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9038) 	pci_disable_pcie_error_reporting(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9039) 	pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9042) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9043)  * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9044)  * @ha: HA context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9045)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9046) static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9048) 	/* Update our PCI device dma_mask for full 64 bit mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9049) 	if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9050) 		dev_dbg(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9051) 			  "Failed to set 64 bit PCI consistent mask; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9052) 			   "using 32 bit.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9053) 		dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9057) static int qla4xxx_slave_alloc(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9058) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9059) 	struct iscsi_cls_session *cls_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9060) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9061) 	struct ddb_entry *ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9062) 	int queue_depth = QL4_DEF_QDEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9064) 	cls_sess = starget_to_session(sdev->sdev_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9065) 	sess = cls_sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9066) 	ddb = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9068) 	sdev->hostdata = ddb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9070) 	if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9071) 		queue_depth = ql4xmaxqdepth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9073) 	scsi_change_queue_depth(sdev, queue_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9074) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9077) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9078)  * qla4xxx_del_from_active_array - returns an active srb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9079)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9080)  * @index: index into the active_array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9081)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9082)  * This routine removes and returns the srb at the specified index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9083)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9084) struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9085)     uint32_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9087) 	struct srb *srb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9088) 	struct scsi_cmnd *cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9090) 	cmd = scsi_host_find_tag(ha->host, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9091) 	if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9092) 		return srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9094) 	srb = (struct srb *)CMD_SP(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9095) 	if (!srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9096) 		return srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9098) 	/* update counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9099) 	if (srb->flags & SRB_DMA_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9100) 		ha->iocb_cnt -= srb->iocb_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9101) 		if (srb->cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9102) 			srb->cmd->host_scribble =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9103) 				(unsigned char *)(unsigned long) MAX_SRBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9105) 	return srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9109)  * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9110)  * @ha: Pointer to host adapter structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9111)  * @cmd: Scsi Command to wait on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9113)  * This routine waits for the command to be returned by the Firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9114)  * for some max time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9115)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9116) static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9117) 				      struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9119) 	int done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9120) 	struct srb *rp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9121) 	uint32_t max_wait_time = EH_WAIT_CMD_TOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9122) 	int ret = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9124) 	/* Dont wait on command if PCI error is being handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9125) 	 * by PCI AER driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9127) 	if (unlikely(pci_channel_offline(ha->pdev)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9128) 	    (test_bit(AF_EEH_BUSY, &ha->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9129) 		ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9130) 		    ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9131) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9134) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9135) 		/* Checking to see if its returned to OS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9136) 		rp = (struct srb *) CMD_SP(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9137) 		if (rp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9138) 			done++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9139) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9140) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9142) 		msleep(2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9143) 	} while (max_wait_time--);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9145) 	return done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9149)  * qla4xxx_wait_for_hba_online - waits for HBA to come online
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9150)  * @ha: Pointer to host adapter structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9151)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9152) static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9154) 	unsigned long wait_online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9156) 	wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9157) 	while (time_before(jiffies, wait_online)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9159) 		if (adapter_up(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9160) 			return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9162) 		msleep(2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9165) 	return QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9168) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9169)  * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9170)  * @ha: pointer to HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9171)  * @stgt: pointer to SCSI target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9172)  * @sdev: pointer to SCSI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9173)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9174)  * This function waits for all outstanding commands to a lun to complete. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9175)  * returns 0 if all pending commands are returned and 1 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9176)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9177) static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9178) 					struct scsi_target *stgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9179) 					struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9181) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9182) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9183) 	struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9185) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9186) 	 * Waiting for all commands for the designated target or dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9187) 	 * in the active array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9189) 	for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9190) 		cmd = scsi_host_find_tag(ha->host, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9191) 		if (cmd && stgt == scsi_target(cmd->device) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9192) 		    (!sdev || sdev == cmd->device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9193) 			if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9194) 				status++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9195) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9196) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9199) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9202) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9203)  * qla4xxx_eh_abort - callback for abort task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9204)  * @cmd: Pointer to Linux's SCSI command structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9205)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9206)  * This routine is called by the Linux OS to abort the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9207)  * command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9208)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9209) static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9211) 	struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9212) 	unsigned int id = cmd->device->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9213) 	uint64_t lun = cmd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9214) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9215) 	struct srb *srb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9216) 	int ret = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9217) 	int wait = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9218) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9220) 	ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9221) 		   ha->host_no, id, lun, cmd, cmd->cmnd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9223) 	rval = qla4xxx_isp_check_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9224) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9225) 		ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9226) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9229) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9230) 	srb = (struct srb *) CMD_SP(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9231) 	if (!srb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9232) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9233) 		ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9234) 			   ha->host_no, id, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9235) 		return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9237) 	kref_get(&srb->srb_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9238) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9240) 	if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9241) 		DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9242) 		    ha->host_no, id, lun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9243) 		ret = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9244) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9245) 		DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9246) 		    ha->host_no, id, lun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9247) 		wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9250) 	kref_put(&srb->srb_ref, qla4xxx_srb_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9252) 	/* Wait for command to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9253) 	if (wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9254) 		if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9255) 			DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9256) 			    ha->host_no, id, lun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9257) 			ret = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9261) 	ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9262) 	    "scsi%ld:%d:%llu: Abort command - %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9263) 	    ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9265) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9268) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9269)  * qla4xxx_eh_device_reset - callback for target reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9270)  * @cmd: Pointer to Linux's SCSI command structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9271)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9272)  * This routine is called by the Linux OS to reset all luns on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9273)  * specified target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9274)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9275) static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9277) 	struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9278) 	struct ddb_entry *ddb_entry = cmd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9279) 	int ret = FAILED, stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9280) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9282) 	if (!ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9283) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9285) 	ret = iscsi_block_scsi_eh(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9286) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9287) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9288) 	ret = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9290) 	ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9291) 		   "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9292) 		   cmd->device->channel, cmd->device->id, cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9294) 	DEBUG2(printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9295) 		      "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9296) 		      "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9297) 		      cmd, jiffies, cmd->request->timeout / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9298) 		      ha->dpc_flags, cmd->result, cmd->allowed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9300) 	rval = qla4xxx_isp_check_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9301) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9302) 		ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9303) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9306) 	/* FIXME: wait for hba to go online */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9307) 	stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9308) 	if (stat != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9309) 		ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9310) 		goto eh_dev_reset_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9313) 	if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9314) 					 cmd->device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9315) 		ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9316) 			   "DEVICE RESET FAILED - waiting for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9317) 			   "commands.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9318) 		goto eh_dev_reset_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9321) 	/* Send marker. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9322) 	if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9323) 		MM_LUN_RESET) != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9324) 		goto eh_dev_reset_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9326) 	ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9327) 		   "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9328) 		   ha->host_no, cmd->device->channel, cmd->device->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9329) 		   cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9331) 	ret = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9333) eh_dev_reset_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9335) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9338) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9339)  * qla4xxx_eh_target_reset - callback for target reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9340)  * @cmd: Pointer to Linux's SCSI command structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9341)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9342)  * This routine is called by the Linux OS to reset the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9343)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9344) static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9346) 	struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9347) 	struct ddb_entry *ddb_entry = cmd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9348) 	int stat, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9349) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9351) 	if (!ddb_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9352) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9354) 	ret = iscsi_block_scsi_eh(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9355) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9356) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9358) 	starget_printk(KERN_INFO, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9359) 		       "WARM TARGET RESET ISSUED.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9361) 	DEBUG2(printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9362) 		      "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9363) 		      "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9364) 		      ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9365) 		      ha->dpc_flags, cmd->result, cmd->allowed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9367) 	rval = qla4xxx_isp_check_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9368) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9369) 		ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9370) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9373) 	stat = qla4xxx_reset_target(ha, ddb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9374) 	if (stat != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9375) 		starget_printk(KERN_INFO, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9376) 			       "WARM TARGET RESET FAILED.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9377) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9380) 	if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9381) 					 NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9382) 		starget_printk(KERN_INFO, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9383) 			       "WARM TARGET DEVICE RESET FAILED - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9384) 			       "waiting for commands.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9385) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9388) 	/* Send marker. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9389) 	if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9390) 		MM_TGT_WARM_RESET) != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9391) 		starget_printk(KERN_INFO, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9392) 			       "WARM TARGET DEVICE RESET FAILED - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9393) 			       "marker iocb failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9394) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9397) 	starget_printk(KERN_INFO, scsi_target(cmd->device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9398) 		       "WARM TARGET RESET SUCCEEDED.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9399) 	return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9402) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9403)  * qla4xxx_is_eh_active - check if error handler is running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9404)  * @shost: Pointer to SCSI Host struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9405)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9406)  * This routine finds that if reset host is called in EH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9407)  * scenario or from some application like sg_reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9408)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9409) static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9411) 	if (shost->shost_state == SHOST_RECOVERY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9412) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9413) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9416) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9417)  * qla4xxx_eh_host_reset - kernel callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9418)  * @cmd: Pointer to Linux's SCSI command structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9420)  * This routine is invoked by the Linux kernel to perform fatal error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9421)  * recovery on the specified adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9422)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9423) static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9425) 	int return_status = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9426) 	struct scsi_qla_host *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9427) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9429) 	ha = to_qla_host(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9431) 	rval = qla4xxx_isp_check_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9432) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9433) 		ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9434) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9437) 	if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9438) 		qla4_83xx_set_idc_dontreset(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9440) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9441) 	 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9442) 	 * protocol drivers, we should not set device_state to NEED_RESET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9443) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9444) 	if (ql4xdontresethba ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9445) 	    ((is_qla8032(ha) || is_qla8042(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9446) 	     qla4_83xx_idc_dontreset(ha))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9447) 		DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9448) 		     ha->host_no, __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9450) 		/* Clear outstanding srb in queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9451) 		if (qla4xxx_is_eh_active(cmd->device->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9452) 			qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9454) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9457) 	ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9458) 		   "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9459) 		   cmd->device->channel, cmd->device->id, cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9461) 	if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9462) 		DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host.  Adapter "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9463) 			      "DEAD.\n", ha->host_no, cmd->device->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9464) 			      __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9466) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9469) 	if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9470) 		if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9471) 			set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9472) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9473) 			set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9476) 	if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9477) 		return_status = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9479) 	ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9480) 		   return_status == FAILED ? "FAILED" : "SUCCEEDED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9482) 	return return_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9485) static int qla4xxx_context_reset(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9487) 	uint32_t mbox_cmd[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9488) 	uint32_t mbox_sts[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9489) 	struct addr_ctrl_blk_def *acb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9490) 	uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9491) 	int rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9492) 	dma_addr_t acb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9494) 	acb = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9495) 				 sizeof(struct addr_ctrl_blk_def),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9496) 				 &acb_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9497) 	if (!acb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9498) 		ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9499) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9500) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9501) 		goto exit_port_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9504) 	memset(acb, 0, acb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9506) 	rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9507) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9508) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9509) 		goto exit_free_acb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9512) 	rval = qla4xxx_disable_acb(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9513) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9514) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9515) 		goto exit_free_acb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9518) 	wait_for_completion_timeout(&ha->disable_acb_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9519) 				    DISABLE_ACB_TOV * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9521) 	rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9522) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9523) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9524) 		goto exit_free_acb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9527) exit_free_acb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9528) 	dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9529) 			  acb, acb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9530) exit_port_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9531) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9532) 			  rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9533) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9536) static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9538) 	struct scsi_qla_host *ha = to_qla_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9539) 	int rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9540) 	uint32_t idc_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9542) 	if (ql4xdontresethba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9543) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9544) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9545) 		rval = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9546) 		goto exit_host_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9549) 	if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9550) 		goto recover_adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9552) 	switch (reset_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9553) 	case SCSI_ADAPTER_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9554) 		set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9556) 	case SCSI_FIRMWARE_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9557) 		if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9558) 			if (is_qla80XX(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9559) 				/* set firmware context reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9560) 				set_bit(DPC_RESET_HA_FW_CONTEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9561) 					&ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9562) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9563) 				rval = qla4xxx_context_reset(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9564) 				goto exit_host_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9565) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9566) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9567) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9570) recover_adapter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9571) 	/* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9572) 	 * reset is issued by application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9573) 	if ((is_qla8032(ha) || is_qla8042(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9574) 	    test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9575) 		idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9576) 		qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9577) 				 (idc_ctrl | GRACEFUL_RESET_BIT1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9580) 	rval = qla4xxx_recover_adapter(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9581) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9582) 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9583) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9584) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9585) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9587) exit_host_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9588) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9591) /* PCI AER driver recovers from all correctable errors w/o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9592)  * driver intervention. For uncorrectable errors PCI AER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9593)  * driver calls the following device driver's callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9594)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9595)  * - Fatal Errors - link_reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9596)  * - Non-Fatal Errors - driver's error_detected() which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9597)  * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9598)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9599)  * PCI AER driver calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9600)  * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9601)  *               returns RECOVERED or NEED_RESET if fw_hung
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9602)  * NEED_RESET - driver's slot_reset()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9603)  * DISCONNECT - device is dead & cannot recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9604)  * RECOVERED - driver's resume()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9605)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9606) static pci_ers_result_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9607) qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9609) 	struct scsi_qla_host *ha = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9611) 	ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9612) 	    ha->host_no, __func__, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9614) 	if (!is_aer_supported(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9615) 		return PCI_ERS_RESULT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9617) 	switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9618) 	case pci_channel_io_normal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9619) 		clear_bit(AF_EEH_BUSY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9620) 		return PCI_ERS_RESULT_CAN_RECOVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9621) 	case pci_channel_io_frozen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9622) 		set_bit(AF_EEH_BUSY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9623) 		qla4xxx_mailbox_premature_completion(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9624) 		qla4xxx_free_irqs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9625) 		pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9626) 		/* Return back all IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9627) 		qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9628) 		return PCI_ERS_RESULT_NEED_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9629) 	case pci_channel_io_perm_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9630) 		set_bit(AF_EEH_BUSY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9631) 		set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9632) 		qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9633) 		return PCI_ERS_RESULT_DISCONNECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9635) 	return PCI_ERS_RESULT_NEED_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9638) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9639)  * qla4xxx_pci_mmio_enabled() gets called if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9640)  * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9641)  * and read/write to the device still works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9642)  * @pdev: PCI device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9643)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9644) static pci_ers_result_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9645) qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9647) 	struct scsi_qla_host *ha = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9649) 	if (!is_aer_supported(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9650) 		return PCI_ERS_RESULT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9652) 	return PCI_ERS_RESULT_RECOVERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9655) static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9657) 	uint32_t rval = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9658) 	int fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9659) 	struct pci_dev *other_pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9661) 	ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9663) 	set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9665) 	if (test_bit(AF_ONLINE, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9666) 		clear_bit(AF_ONLINE, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9667) 		clear_bit(AF_LINK_UP, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9668) 		iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9669) 		qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9670) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9672) 	fn = PCI_FUNC(ha->pdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9673) 	if (is_qla8022(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9674) 		while (fn > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9675) 			fn--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9676) 			ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9677) 				   ha->host_no, __func__, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9678) 			/* Get the pci device given the domain, bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9679) 			 * slot/function number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9680) 			other_pdev = pci_get_domain_bus_and_slot(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9681) 					   pci_domain_nr(ha->pdev->bus),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9682) 					   ha->pdev->bus->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9683) 					   PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9684) 					   fn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9686) 			if (!other_pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9687) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9689) 			if (atomic_read(&other_pdev->enable_cnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9690) 				ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9691) 					   ha->host_no, __func__, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9692) 				pci_dev_put(other_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9693) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9694) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9695) 			pci_dev_put(other_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9696) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9697) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9698) 		/* this case is meant for ISP83xx/ISP84xx only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9699) 		if (qla4_83xx_can_perform_reset(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9700) 			/* reset fn as iSCSI is going to perform the reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9701) 			fn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9703) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9705) 	/* The first function on the card, the reset owner will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9706) 	 * start & initialize the firmware. The other functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9707) 	 * on the card will reset the firmware context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9708) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9709) 	if (!fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9710) 		ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9711) 		    "0x%x is the owner\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9712) 		    ha->pdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9714) 		ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9715) 		qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9716) 				    QLA8XXX_DEV_COLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9717) 		ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9719) 		rval = qla4_8xxx_update_idc_reg(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9720) 		if (rval == QLA_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9721) 			ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9722) 				   ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9723) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9724) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9725) 					    QLA8XXX_DEV_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9726) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9727) 			goto exit_error_recovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9728) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9730) 		clear_bit(AF_FW_RECOVERY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9731) 		rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9733) 		if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9734) 			ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9735) 			    "FAILED\n", ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9736) 			qla4xxx_free_irqs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9737) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9738) 			qla4_8xxx_clear_drv_active(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9739) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9740) 					    QLA8XXX_DEV_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9741) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9742) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9743) 			ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9744) 			    "READY\n", ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9745) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9746) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9747) 					    QLA8XXX_DEV_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9748) 			/* Clear driver state register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9749) 			qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9750) 			qla4_8xxx_set_drv_active(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9751) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9752) 			ha->isp_ops->enable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9754) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9755) 		ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9756) 		    "the reset owner\n", ha->host_no, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9757) 		    ha->pdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9758) 		if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9759) 		     QLA8XXX_DEV_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9760) 			clear_bit(AF_FW_RECOVERY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9761) 			rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9762) 			if (rval == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9763) 				ha->isp_ops->enable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9764) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9765) 				qla4xxx_free_irqs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9767) 			ha->isp_ops->idc_lock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9768) 			qla4_8xxx_set_drv_active(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9769) 			ha->isp_ops->idc_unlock(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9770) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9772) exit_error_recovery:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9773) 	clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9774) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9777) static pci_ers_result_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9778) qla4xxx_pci_slot_reset(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9780) 	pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9781) 	struct scsi_qla_host *ha = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9782) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9784) 	ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9785) 	    ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9787) 	if (!is_aer_supported(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9788) 		return PCI_ERS_RESULT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9790) 	/* Restore the saved state of PCIe device -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9791) 	 * BAR registers, PCI Config space, PCIX, MSI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9792) 	 * IOV states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9793) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9794) 	pci_restore_state(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9796) 	/* pci_restore_state() clears the saved_state flag of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9797) 	 * save restored state which resets saved_state flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9798) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9799) 	pci_save_state(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9801) 	/* Initialize device or resume if in suspended state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9802) 	rc = pci_enable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9803) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9804) 		ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9805) 		    "device after reset\n", ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9806) 		goto exit_slot_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9809) 	ha->isp_ops->disable_intrs(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9811) 	if (is_qla80XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9812) 		if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9813) 			ret = PCI_ERS_RESULT_RECOVERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9814) 			goto exit_slot_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9815) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9816) 			goto exit_slot_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9817) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9819) exit_slot_reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9820) 	ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9821) 	    "device after reset\n", ha->host_no, __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9822) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9825) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9826) qla4xxx_pci_resume(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9828) 	struct scsi_qla_host *ha = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9829) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9831) 	ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9832) 	    ha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9834) 	ret = qla4xxx_wait_for_hba_online(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9835) 	if (ret != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9836) 		ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9837) 		    "resume I/O from slot/link_reset\n", ha->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9838) 		     __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9839) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9841) 	clear_bit(AF_EEH_BUSY, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9844) static const struct pci_error_handlers qla4xxx_err_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9845) 	.error_detected = qla4xxx_pci_error_detected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9846) 	.mmio_enabled = qla4xxx_pci_mmio_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9847) 	.slot_reset = qla4xxx_pci_slot_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9848) 	.resume = qla4xxx_pci_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9849) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9851) static struct pci_device_id qla4xxx_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9852) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9853) 		.vendor		= PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9854) 		.device		= PCI_DEVICE_ID_QLOGIC_ISP4010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9855) 		.subvendor	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9856) 		.subdevice	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9857) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9858) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9859) 		.vendor		= PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9860) 		.device		= PCI_DEVICE_ID_QLOGIC_ISP4022,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9861) 		.subvendor	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9862) 		.subdevice	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9863) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9864) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9865) 		.vendor		= PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9866) 		.device		= PCI_DEVICE_ID_QLOGIC_ISP4032,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9867) 		.subvendor	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9868) 		.subdevice	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9869) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9870) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9871) 		.vendor         = PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9872) 		.device         = PCI_DEVICE_ID_QLOGIC_ISP8022,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9873) 		.subvendor      = PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9874) 		.subdevice      = PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9875) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9876) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9877) 		.vendor		= PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9878) 		.device		= PCI_DEVICE_ID_QLOGIC_ISP8324,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9879) 		.subvendor	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9880) 		.subdevice	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9881) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9882) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9883) 		.vendor		= PCI_VENDOR_ID_QLOGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9884) 		.device		= PCI_DEVICE_ID_QLOGIC_ISP8042,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9885) 		.subvendor	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9886) 		.subdevice	= PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9887) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9888) 	{0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9889) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9890) MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9892) static struct pci_driver qla4xxx_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9893) 	.name		= DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9894) 	.id_table	= qla4xxx_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9895) 	.probe		= qla4xxx_probe_adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9896) 	.remove		= qla4xxx_remove_adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9897) 	.err_handler = &qla4xxx_err_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9898) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9900) static int __init qla4xxx_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9902) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9904) 	if (ql4xqfulltracking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9905) 		qla4xxx_driver_template.track_queue_depth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9907) 	/* Allocate cache for SRBs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9908) 	srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9909) 				       SLAB_HWCACHE_ALIGN, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9910) 	if (srb_cachep == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9911) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9912) 		       "%s: Unable to allocate SRB cache..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9913) 		       "Failing load!\n", DRIVER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9914) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9915) 		goto no_srp_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9918) 	/* Derive version string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9919) 	strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9920) 	if (ql4xextended_error_logging)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9921) 		strcat(qla4xxx_version_str, "-debug");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9923) 	qla4xxx_scsi_transport =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9924) 		iscsi_register_transport(&qla4xxx_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9925) 	if (!qla4xxx_scsi_transport){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9926) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9927) 		goto release_srb_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9930) 	ret = pci_register_driver(&qla4xxx_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9931) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9932) 		goto unregister_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9934) 	printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9935) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9937) unregister_transport:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9938) 	iscsi_unregister_transport(&qla4xxx_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9939) release_srb_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9940) 	kmem_cache_destroy(srb_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9941) no_srp_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9942) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9945) static void __exit qla4xxx_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9947) 	pci_unregister_driver(&qla4xxx_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9948) 	iscsi_unregister_transport(&qla4xxx_iscsi_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9949) 	kmem_cache_destroy(srb_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9952) module_init(qla4xxx_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9953) module_exit(qla4xxx_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9955) MODULE_AUTHOR("QLogic Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9956) MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9957) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9958) MODULE_VERSION(QLA4XXX_DRIVER_VERSION);