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 attaching;
146 bool p2p_winner;
147 struct efc_domain *domain;
148 u64 wwpn;
149 u64 wwnn;
150 void *tgt_data;
151 void *ini_data;
152
153 u32 indicator;
154 u32 fc_id;
155 struct efc_dma dma;
156
157 u8 wwnn_str[EFC_WWN_LENGTH];
158 __be64 sli_wwpn;
159 __be64 sli_wwnn;
160
161 struct efc_sm_ctx sm;
162 struct xarray lookup;
163 bool enable_ini;
164 bool enable_tgt;
165 bool enable_rscn;
166 bool shutting_down;
167 u32 p2p_port_id;
168 enum efc_nport_topology topology;
169 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
170 u32 p2p_remote_port_id;
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
207
208struct efc_domain {
209 struct efc *efc;
210 char display_name[EFC_NAME_LENGTH];
211 struct list_head nport_list;
212 struct kref ref;
213 void (*release)(struct kref *arg);
214 void *ini_domain;
215 void *tgt_domain;
216
217
218 u32 fcf;
219 u32 fcf_indicator;
220 u32 indicator;
221 u32 nport_count;
222 struct efc_dma dma;
223
224
225 u64 fcf_wwn;
226 struct efc_sm_ctx drvsm;
227 bool attached;
228 bool is_fc;
229 bool is_loop;
230 bool is_nlport;
231 bool domain_found_pending;
232 bool req_domain_free;
233 bool req_accept_frames;
234 bool domain_notify_pend;
235
236 struct efc_domain_record pending_drec;
237 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
238 u8 flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
239
240 struct xarray lookup;
241
242 struct efc_nport *nport;
243};
244
245
246
247
248
249
250
251
252
253
254
255
256
257struct efc_remote_node {
258 u32 indicator;
259 u32 index;
260 u32 fc_id;
261
262 bool attached;
263
264 struct efc_nport *nport;
265 void *node;
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
317
318struct efc_node {
319 struct efc *efc;
320 char display_name[EFC_NAME_LENGTH];
321 struct efc_nport *nport;
322 struct kref ref;
323 void (*release)(struct kref *arg);
324 bool hold_frames;
325 bool els_io_enabled;
326 bool send_plogi_acc;
327 bool send_plogi;
328 bool rscn_pending;
329 bool fcp_enabled;
330 bool attached;
331 bool req_free;
332
333 spinlock_t els_ios_lock;
334 struct list_head els_ios_list;
335 void *ini_node;
336 void *tgt_node;
337
338 struct efc_remote_node rnode;
339
340 struct efc_sm_ctx sm;
341 u32 evtdepth;
342
343 enum efc_node_send_ls_acc send_ls_acc;
344 void *ls_acc_io;
345 u32 ls_acc_oxid;
346 u32 ls_acc_did;
347 enum efc_node_shutd_rsn shutdown_reason;
348 bool targ;
349 bool init;
350 bool refound;
351 struct efc_dma sparm_dma_buf;
352 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
353 spinlock_t pend_frames_lock;
354 struct list_head pend_frames;
355 u32 pend_frames_processed;
356 u32 ox_id_in_use;
357 u32 els_retries_remaining;
358 u32 els_req_cnt;
359 u32 els_cmpl_cnt;
360 u32 abort_cnt;
361
362 char current_state_name[EFC_SM_NAME_LENGTH];
363 char prev_state_name[EFC_SM_NAME_LENGTH];
364 int current_evt;
365 int prev_evt;
366
367 void (*nodedb_state)(struct efc_sm_ctx *ctx,
368 u32 evt, void *arg);
369 struct timer_list gidpt_delay_timer;
370 u64 time_last_gidpt_msec;
371
372 char wwnn[EFC_WWN_LENGTH];
373 char wwpn[EFC_WWN_LENGTH];
374};
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390struct efc_vport {
391 struct list_head list_entry;
392 u64 wwnn;
393 u64 wwpn;
394 u32 fc_id;
395 bool enable_tgt;
396 bool enable_ini;
397 void *tgt_data;
398 void *ini_data;
399 struct efc_nport *nport;
400};
401
402#define node_printf(node, fmt, args...) \
403 efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
404
405
406struct efc_node_cb {
407 int status;
408 int ext_status;
409 struct efc_hw_rq_buffer *header;
410 struct efc_hw_rq_buffer *payload;
411 struct efc_dma els_rsp;
412
413
414 int rsp_len;
415};
416
417struct efc_hw_rq_buffer {
418 u16 rqindex;
419 struct efc_dma dma;
420};
421
422
423
424
425
426
427
428
429
430
431
432struct efc_hw_sequence {
433 struct list_head list_entry;
434 void *hw;
435 u8 fcfi;
436 struct efc_hw_rq_buffer *header;
437 struct efc_hw_rq_buffer *payload;
438 void *hw_priv;
439};
440
441enum efc_disc_io_type {
442 EFC_DISC_IO_ELS_REQ,
443 EFC_DISC_IO_ELS_RESP,
444 EFC_DISC_IO_CT_REQ,
445 EFC_DISC_IO_CT_RESP
446};
447
448struct efc_io_els_params {
449 u32 s_id;
450 u16 ox_id;
451 u8 timeout;
452};
453
454struct efc_io_ct_params {
455 u8 r_ctl;
456 u8 type;
457 u8 df_ctl;
458 u8 timeout;
459 u16 ox_id;
460};
461
462union efc_disc_io_param {
463 struct efc_io_els_params els;
464 struct efc_io_ct_params ct;
465};
466
467struct efc_disc_io {
468 struct efc_dma req;
469 struct efc_dma rsp;
470 enum efc_disc_io_type io_type;
471 u16 xmit_len;
472 u16 rsp_len;
473 u32 rpi;
474 u32 vpi;
475 u32 s_id;
476 u32 d_id;
477 bool rpi_registered;
478 union efc_disc_io_param iparam;
479};
480
481
482#define EFC_HW_SEQ_HOLD 0
483
484#define EFC_HW_SEQ_FREE 1
485
486struct libefc_function_template {
487
488 int (*new_nport)(struct efc *efc, struct efc_nport *sp);
489 void (*del_nport)(struct efc *efc, struct efc_nport *sp);
490
491
492 int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
493 int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
494
495 int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
496
497 int (*send_els)(struct efc *efc, struct efc_disc_io *io);
498
499 int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
500
501 int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
502};
503
504#define EFC_LOG_LIB 0x01
505#define EFC_LOG_NODE 0x02
506#define EFC_LOG_PORT 0x04
507#define EFC_LOG_DOMAIN 0x08
508#define EFC_LOG_ELS 0x10
509#define EFC_LOG_DOMAIN_SM 0x20
510#define EFC_LOG_SM 0x40
511
512
513struct efc {
514 void *base;
515 struct pci_dev *pci;
516 struct sli4 *sli;
517 u32 fcfi;
518 u64 req_wwpn;
519 u64 req_wwnn;
520
521 u64 def_wwpn;
522 u64 def_wwnn;
523 u64 max_xfer_size;
524 mempool_t *node_pool;
525 struct dma_pool *node_dma_pool;
526 u32 nodes_count;
527
528 u32 link_status;
529
530 struct list_head vport_list;
531
532 spinlock_t vport_lock;
533
534 struct libefc_function_template tt;
535
536
537
538 spinlock_t lock;
539
540 bool enable_ini;
541 bool enable_tgt;
542
543 u32 log_level;
544
545 struct efc_domain *domain;
546 void (*domain_free_cb)(struct efc *efc, void *arg);
547 void *domain_free_cb_arg;
548
549 u64 tgt_rscn_delay_msec;
550 u64 tgt_rscn_period_msec;
551
552 bool external_loopback;
553 u32 nodedb_mask;
554 u32 logmask;
555 mempool_t *els_io_pool;
556 atomic_t els_io_alloc_failed_count;
557
558
559 bool hold_frames;
560
561 spinlock_t pend_frames_lock;
562 struct list_head pend_frames;
563
564 u32 pend_frames_processed;
565
566};
567
568
569
570
571int efcport_init(struct efc *efc);
572void efcport_destroy(struct efc *efc);
573
574
575
576int efc_domain_cb(void *arg, int event, void *data);
577void
578efc_register_domain_free_cb(struct efc *efc,
579 void (*callback)(struct efc *efc, void *arg),
580 void *arg);
581
582
583
584
585void efc_nport_cb(void *arg, int event, void *data);
586struct efc_vport *
587efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
588 bool enable_ini, bool enable_tgt,
589 void *tgt_data, void *ini_data);
590int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
591 u64 wwnn, u32 fc_id, bool ini, bool tgt,
592 void *tgt_data, void *ini_data);
593int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
594 u64 wwpn, u64 wwnn);
595
596void efc_vport_del_all(struct efc *efc);
597
598
599
600
601int efc_remote_node_cb(void *arg, int event, void *data);
602void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
603void efc_node_post_shutdown(struct efc_node *node, void *arg);
604u64 efc_node_get_wwpn(struct efc_node *node);
605
606
607
608
609void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
610void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
611 u32 ext_status);
612
613
614
615
616void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
617void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
618void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
619void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
620
621#endif
622