^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright 2014 Cisco Systems, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This program is free software; you may redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifndef _SNIC_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define _SNIC_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "snic_disc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "snic_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "snic_res.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "snic_trc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "snic_stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "vnic_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "vnic_wq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "vnic_cq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "vnic_intr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "vnic_stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "vnic_snic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define SNIC_DRV_NAME "snic"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define SNIC_DRV_DESCRIPTION "Cisco SCSI NIC Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define SNIC_DRV_VERSION "0.0.1.18"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define PFX SNIC_DRV_NAME ":"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define DFX SNIC_DRV_NAME "%d: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define DESC_CLEAN_LOW_WATERMARK 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define SNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16 /* UCSM default throttle count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define SNIC_MAX_IO_REQ 50 /* scsi_cmnd tag map entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define SNIC_MIN_IO_REQ 8 /* Min IO throttle count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define SNIC_IO_LOCKS 64 /* IO locks: power of 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define SNIC_DFLT_QUEUE_DEPTH 32 /* Default Queue Depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define SNIC_MAX_QUEUE_DEPTH 64 /* Max Queue Depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define SNIC_DFLT_CMD_TIMEOUT 90 /* Extended tmo for FW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Tag bits used for special requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define SNIC_TAG_ABORT BIT(30) /* Tag indicating abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define SNIC_TAG_DEV_RST BIT(29) /* Tag for device reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define SNIC_TAG_IOCTL_DEV_RST BIT(28) /* Tag for User Device Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define SNIC_TAG_MASK (BIT(24) - 1) /* Mask for lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define SNIC_NO_TAG -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Command flags to identify the type of command and for other future use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define SNIC_NO_FLAGS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define SNIC_IO_INITIALIZED BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define SNIC_IO_ISSUED BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define SNIC_IO_DONE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define SNIC_IO_REQ_NULL BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define SNIC_IO_ABTS_PENDING BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define SNIC_IO_ABORTED BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define SNIC_IO_ABTS_ISSUED BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define SNIC_IO_TERM_ISSUED BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define SNIC_IO_ABTS_TIMEDOUT BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define SNIC_IO_ABTS_TERM_DONE BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define SNIC_IO_ABTS_TERM_REQ_NULL BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SNIC_IO_ABTS_TERM_TIMEDOUT BIT(11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define SNIC_IO_INTERNAL_TERM_PENDING BIT(12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define SNIC_IO_INTERNAL_TERM_ISSUED BIT(13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define SNIC_DEVICE_RESET BIT(14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define SNIC_DEV_RST_ISSUED BIT(15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define SNIC_DEV_RST_TIMEDOUT BIT(16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define SNIC_DEV_RST_ABTS_ISSUED BIT(17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define SNIC_DEV_RST_TERM_ISSUED BIT(18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define SNIC_DEV_RST_DONE BIT(19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define SNIC_DEV_RST_REQ_NULL BIT(20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define SNIC_DEV_RST_ABTS_DONE BIT(21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define SNIC_DEV_RST_TERM_DONE BIT(22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define SNIC_DEV_RST_ABTS_PENDING BIT(23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define SNIC_DEV_RST_PENDING BIT(24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define SNIC_DEV_RST_NOTSUP BIT(25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define SNIC_SCSI_CLEANUP BIT(26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define SNIC_HOST_RESET_ISSUED BIT(27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define SNIC_HOST_RESET_CMD_TERM \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) (SNIC_DEV_RST_NOTSUP | SNIC_SCSI_CLEANUP | SNIC_HOST_RESET_ISSUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define SNIC_ABTS_TIMEOUT 30000 /* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SNIC_LUN_RESET_TIMEOUT 30000 /* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SNIC_HOST_RESET_TIMEOUT 30000 /* msec */
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * These are protected by the hashed req_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define CMD_SP(Cmnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->rqi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define CMD_STATE(Cmnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define CMD_ABTS_STATUS(Cmnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->abts_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define CMD_LR_STATUS(Cmnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->lr_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define CMD_FLAGS(Cmnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) (((struct snic_internal_io_state *)scsi_cmd_priv(Cmnd))->flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define SNIC_INVALID_CODE 0x100 /* Hdr Status val unused by firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define SNIC_MAX_TARGET 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define SNIC_FLAGS_NONE (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* snic module params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) extern unsigned int snic_max_qdepth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* snic debugging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) extern unsigned int snic_log_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define SNIC_MAIN_LOGGING 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define SNIC_SCSI_LOGGING 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define SNIC_ISR_LOGGING 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define SNIC_DESC_LOGGING 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define SNIC_CHECK_LOGGING(LEVEL, CMD) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (unlikely(snic_log_level & LEVEL)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) CMD; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) } while (0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define SNIC_MAIN_DBG(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) SNIC_CHECK_LOGGING(SNIC_MAIN_LOGGING, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) shost_printk(KERN_INFO, host, fmt, ## args);)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define SNIC_SCSI_DBG(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) shost_printk(KERN_INFO, host, fmt, ##args);)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define SNIC_DISC_DBG(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) SNIC_CHECK_LOGGING(SNIC_SCSI_LOGGING, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) shost_printk(KERN_INFO, host, fmt, ##args);)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define SNIC_ISR_DBG(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SNIC_CHECK_LOGGING(SNIC_ISR_LOGGING, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) shost_printk(KERN_INFO, host, fmt, ##args);)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define SNIC_HOST_ERR(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) shost_printk(KERN_ERR, host, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define SNIC_HOST_INFO(host, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) shost_printk(KERN_INFO, host, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define SNIC_INFO(fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pr_info(PFX fmt, ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define SNIC_DBG(fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pr_info(PFX fmt, ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define SNIC_ERR(fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pr_err(PFX fmt, ## args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define SNIC_BUG_ON(EXPR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (EXPR) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) SNIC_ERR("SNIC BUG(%s)\n", #EXPR); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) BUG_ON(EXPR); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define SNIC_BUG_ON(EXPR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (EXPR) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) SNIC_ERR("SNIC BUG(%s) at %s : %d\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #EXPR, __func__, __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) WARN_ON_ONCE(EXPR); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Soft assert */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define SNIC_ASSERT_NOT_IMPL(EXPR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (EXPR) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) SNIC_INFO("Functionality not impl'ed at %s:%d\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) __func__, __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) WARN_ON_ONCE(EXPR); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern const char *snic_state_str[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) enum snic_intx_intr_index {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) SNIC_INTX_WQ_RQ_COPYWQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) SNIC_INTX_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) SNIC_INTX_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) SNIC_INTX_INTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) enum snic_msix_intr_index {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) SNIC_MSIX_WQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) SNIC_MSIX_IO_CMPL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) SNIC_MSIX_ERR_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) SNIC_MSIX_INTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define SNIC_INTRHDLR_NAMSZ (2 * IFNAMSIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct snic_msix_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int requested;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) char devname[SNIC_INTRHDLR_NAMSZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) irqreturn_t (*isr)(int, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) void *devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) enum snic_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) SNIC_INIT = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) SNIC_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) SNIC_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) SNIC_OFFLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) SNIC_FWRESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define SNIC_WQ_MAX 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define SNIC_CQ_IO_CMPL_MAX 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define SNIC_CQ_MAX (SNIC_WQ_MAX + SNIC_CQ_IO_CMPL_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* firmware version information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct snic_fw_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) u32 fw_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u32 hid; /* u16 hid | u16 vnic id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) u32 max_concur_ios; /* max concurrent ios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u32 max_sgs_per_cmd; /* max sgls per IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u32 max_io_sz; /* max io size supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) u32 hba_cap; /* hba capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) u32 max_tgts; /* max tgts supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) u16 io_tmo; /* FW Extended timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct completion *wait; /* protected by snic lock*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * snic_work item : defined to process asynchronous events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct snic_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u16 ev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u64 *ev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * snic structure to represent SCSI vNIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct snic {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* snic specific members */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) atomic_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) spinlock_t snic_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct completion *remove_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) bool in_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) bool stop_link_events; /* stop processing link events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* discovery related */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct snic_disc disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Scsi Host info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* vnic related structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct vnic_dev_bar bar0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct vnic_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) unsigned long stats_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) unsigned long stats_reset_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct vnic_dev *vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* hw resource info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) unsigned int wq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) unsigned int cq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) unsigned int intr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) unsigned int err_intr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int link_status; /* retrieved from svnic_dev_link_status() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) u32 link_down_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* pci related */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* io related info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) mempool_t *req_pool[SNIC_REQ_MAX_CACHES]; /* (??) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ____cacheline_aligned spinlock_t io_req_lock[SNIC_IO_LOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Maintain snic specific commands, cmds with no tag in spl_cmd_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ____cacheline_aligned spinlock_t spl_cmd_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct list_head spl_cmd_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) unsigned int max_tag_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) atomic_t ios_inflight; /* io in flight counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct vnic_snic_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct work_struct link_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* firmware information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct snic_fw_info fwinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /* Work for processing Target related work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct work_struct tgt_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /* Work for processing Discovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct work_struct disc_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* stats related */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) unsigned int reset_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) atomic64_t io_cmpl_skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct snic_stats s_stats; /* Per SNIC driver stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* platform specific */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct dentry *stats_host; /* Per snic debugfs root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct dentry *stats_file; /* Per snic debugfs file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct dentry *reset_stats_file;/* Per snic reset stats file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* completion queue cache line section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ____cacheline_aligned struct vnic_cq cq[SNIC_CQ_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* work queue cache line section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ____cacheline_aligned struct vnic_wq wq[SNIC_WQ_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) spinlock_t wq_lock[SNIC_WQ_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* interrupt resource cache line section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ____cacheline_aligned struct vnic_intr intr[SNIC_MSIX_INTR_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }; /* end of snic structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * SNIC Driver's Global Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct snic_global {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct list_head snic_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) spinlock_t snic_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct kmem_cache *req_cache[SNIC_REQ_MAX_CACHES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct workqueue_struct *event_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* debugfs related global data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct dentry *trc_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct dentry *stats_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct snic_trc trc ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) extern struct snic_global *snic_glob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int snic_glob_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) void snic_glob_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) extern struct workqueue_struct *snic_event_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) extern struct device_attribute *snic_attrs[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int snic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int snic_abort_cmd(struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int snic_device_reset(struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int snic_host_reset(struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int snic_reset(struct Scsi_Host *, struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) void snic_shutdown_scsi_cleanup(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int snic_request_intr(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void snic_free_intr(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int snic_set_intr_mode(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) void snic_clear_intr_mode(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int snic_fwcq_cmpl_handler(struct snic *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) int snic_wq_cmpl_handler(struct snic *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) void snic_free_wq_buf(struct vnic_wq *, struct vnic_wq_buf *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) void snic_log_q_error(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) void snic_handle_link_event(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) void snic_handle_link(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int snic_queue_exch_ver_req(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) void snic_io_exch_ver_cmpl_handler(struct snic *, struct snic_fw_req *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int snic_queue_wq_desc(struct snic *, void *os_buf, u16 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) void snic_handle_untagged_req(struct snic *, struct snic_req_info *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) void snic_release_untagged_req(struct snic *, struct snic_req_info *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) void snic_free_all_untagged_reqs(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int snic_get_conf(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) void snic_set_state(struct snic *, enum snic_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int snic_get_state(struct snic *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) const char *snic_state_to_str(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) void snic_hex_dump(char *, char *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void snic_print_desc(const char *fn, char *os_buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) const char *show_opcode_name(int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) #endif /* _SNIC_H */