0001
0002
0003
0004
0005
0006
0007 #ifndef __EFCLIB_H__
0008 #define __EFCLIB_H__
0009
0010 #include "scsi/fc/fc_els.h"
0011 #include "scsi/fc/fc_fs.h"
0012 #include "scsi/fc/fc_ns.h"
0013 #include "scsi/fc/fc_gs.h"
0014 #include "scsi/fc_frame.h"
0015 #include "../include/efc_common.h"
0016 #include "../libefc_sli/sli4.h"
0017
0018 #define EFC_SERVICE_PARMS_LENGTH 120
0019 #define EFC_NAME_LENGTH 32
0020 #define EFC_SM_NAME_LENGTH 64
0021 #define EFC_DISPLAY_BUS_INFO_LENGTH 16
0022
0023 #define EFC_WWN_LENGTH 32
0024
0025 #define EFC_FC_ELS_DEFAULT_RETRIES 3
0026
0027
0028 #define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT 0
0029 #define EFC_FC_FLOGI_TIMEOUT_SEC 5
0030 #define EFC_SHUTDOWN_TIMEOUT_USEC 30000000
0031
0032
0033 #define EFC_SCSI_CALL_COMPLETE 0
0034 #define EFC_SCSI_CALL_ASYNC 1
0035
0036
0037 enum efc_nport_topology {
0038 EFC_NPORT_TOPO_UNKNOWN = 0,
0039 EFC_NPORT_TOPO_FABRIC,
0040 EFC_NPORT_TOPO_P2P,
0041 EFC_NPORT_TOPO_FC_AL,
0042 };
0043
0044 #define enable_target_rscn(efc) 1
0045
0046 enum efc_node_shutd_rsn {
0047 EFC_NODE_SHUTDOWN_DEFAULT = 0,
0048 EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
0049 EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
0050 };
0051
0052 enum efc_node_send_ls_acc {
0053 EFC_NODE_SEND_LS_ACC_NONE = 0,
0054 EFC_NODE_SEND_LS_ACC_PLOGI,
0055 EFC_NODE_SEND_LS_ACC_PRLI,
0056 };
0057
0058 #define EFC_LINK_STATUS_UP 0
0059 #define EFC_LINK_STATUS_DOWN 1
0060
0061
0062 struct efc_sm_ctx {
0063 void (*current_state)(struct efc_sm_ctx *ctx,
0064 u32 evt, void *arg);
0065
0066 const char *description;
0067 void *app;
0068 };
0069
0070
0071 struct efc_domain_record {
0072 u32 index;
0073 u32 priority;
0074 u8 address[6];
0075 u8 wwn[8];
0076 union {
0077 u8 vlan[512];
0078 u8 loop[128];
0079 } map;
0080 u32 speed;
0081 u32 fc_id;
0082 bool is_loop;
0083 bool is_nport;
0084 };
0085
0086
0087 enum efc_hw_domain_event {
0088 EFC_HW_DOMAIN_ALLOC_OK,
0089 EFC_HW_DOMAIN_ALLOC_FAIL,
0090 EFC_HW_DOMAIN_ATTACH_OK,
0091 EFC_HW_DOMAIN_ATTACH_FAIL,
0092 EFC_HW_DOMAIN_FREE_OK,
0093 EFC_HW_DOMAIN_FREE_FAIL,
0094 EFC_HW_DOMAIN_LOST,
0095 EFC_HW_DOMAIN_FOUND,
0096 EFC_HW_DOMAIN_CHANGED,
0097 };
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 struct efc_nport {
0136 struct list_head list_entry;
0137 struct kref ref;
0138 void (*release)(struct kref *arg);
0139 struct efc *efc;
0140 u32 instance_index;
0141 char display_name[EFC_NAME_LENGTH];
0142 bool is_vport;
0143 bool free_req_pending;
0144 bool attached;
0145 bool attaching;
0146 bool p2p_winner;
0147 struct efc_domain *domain;
0148 u64 wwpn;
0149 u64 wwnn;
0150 void *tgt_data;
0151 void *ini_data;
0152
0153 u32 indicator;
0154 u32 fc_id;
0155 struct efc_dma dma;
0156
0157 u8 wwnn_str[EFC_WWN_LENGTH];
0158 __be64 sli_wwpn;
0159 __be64 sli_wwnn;
0160
0161 struct efc_sm_ctx sm;
0162 struct xarray lookup;
0163 bool enable_ini;
0164 bool enable_tgt;
0165 bool enable_rscn;
0166 bool shutting_down;
0167 u32 p2p_port_id;
0168 enum efc_nport_topology topology;
0169 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
0170 u32 p2p_remote_port_id;
0171 };
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 struct efc_domain {
0209 struct efc *efc;
0210 char display_name[EFC_NAME_LENGTH];
0211 struct list_head nport_list;
0212 struct kref ref;
0213 void (*release)(struct kref *arg);
0214 void *ini_domain;
0215 void *tgt_domain;
0216
0217
0218 u32 fcf;
0219 u32 fcf_indicator;
0220 u32 indicator;
0221 u32 nport_count;
0222 struct efc_dma dma;
0223
0224
0225 u64 fcf_wwn;
0226 struct efc_sm_ctx drvsm;
0227 bool attached;
0228 bool is_fc;
0229 bool is_loop;
0230 bool is_nlport;
0231 bool domain_found_pending;
0232 bool req_domain_free;
0233 bool req_accept_frames;
0234 bool domain_notify_pend;
0235
0236 struct efc_domain_record pending_drec;
0237 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
0238 u8 flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
0239
0240 struct xarray lookup;
0241
0242 struct efc_nport *nport;
0243 };
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 struct efc_remote_node {
0258 u32 indicator;
0259 u32 index;
0260 u32 fc_id;
0261
0262 bool attached;
0263
0264 struct efc_nport *nport;
0265 void *node;
0266 };
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318 struct efc_node {
0319 struct efc *efc;
0320 char display_name[EFC_NAME_LENGTH];
0321 struct efc_nport *nport;
0322 struct kref ref;
0323 void (*release)(struct kref *arg);
0324 bool hold_frames;
0325 bool els_io_enabled;
0326 bool send_plogi_acc;
0327 bool send_plogi;
0328 bool rscn_pending;
0329 bool fcp_enabled;
0330 bool attached;
0331 bool req_free;
0332
0333 spinlock_t els_ios_lock;
0334 struct list_head els_ios_list;
0335 void *ini_node;
0336 void *tgt_node;
0337
0338 struct efc_remote_node rnode;
0339
0340 struct efc_sm_ctx sm;
0341 u32 evtdepth;
0342
0343 enum efc_node_send_ls_acc send_ls_acc;
0344 void *ls_acc_io;
0345 u32 ls_acc_oxid;
0346 u32 ls_acc_did;
0347 enum efc_node_shutd_rsn shutdown_reason;
0348 bool targ;
0349 bool init;
0350 bool refound;
0351 struct efc_dma sparm_dma_buf;
0352 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
0353 spinlock_t pend_frames_lock;
0354 struct list_head pend_frames;
0355 u32 pend_frames_processed;
0356 u32 ox_id_in_use;
0357 u32 els_retries_remaining;
0358 u32 els_req_cnt;
0359 u32 els_cmpl_cnt;
0360 u32 abort_cnt;
0361
0362 char current_state_name[EFC_SM_NAME_LENGTH];
0363 char prev_state_name[EFC_SM_NAME_LENGTH];
0364 int current_evt;
0365 int prev_evt;
0366
0367 void (*nodedb_state)(struct efc_sm_ctx *ctx,
0368 u32 evt, void *arg);
0369 struct timer_list gidpt_delay_timer;
0370 u64 time_last_gidpt_msec;
0371
0372 char wwnn[EFC_WWN_LENGTH];
0373 char wwpn[EFC_WWN_LENGTH];
0374 };
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390 struct efc_vport {
0391 struct list_head list_entry;
0392 u64 wwnn;
0393 u64 wwpn;
0394 u32 fc_id;
0395 bool enable_tgt;
0396 bool enable_ini;
0397 void *tgt_data;
0398 void *ini_data;
0399 struct efc_nport *nport;
0400 };
0401
0402 #define node_printf(node, fmt, args...) \
0403 efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
0404
0405
0406 struct efc_node_cb {
0407 int status;
0408 int ext_status;
0409 struct efc_hw_rq_buffer *header;
0410 struct efc_hw_rq_buffer *payload;
0411 struct efc_dma els_rsp;
0412
0413
0414 int rsp_len;
0415 };
0416
0417 struct efc_hw_rq_buffer {
0418 u16 rqindex;
0419 struct efc_dma dma;
0420 };
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432 struct efc_hw_sequence {
0433 struct list_head list_entry;
0434 void *hw;
0435 u8 fcfi;
0436 struct efc_hw_rq_buffer *header;
0437 struct efc_hw_rq_buffer *payload;
0438 void *hw_priv;
0439 };
0440
0441 enum efc_disc_io_type {
0442 EFC_DISC_IO_ELS_REQ,
0443 EFC_DISC_IO_ELS_RESP,
0444 EFC_DISC_IO_CT_REQ,
0445 EFC_DISC_IO_CT_RESP
0446 };
0447
0448 struct efc_io_els_params {
0449 u32 s_id;
0450 u16 ox_id;
0451 u8 timeout;
0452 };
0453
0454 struct efc_io_ct_params {
0455 u8 r_ctl;
0456 u8 type;
0457 u8 df_ctl;
0458 u8 timeout;
0459 u16 ox_id;
0460 };
0461
0462 union efc_disc_io_param {
0463 struct efc_io_els_params els;
0464 struct efc_io_ct_params ct;
0465 };
0466
0467 struct efc_disc_io {
0468 struct efc_dma req;
0469 struct efc_dma rsp;
0470 enum efc_disc_io_type io_type;
0471 u16 xmit_len;
0472 u16 rsp_len;
0473 u32 rpi;
0474 u32 vpi;
0475 u32 s_id;
0476 u32 d_id;
0477 bool rpi_registered;
0478 union efc_disc_io_param iparam;
0479 };
0480
0481
0482 #define EFC_HW_SEQ_HOLD 0
0483
0484 #define EFC_HW_SEQ_FREE 1
0485
0486 struct libefc_function_template {
0487
0488 int (*new_nport)(struct efc *efc, struct efc_nport *sp);
0489 void (*del_nport)(struct efc *efc, struct efc_nport *sp);
0490
0491
0492 int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
0493 int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
0494
0495 int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
0496
0497 int (*send_els)(struct efc *efc, struct efc_disc_io *io);
0498
0499 int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
0500
0501 int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
0502 };
0503
0504 #define EFC_LOG_LIB 0x01
0505 #define EFC_LOG_NODE 0x02
0506 #define EFC_LOG_PORT 0x04
0507 #define EFC_LOG_DOMAIN 0x08
0508 #define EFC_LOG_ELS 0x10
0509 #define EFC_LOG_DOMAIN_SM 0x20
0510 #define EFC_LOG_SM 0x40
0511
0512
0513 struct efc {
0514 void *base;
0515 struct pci_dev *pci;
0516 struct sli4 *sli;
0517 u32 fcfi;
0518 u64 req_wwpn;
0519 u64 req_wwnn;
0520
0521 u64 def_wwpn;
0522 u64 def_wwnn;
0523 u64 max_xfer_size;
0524 mempool_t *node_pool;
0525 struct dma_pool *node_dma_pool;
0526 u32 nodes_count;
0527
0528 u32 link_status;
0529
0530 struct list_head vport_list;
0531
0532 spinlock_t vport_lock;
0533
0534 struct libefc_function_template tt;
0535
0536
0537
0538 spinlock_t lock;
0539
0540 bool enable_ini;
0541 bool enable_tgt;
0542
0543 u32 log_level;
0544
0545 struct efc_domain *domain;
0546 void (*domain_free_cb)(struct efc *efc, void *arg);
0547 void *domain_free_cb_arg;
0548
0549 u64 tgt_rscn_delay_msec;
0550 u64 tgt_rscn_period_msec;
0551
0552 bool external_loopback;
0553 u32 nodedb_mask;
0554 u32 logmask;
0555 mempool_t *els_io_pool;
0556 atomic_t els_io_alloc_failed_count;
0557
0558
0559 bool hold_frames;
0560
0561 spinlock_t pend_frames_lock;
0562 struct list_head pend_frames;
0563
0564 u32 pend_frames_processed;
0565
0566 };
0567
0568
0569
0570
0571 int efcport_init(struct efc *efc);
0572 void efcport_destroy(struct efc *efc);
0573
0574
0575
0576 int efc_domain_cb(void *arg, int event, void *data);
0577 void
0578 efc_register_domain_free_cb(struct efc *efc,
0579 void (*callback)(struct efc *efc, void *arg),
0580 void *arg);
0581
0582
0583
0584
0585 void efc_nport_cb(void *arg, int event, void *data);
0586 struct efc_vport *
0587 efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
0588 bool enable_ini, bool enable_tgt,
0589 void *tgt_data, void *ini_data);
0590 int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
0591 u64 wwnn, u32 fc_id, bool ini, bool tgt,
0592 void *tgt_data, void *ini_data);
0593 int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
0594 u64 wwpn, u64 wwnn);
0595
0596 void efc_vport_del_all(struct efc *efc);
0597
0598
0599
0600
0601 int efc_remote_node_cb(void *arg, int event, void *data);
0602 void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
0603 void efc_node_post_shutdown(struct efc_node *node, void *arg);
0604 u64 efc_node_get_wwpn(struct efc_node *node);
0605
0606
0607
0608
0609 void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
0610 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
0611 u32 ext_status);
0612
0613
0614
0615
0616 void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
0617 void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
0618 void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
0619 void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
0620
0621 #endif