Print this page
    
NEX-3177 enums and string arrays required to be in sync.
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
re #8564, rb4224 "mutex_enter: bad mutex" panic when under heavy load
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/io/comstar/port/pppt/pppt.h
          +++ new/usr/src/uts/common/io/comstar/port/pppt/pppt.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  
    | 
      ↓ open down ↓ | 
    10 lines elided | 
    
      ↑ open up ↑ | 
  
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
       21 +
  21   22  /*
  22   23   * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2013, Nexenta Systems, Inc. All rights reserved.
       24 + * Copyright 2013, 2015 Nexenta Systems, Inc. All rights reserved.
  24   25   */
  25   26  #ifndef _PPPT_H
  26   27  #define _PPPT_H
  27   28  
  28   29  #include <sys/pppt_ic_if.h>
  29   30  
  30   31  #ifdef  __cplusplus
  31   32  extern "C" {
  32   33  #endif
  33   34  
  34   35  #define PPPT_GLOBAL_LOCK() mutex_enter(&pppt_global.global_lock)
  35   36  #define PPPT_GLOBAL_UNLOCK() mutex_exit(&pppt_global.global_lock)
  36   37  
  37   38  extern int pppt_logging;
  38   39  
  39   40  #define PPPT_LOG if (pppt_logging) cmn_err
  40   41  
  41   42  #define TGT_DEREG_RETRY_SECONDS 1
  
    | 
      ↓ open down ↓ | 
    8 lines elided | 
    
      ↑ open up ↑ | 
  
  42   43  
  43   44  typedef enum {
  44   45          PPPT_STATUS_SUCCESS = 0,
  45   46          PPPT_STATUS_FAIL,
  46   47          PPPT_STATUS_ABORTED,
  47   48          PPPT_STATUS_DONE
  48   49  } pppt_status_t;
  49   50  
  50   51  #define PPPT_MODNAME "pppt"
  51   52  
       53 +#define TGT_STATE_LIST() \
       54 +        item(TS_UNDEFINED) \
       55 +        item(TS_CREATED) \
       56 +        item(TS_ONLINING) \
       57 +        item(TS_ONLINE) \
       58 +        item(TS_STMF_ONLINE) \
       59 +        item(TS_DELETING_NEED_OFFLINE) \
       60 +        item(TS_OFFLINING) \
       61 +        item(TS_OFFLINE) \
       62 +        item(TS_STMF_OFFLINE) \
       63 +        item(TS_DELETING_STMF_DEREG) \
       64 +        item(TS_DELETING_STMF_DEREG_FAIL) \
       65 +        item(TS_DELETING) \
       66 +        item(TS_MAX_STATE)
       67 +
  52   68  /* Target states and events, update pppt_ts_name table whenever modified */
  53   69  typedef enum {
  54      -        TS_UNDEFINED = 0,
  55      -        TS_CREATED,
  56      -        TS_ONLINING,
  57      -        TS_ONLINE,
  58      -        TS_STMF_ONLINE,
  59      -        TS_DELETING_NEED_OFFLINE,
  60      -        TS_OFFLINING,
  61      -        TS_OFFLINE,
  62      -        TS_STMF_OFFLINE,
  63      -        TS_DELETING_STMF_DEREG,
  64      -        TS_DELETING_STMF_DEREG_FAIL,
  65      -        TS_DELETING,
  66      -        TS_MAX_STATE
       70 +#define item(a) a,
       71 +        TGT_STATE_LIST()
       72 +#undef  item
  67   73  } pppt_tgt_state_t;
  68   74  
  69   75  #ifdef PPPT_TGT_SM_STRINGS
  70      -static const char *pppt_ts_name[TS_MAX_STATE+1] = {
  71      -        "TS_UNDEFINED",
  72      -        "TS_CREATED",
  73      -        "TS_ONLINING",
  74      -        "TS_ONLINE",
  75      -        "TS_STMF_ONLINE",
  76      -        "TS_DELETING_NEED_OFFLINE",
  77      -        "TS_OFFLINING",
  78      -        "TS_OFFLINE",
  79      -        "TS_STMF_OFFLINE",
  80      -        "TS_DELETING_STMF_DEREG",
  81      -        "TS_DELETING_STMF_DEREG_FAIL",
  82      -        "TS_DELETING",
  83      -        "TS_MAX_STATE"
       76 +static const char *pppt_ts_name[TS_MAX_STATE + 1] = {
       77 +#define item(a) #a,
       78 +        TGT_STATE_LIST()
       79 +#undef  item
  84   80  };
  85   81  #endif
  86   82  
       83 +#define TGT_EVENT_LIST() \
       84 +        item(TE_UNDEFINED) \
       85 +        item(TE_STMF_ONLINE_REQ) \
       86 +        item(TE_ONLINE_SUCCESS) \
       87 +        item(TE_ONLINE_FAIL) \
       88 +        item(TE_STMF_ONLINE_COMPLETE_ACK) \
       89 +        item(TE_STMF_OFFLINE_REQ) \
       90 +        item(TE_OFFLINE_COMPLETE) \
       91 +        item(TE_STMF_OFFLINE_COMPLETE_ACK) \
       92 +        item(TE_DELETE) \
       93 +        item(TE_STMF_DEREG_SUCCESS) \
       94 +        item(TE_STMF_DEREG_FAIL) \
       95 +        item(TE_STMF_DEREG_RETRY) \
       96 +        item(TE_WAIT_REF_COMPLETE) /* XXX */ \
       97 +        item(TE_MAX_EVENT)
       98 +
  87   99  typedef enum {
  88      -        TE_UNDEFINED = 0,
  89      -        TE_STMF_ONLINE_REQ,
  90      -        TE_ONLINE_SUCCESS,
  91      -        TE_ONLINE_FAIL,
  92      -        TE_STMF_ONLINE_COMPLETE_ACK,
  93      -        TE_STMF_OFFLINE_REQ,
  94      -        TE_OFFLINE_COMPLETE,
  95      -        TE_STMF_OFFLINE_COMPLETE_ACK,
  96      -        TE_DELETE,
  97      -        TE_STMF_DEREG_SUCCESS,
  98      -        TE_STMF_DEREG_FAIL,
  99      -        TE_STMF_DEREG_RETRY,
 100      -        TE_WAIT_REF_COMPLETE, /* XXX */
 101      -        TE_MAX_EVENT
      100 +#define item(a) a,
      101 +        TGT_EVENT_LIST()
      102 +#undef  item
 102  103  } pppt_tgt_event_t;
 103  104  
 104  105  #ifdef PPPT_TGT_SM_STRINGS
 105      -static const char *pppt_te_name[TE_MAX_EVENT+1] = {
 106      -        "TE_UNDEFINED",
 107      -        "TE_STMF_ONLINE_REQ",
 108      -        "TE_ONLINE_SUCCESS",
 109      -        "TE_ONLINE_FAIL",
 110      -        "TE_STMF_ONLINE_COMPLETE_ACK",
 111      -        "TE_STMF_OFFLINE_REQ",
 112      -        "TE_OFFLINE_COMPLETE",
 113      -        "TE_STMF_OFFLINE_COMPLETE_ACK",
 114      -        "TE_DELETE",
 115      -        "TE_STMF_DEREG_SUCCESS",
 116      -        "TE_STMF_DEREG_FAIL",
 117      -        "TE_STMF_DEREG_RETRY",
 118      -        "TE_WAIT_REF_COMPLETE",
 119      -        "TE_MAX_EVENT"
      106 +static const char *pppt_te_name[TE_MAX_EVENT + 1] = {
      107 +#define item(a) #a,
      108 +        TGT_EVENT_LIST()
      109 +#undef  item
 120  110  };
 121  111  #endif
 122  112  
 123  113  typedef struct pppt_tgt_s {
 124  114          kmutex_t                target_mutex;
 125  115          kcondvar_t              target_cv;
 126  116          avl_node_t              target_global_ln;
 127  117          scsi_devid_desc_t       *target_devid;
 128  118          stmf_local_port_t       *target_stmf_lport;
 129  119          avl_tree_t              target_sess_list;
 130  120  
 131  121          /* Target state */
 132  122          boolean_t               target_sm_busy;
 133  123          boolean_t               target_deleting;
 134  124          pppt_tgt_state_t        target_state;
 135  125          pppt_tgt_state_t        target_last_state;
 136  126          int                     target_refcount;
 137  127          list_t                  target_events;
 138  128  } pppt_tgt_t;
 139  129  
 140  130  typedef struct {
 141  131          struct pppt_tgt_s       *ps_target;
 142  132          uint64_t                ps_session_id;
 143  133          int                     ps_refcnt;
 144  134          kmutex_t                ps_mutex;
 145  135          kcondvar_t              ps_cv;
 146  136          boolean_t               ps_closed;
 147  137          avl_node_t              ps_global_ln;
 148  138          avl_node_t              ps_target_ln;
 149  139          avl_tree_t              ps_task_list;
 150  140          stmf_scsi_session_t     *ps_stmf_sess;
 151  141  } pppt_sess_t;
 152  142  
 153  143  typedef struct {
 154  144          stmf_data_buf_t         *pbuf_stmf_buf;
 155  145          boolean_t               pbuf_is_immed;
 156  146          stmf_ic_msg_t           *pbuf_immed_msg;
 157  147  } pppt_buf_t;
 158  148  
 159  149  typedef enum {
 160  150          PTS_INIT = 0,
 161  151          PTS_ACTIVE,
 162  152          PTS_DONE,
 163  153          PTS_SENT_STATUS,
 164  154          PTS_ABORTED
 165  155  } pppt_task_state_t;
 166  156  
 167  157  typedef struct {
 168  158          pppt_sess_t             *pt_sess;
 169  159          avl_node_t              pt_sess_ln;
 170  160          int                     pt_refcnt;
 171  161          kmutex_t                pt_mutex;
 172  162          stmf_ic_msgid_t         pt_task_id;
 173  163          uint8_t                 pt_lun_id[16];
 174  164          pppt_task_state_t       pt_state;
 175  165          scsi_task_t             *pt_stmf_task;
 176  166          pppt_buf_t              *pt_immed_data;
 177  167          pppt_buf_t              *pt_read_buf;
 178  168          stmf_ic_msgid_t         pt_read_xfer_msgid;
 179  169  } pppt_task_t;
 180  170  
 181  171  /*
 182  172   * Error statistics
 183  173   */
 184  174  typedef struct {
 185  175          uint64_t                es_tgt_reg_svc_disabled;
 186  176          uint64_t                es_tgt_reg_duplicate;
 187  177          uint64_t                es_tgt_reg_create_fail;
 188  178          uint64_t                es_tgt_dereg_svc_disabled;
 189  179          uint64_t                es_tgt_dereg_not_found;
 190  180          uint64_t                es_sess_destroy_no_session;
 191  181          uint64_t                es_sess_lookup_no_session;
 192  182          uint64_t                es_sess_lookup_ident_mismatch;
 193  183          uint64_t                es_sess_lookup_bad_tgt_state;
 194  184          uint64_t                es_scmd_ptask_alloc_fail;
 195  185          uint64_t                es_scmd_sess_create_fail;
 196  186          uint64_t                es_scmd_stask_alloc_fail;
 197  187          uint64_t                es_scmd_dup_task_count;
 198  188  } pppt_error_stats_t;
 199  189  
 200  190  #define PPPT_INC_STAT(stat_field) \
 201  191          atomic_inc_64(&pppt_global.global_error_stats.stat_field);
 202  192  
 203  193  /*
 204  194   * State values for the iscsit service
 205  195   */
 206  196  typedef enum {
 207  197          PSS_UNDEFINED = 0,
 208  198          PSS_DETACHED,
 209  199          PSS_DISABLED,
 210  200          PSS_ENABLING,
 211  201          PSS_ENABLED,
 212  202          PSS_BUSY,
 213  203          PSS_DISABLING
 214  204  } pppt_service_state_t;
 215  205  
 216  206  
 217  207  typedef struct {
 218  208          pppt_service_state_t    global_svc_state;
 219  209          dev_info_t              *global_dip;
 220  210          stmf_port_provider_t    *global_pp;
 221  211          stmf_dbuf_store_t       *global_dbuf_store;
 222  212          taskq_t                 *global_dispatch_taskq;
 223  213          taskq_t                 *global_sess_taskq;
 224  214          avl_tree_t              global_sess_list;
 225  215          avl_tree_t              global_target_list;
 226  216          kmutex_t                global_lock;
 227  217          door_handle_t           global_door;
 228  218          kmutex_t                global_door_lock;
 229  219          pppt_error_stats_t      global_error_stats;
 230  220  } pppt_global_t;
 231  221  
 232  222  extern pppt_global_t pppt_global;
 233  223  
 234  224  stmf_status_t pppt_lport_xfer_data(scsi_task_t *task, stmf_data_buf_t *dbuf,
 235  225      uint32_t ioflags);
 236  226  
 237  227  void pppt_xfer_read_complete(pppt_task_t *pppt_task, stmf_status_t status);
 238  228  
 239  229  stmf_status_t pppt_lport_send_status(scsi_task_t *task, uint32_t ioflags);
 240  230  
 241  231  void pppt_lport_task_free(scsi_task_t *task);
 242  232  
 243  233  stmf_status_t pppt_lport_abort(stmf_local_port_t *lport, int abort_cmd,
 244  234      void *arg, uint32_t flags);
 245  235  
 246  236  void pppt_lport_ctl(stmf_local_port_t *lport, int cmd, void *arg);
 247  237  
 248  238  pppt_sess_t *pppt_sess_lookup_locked(uint64_t session_id,
 249  239      scsi_devid_desc_t *lport_devid,
 250  240      stmf_remote_port_t *rport);
 251  241  
 252  242  pppt_sess_t *pppt_sess_lookup_by_id_locked(uint64_t session_id);
 253  243  
 254  244  pppt_sess_t *pppt_sess_lookup_create(scsi_devid_desc_t *lport_devid,
 255  245      scsi_devid_desc_t *rport_devid, stmf_remote_port_t *rport,
 256  246      uint64_t session_id, stmf_status_t *statusp);
 257  247  
 258  248  void pppt_sess_rele(pppt_sess_t *sks);
 259  249  
 260  250  void pppt_sess_rele_locked(pppt_sess_t *sks);
 261  251  
 262  252  void pppt_sess_close_locked(pppt_sess_t *ps);
 263  253  
 264  254  int pppt_sess_avl_compare_by_id(const void *void_sess1,
 265  255      const void *void_sess2);
 266  256  
 267  257  int pppt_sess_avl_compare_by_name(const void *void_sess1,
 268  258      const void *void_sess2);
 269  259  
 270  260  pppt_task_t *pppt_task_alloc(void);
 271  261  
 272  262  void pppt_task_free(pppt_task_t *ptask);
 273  263  
 274  264  pppt_status_t pppt_task_start(pppt_task_t *ptask);
 275  265  
 276  266  pppt_status_t pppt_task_done(pppt_task_t *ptask);
 277  267  
 278  268  pppt_task_t *pppt_task_lookup(stmf_ic_msgid_t msgid);
 279  269  
 280  270  void pppt_msg_rx(stmf_ic_msg_t *msg);
 281  271  
 282  272  void pppt_msg_tx_status(stmf_ic_msg_t *orig_msg, stmf_status_t status);
 283  273  
 284  274  pppt_tgt_t *pppt_tgt_lookup(scsi_devid_desc_t *tgt_devid);
 285  275  
 286  276  pppt_tgt_t *pppt_tgt_lookup_locked(scsi_devid_desc_t *tgt_devid);
 287  277  
 288  278  pppt_tgt_t *pppt_tgt_create(stmf_ic_reg_port_msg_t *reg_port,
 289  279      stmf_status_t *errcode);
 290  280  
 291  281  void pppt_tgt_async_delete(pppt_tgt_t *tgt);
 292  282  
 293  283  void pppt_tgt_destroy(pppt_tgt_t *tgt);
 294  284  
 295  285  int pppt_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2);
 296  286  
 297  287  void pppt_tgt_sm_ctl(stmf_local_port_t *lport, int cmd, void *arg);
 298  288  
 299  289  pppt_status_t pppt_task_hold(pppt_task_t *);
 300  290  
 301  291  #ifdef  __cplusplus
 302  292  }
 303  293  #endif
 304  294  
 305  295  #endif  /* _PPPT_H */
  
    | 
      ↓ open down ↓ | 
    176 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX