1
2
3
4
5
6
7#ifndef __EFCLIB_H__
8#define __EFCLIB_H__
9
10#include "scsi/fc/fc_els.h"
11#include "scsi/fc/fc_fs.h"
12#include "scsi/fc/fc_ns.h"
13#include "scsi/fc/fc_gs.h"
14#include "scsi/fc_frame.h"
15#include "../include/efc_common.h"
16#include "../libefc_sli/sli4.h"
17
18#define EFC_SERVICE_PARMS_LENGTH 120
19#define EFC_NAME_LENGTH 32
20#define EFC_SM_NAME_LENGTH 64
21#define EFC_DISPLAY_BUS_INFO_LENGTH 16
22
23#define EFC_WWN_LENGTH 32
24
25#define EFC_FC_ELS_DEFAULT_RETRIES 3
26
27
28#define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT 0
29#define EFC_FC_FLOGI_TIMEOUT_SEC 5
30#define EFC_SHUTDOWN_TIMEOUT_USEC 30000000
31
32
33#define EFC_SCSI_CALL_COMPLETE 0
34#define EFC_SCSI_CALL_ASYNC 1
35
36
37enum efc_nport_topology {
38 EFC_NPORT_TOPO_UNKNOWN = 0,
39 EFC_NPORT_TOPO_FABRIC,
40 EFC_NPORT_TOPO_P2P,
41 EFC_NPORT_TOPO_FC_AL,
42};
43
44#define enable_target_rscn(efc) 1
45
46enum efc_node_shutd_rsn {
47 EFC_NODE_SHUTDOWN_DEFAULT = 0,
48 EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
49 EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
50};
51
52enum efc_node_send_ls_acc {
53 EFC_NODE_SEND_LS_ACC_NONE = 0,
54 EFC_NODE_SEND_LS_ACC_PLOGI,
55 EFC_NODE_SEND_LS_ACC_PRLI,
56};
57
58#define EFC_LINK_STATUS_UP 0
59#define EFC_LINK_STATUS_DOWN 1
60
61
62struct efc_sm_ctx {
63 void (*current_state)(struct efc_sm_ctx *ctx,
64 u32 evt, void *arg);
65
66 const char *description;
67 void *app;
68};
69
70
71struct efc_domain_record {
72 u32 index;
73 u32 priority;
74 u8 address[6];
75 u8 wwn[8];
76 union {
77 u8 vlan[512];
78 u8 loop[128];
79 } map;
80 u32 speed;
81 u32 fc_id;
82 bool is_loop;
83 bool is_nport;
84};
85
86
87enum efc_hw_domain_event {
88 EFC_HW_DOMAIN_ALLOC_OK,
89 EFC_HW_DOMAIN_ALLOC_FAIL,
90 EFC_HW_DOMAIN_ATTACH_OK,
91 EFC_HW_DOMAIN_ATTACH_FAIL,
92 EFC_HW_DOMAIN_FREE_OK,
93 EFC_HW_DOMAIN_FREE_FAIL,
94 EFC_HW_DOMAIN_LOST,
95 EFC_HW_DOMAIN_FOUND,
96 EFC_HW_DOMAIN_CHANGED,
97};
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135struct efc_nport {
136 struct list_head list_entry;
137 struct kref ref;
138 void (*release)(struct kref *arg);
139 struct efc *efc;
140 u32 instance_index;
141 char display_name[EFC_NAME_LENGTH];
142 bool is_vport;
143 bool free_req_pending;
144 bool attached;
145 bool p2p_winner;
146 struct efc_domain *domain;
147 u64 wwpn;
148 u64 wwnn;
149 void *tgt_data;
150 void *ini_data;
151
152 u32 indicator;
153 u32 fc_id;
154 struct efc_dma dma;
155
156 u8 wwnn_str[EFC_WWN_LENGTH];
157 __be64 sli_wwpn;
158 __be64 sli_wwnn;
159
160 struct efc_sm_ctx sm;
161 struct xarray lookup;
162 bool enable_ini;
163 bool enable_tgt;
164 bool enable_rscn;
165 bool shutting_down;
166 u32 p2p_port_id;
167 enum efc_nport_topology topology;
168 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
169 u32 p2p_remote_port_id;
170};
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207struct efc_domain {
208 struct efc *efc;
209 char display_name[EFC_NAME_LENGTH];
210 struct list_head nport_list;
211 struct kref ref;
212 void (*release)(struct kref *arg);
213 void *ini_domain;
214 void *tgt_domain;
215
216
217 u32 fcf;
218 u32 fcf_indicator;
219 u32 indicator;
220 u32 nport_count;
221 struct efc_dma dma;
222
223
224 u64 fcf_wwn;
225 struct efc_sm_ctx drvsm;
226 bool attached;
227 bool is_fc;
228 bool is_loop;
229 bool is_nlport;
230 bool domain_found_pending;
231 bool req_domain_free;
232 bool req_accept_frames;
233 bool domain_notify_pend;
234
235 struct efc_domain_record pending_drec;
236 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
237 u8 flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
238
239 struct xarray lookup;
240
241 struct efc_nport *nport;
242};
243
244
245
246
247
248
249
250
251
252
253
254
255
256struct efc_remote_node {
257 u32 indicator;
258 u32 index;
259 u32 fc_id;
260
261 bool attached;
262
263 struct efc_nport *nport;
264 void *node;
265};
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317struct efc_node {
318 struct efc *efc;
319 char display_name[EFC_NAME_LENGTH];
320 struct efc_nport *nport;
321 struct kref ref;
322 void (*release)(struct kref *arg);
323 bool hold_frames;
324 bool els_io_enabled;
325 bool send_plogi_acc;
326 bool send_plogi;
327 bool rscn_pending;
328 bool fcp_enabled;
329 bool attached;
330 bool req_free;
331
332 spinlock_t els_ios_lock;
333 struct list_head els_ios_list;
334 void *ini_node;
335 void *tgt_node;
336
337 struct efc_remote_node rnode;
338
339 struct efc_sm_ctx sm;
340 u32 evtdepth;
341
342 enum efc_node_send_ls_acc send_ls_acc;
343 void *ls_acc_io;
344 u32 ls_acc_oxid;
345 u32 ls_acc_did;
346 enum efc_node_shutd_rsn shutdown_reason;
347 bool targ;
348 bool init;
349 bool refound;
350 struct efc_dma sparm_dma_buf;
351 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
352 spinlock_t pend_frames_lock;
353 struct list_head pend_frames;
354 u32 pend_frames_processed;
355 u32 ox_id_in_use;
356 u32 els_retries_remaining;
357 u32 els_req_cnt;
358 u32 els_cmpl_cnt;
359 u32 abort_cnt;
360
361 char current_state_name[EFC_SM_NAME_LENGTH];
362 char prev_state_name[EFC_SM_NAME_LENGTH];
363 int current_evt;
364 int prev_evt;
365
366 void (*nodedb_state)(struct efc_sm_ctx *ctx,
367 u32 evt, void *arg);
368 struct timer_list gidpt_delay_timer;
369 u64 time_last_gidpt_msec;
370
371 char wwnn[EFC_WWN_LENGTH];
372 char wwpn[EFC_WWN_LENGTH];
373};
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389struct efc_vport {
390 struct list_head list_entry;
391 u64 wwnn;
392 u64 wwpn;
393 u32 fc_id;
394 bool enable_tgt;
395 bool enable_ini;
396 void *tgt_data;
397 void *ini_data;
398 struct efc_nport *nport;
399};
400
401#define node_printf(node, fmt, args...) \
402 efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
403
404
405struct efc_node_cb {
406 int status;
407 int ext_status;
408 struct efc_hw_rq_buffer *header;
409 struct efc_hw_rq_buffer *payload;
410 struct efc_dma els_rsp;
411
412
413 int rsp_len;
414};
415
416struct efc_hw_rq_buffer {
417 u16 rqindex;
418 struct efc_dma dma;
419};
420
421
422
423
424
425
426
427
428
429
430
431struct efc_hw_sequence {
432 struct list_head list_entry;
433 void *hw;
434 u8 fcfi;
435 struct efc_hw_rq_buffer *header;
436 struct efc_hw_rq_buffer *payload;
437 void *hw_priv;
438};
439
440enum efc_disc_io_type {
441 EFC_DISC_IO_ELS_REQ,
442 EFC_DISC_IO_ELS_RESP,
443 EFC_DISC_IO_CT_REQ,
444 EFC_DISC_IO_CT_RESP
445};
446
447struct efc_io_els_params {
448 u32 s_id;
449 u16 ox_id;
450 u8 timeout;
451};
452
453struct efc_io_ct_params {
454 u8 r_ctl;
455 u8 type;
456 u8 df_ctl;
457 u8 timeout;
458 u16 ox_id;
459};
460
461union efc_disc_io_param {
462 struct efc_io_els_params els;
463 struct efc_io_ct_params ct;
464};
465
466struct efc_disc_io {
467 struct efc_dma req;
468 struct efc_dma rsp;
469 enum efc_disc_io_type io_type;
470 u16 xmit_len;
471 u16 rsp_len;
472 u32 rpi;
473 u32 vpi;
474 u32 s_id;
475 u32 d_id;
476 bool rpi_registered;
477 union efc_disc_io_param iparam;
478};
479
480
481#define EFC_HW_SEQ_HOLD 0
482
483#define EFC_HW_SEQ_FREE 1
484
485struct libefc_function_template {
486
487 int (*new_nport)(struct efc *efc, struct efc_nport *sp);
488 void (*del_nport)(struct efc *efc, struct efc_nport *sp);
489
490
491 int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
492 int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
493
494 int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
495
496 int (*send_els)(struct efc *efc, struct efc_disc_io *io);
497
498 int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
499
500 int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
501};
502
503#define EFC_LOG_LIB 0x01
504#define EFC_LOG_NODE 0x02
505#define EFC_LOG_PORT 0x04
506#define EFC_LOG_DOMAIN 0x08
507#define EFC_LOG_ELS 0x10
508#define EFC_LOG_DOMAIN_SM 0x20
509#define EFC_LOG_SM 0x40
510
511
512struct efc {
513 void *base;
514 struct pci_dev *pci;
515 struct sli4 *sli;
516 u32 fcfi;
517 u64 req_wwpn;
518 u64 req_wwnn;
519
520 u64 def_wwpn;
521 u64 def_wwnn;
522 u64 max_xfer_size;
523 mempool_t *node_pool;
524 struct dma_pool *node_dma_pool;
525 u32 nodes_count;
526
527 u32 link_status;
528
529 struct list_head vport_list;
530
531 spinlock_t vport_lock;
532
533 struct libefc_function_template tt;
534
535
536
537 spinlock_t lock;
538
539 bool enable_ini;
540 bool enable_tgt;
541
542 u32 log_level;
543
544 struct efc_domain *domain;
545 void (*domain_free_cb)(struct efc *efc, void *arg);
546 void *domain_free_cb_arg;
547
548 u64 tgt_rscn_delay_msec;
549 u64 tgt_rscn_period_msec;
550
551 bool external_loopback;
552 u32 nodedb_mask;
553 u32 logmask;
554 mempool_t *els_io_pool;
555 atomic_t els_io_alloc_failed_count;
556
557
558 bool hold_frames;
559
560 spinlock_t pend_frames_lock;
561 struct list_head pend_frames;
562
563 u32 pend_frames_processed;
564
565};
566
567
568
569
570int efcport_init(struct efc *efc);
571void efcport_destroy(struct efc *efc);
572
573
574
575int efc_domain_cb(void *arg, int event, void *data);
576void
577efc_register_domain_free_cb(struct efc *efc,
578 void (*callback)(struct efc *efc, void *arg),
579 void *arg);
580
581
582
583
584void efc_nport_cb(void *arg, int event, void *data);
585struct efc_vport *
586efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
587 bool enable_ini, bool enable_tgt,
588 void *tgt_data, void *ini_data);
589int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
590 u64 wwnn, u32 fc_id, bool ini, bool tgt,
591 void *tgt_data, void *ini_data);
592int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
593 u64 wwpn, u64 wwnn);
594
595void efc_vport_del_all(struct efc *efc);
596
597
598
599
600int efc_remote_node_cb(void *arg, int event, void *data);
601void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
602void efc_node_post_shutdown(struct efc_node *node, void *arg);
603u64 efc_node_get_wwpn(struct efc_node *node);
604
605
606
607
608void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
609void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
610 u32 ext_status);
611
612
613
614
615void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
616void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
617void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
618void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
619
620#endif
621