1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
8 * Functions to build and send ELS/CT/BLS commands and responses.
13 #include "../libefc_sli/sli4.h"
15 #define EFC_LOG_ENABLE_ELS_TRACE(efc) \
16 (((efc) != NULL) ? (((efc)->logmask & (1U << 1)) != 0) : 0)
18 #define node_els_trace() \
20 if (EFC_LOG_ENABLE_ELS_TRACE(efc)) \
21 efc_log_info(efc, "[%s] %-20s\n", \
22 node->display_name, __func__); \
25 #define els_io_printf(els, fmt, ...) \
26 efc_log_err((struct efc *)els->node->efc,\
28 els->node->display_name,\
29 els->display_name, ##__VA_ARGS__)
31 #define EFC_ELS_RSP_LEN 1024
32 #define EFC_ELS_GID_PT_RSP_LEN 8096
34 struct efc_els_io_req *
35 efc_els_io_alloc(struct efc_node *node, u32 reqlen)
37 return efc_els_io_alloc_size(node, reqlen, EFC_ELS_RSP_LEN);
40 struct efc_els_io_req *
41 efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen)
44 struct efc_els_io_req *els;
45 unsigned long flags = 0;
49 if (!node->els_io_enabled) {
50 efc_log_err(efc, "els io alloc disabled\n");
54 els = mempool_alloc(efc->els_io_pool, GFP_ATOMIC);
56 atomic_add_return(1, &efc->els_io_alloc_failed_count);
60 /* initialize refcount */
62 els->release = _efc_els_io_free;
64 /* populate generic io fields */
67 /* now allocate DMA for request and response */
68 els->io.req.size = reqlen;
69 els->io.req.virt = dma_alloc_coherent(&efc->pci->dev, els->io.req.size,
70 &els->io.req.phys, GFP_KERNEL);
71 if (!els->io.req.virt) {
72 mempool_free(els, efc->els_io_pool);
76 els->io.rsp.size = rsplen;
77 els->io.rsp.virt = dma_alloc_coherent(&efc->pci->dev, els->io.rsp.size,
78 &els->io.rsp.phys, GFP_KERNEL);
79 if (!els->io.rsp.virt) {
80 dma_free_coherent(&efc->pci->dev, els->io.req.size,
81 els->io.req.virt, els->io.req.phys);
82 mempool_free(els, efc->els_io_pool);
87 /* initialize fields */
88 els->els_retries_remaining = EFC_FC_ELS_DEFAULT_RETRIES;
90 /* add els structure to ELS IO list */
91 INIT_LIST_HEAD(&els->list_entry);
92 spin_lock_irqsave(&node->els_ios_lock, flags);
93 list_add_tail(&els->list_entry, &node->els_ios_list);
94 spin_unlock_irqrestore(&node->els_ios_lock, flags);
101 efc_els_io_free(struct efc_els_io_req *els)
103 kref_put(&els->ref, els->release);
107 _efc_els_io_free(struct kref *arg)
109 struct efc_els_io_req *els =
110 container_of(arg, struct efc_els_io_req, ref);
112 struct efc_node *node;
113 int send_empty_event = false;
114 unsigned long flags = 0;
119 spin_lock_irqsave(&node->els_ios_lock, flags);
121 list_del(&els->list_entry);
122 /* Send list empty event if the IO allocator
123 * is disabled, and the list is empty
124 * If node->els_io_enabled was not checked,
125 * the event would be posted continually
127 send_empty_event = (!node->els_io_enabled &&
128 list_empty(&node->els_ios_list));
130 spin_unlock_irqrestore(&node->els_ios_lock, flags);
132 /* free ELS request and response buffers */
133 dma_free_coherent(&efc->pci->dev, els->io.rsp.size,
134 els->io.rsp.virt, els->io.rsp.phys);
135 dma_free_coherent(&efc->pci->dev, els->io.req.size,
136 els->io.req.virt, els->io.req.phys);
138 mempool_free(els, efc->els_io_pool);
140 if (send_empty_event)
141 efc_scsi_io_list_empty(node->efc, node);
145 efc_els_retry(struct efc_els_io_req *els);
148 efc_els_delay_timer_cb(struct timer_list *t)
150 struct efc_els_io_req *els = from_timer(els, t, delay_timer);
152 /* Retry delay timer expired, retry the ELS request */
157 efc_els_req_cb(void *arg, u32 length, int status, u32 ext_status)
159 struct efc_els_io_req *els;
160 struct efc_node *node;
162 struct efc_node_cb cbdata;
170 els_io_printf(els, "status x%x ext x%x\n", status, ext_status);
172 /* set the response len element of els->rsp */
173 els->io.rsp.len = length;
175 cbdata.status = status;
176 cbdata.ext_status = ext_status;
177 cbdata.header = NULL;
178 cbdata.els_rsp = els->io.rsp;
180 /* set the response len element of els->rsp */
181 cbdata.rsp_len = length;
183 /* FW returns the number of bytes received on the link in
184 * the WCQE, not the amount placed in the buffer; use this info to
185 * check if there was an overrun.
187 if (length > els->io.rsp.size) {
189 "ELS response returned len=%d > buflen=%zu\n",
190 length, els->io.rsp.size);
191 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
195 /* Post event to ELS IO object */
197 case SLI4_FC_WCQE_STATUS_SUCCESS:
198 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_OK, &cbdata);
201 case SLI4_FC_WCQE_STATUS_LS_RJT:
202 reason_code = (ext_status >> 16) & 0xff;
204 /* delay and retry if reason code is Logical Busy */
205 switch (reason_code) {
207 els->node->els_req_cnt--;
209 "LS_RJT Logical Busy, delay and retry\n");
210 timer_setup(&els->delay_timer,
211 efc_els_delay_timer_cb, 0);
212 mod_timer(&els->delay_timer,
213 jiffies + msecs_to_jiffies(5000));
216 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_RJT,
222 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
223 switch (ext_status) {
224 case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT:
228 efc_log_err(efc, "LOCAL_REJECT with ext status:%x\n",
230 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL,
235 default: /* Other error */
236 efc_log_warn(efc, "els req failed status x%x, ext_status x%x\n",
238 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
245 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
248 struct efc_els_io_req *els =
249 container_of(io, struct efc_els_io_req, io);
251 WARN_ON_ONCE(!els->cb);
253 ((efc_hw_srrs_cb_t)els->cb) (els, len, status, ext_status);
256 static int efc_els_send_req(struct efc_node *node, struct efc_els_io_req *els,
257 enum efc_disc_io_type io_type)
260 struct efc *efc = node->efc;
261 struct efc_node_cb cbdata;
263 /* update ELS request counter */
264 els->node->els_req_cnt++;
266 /* Prepare the IO request details */
267 els->io.io_type = io_type;
268 els->io.xmit_len = els->io.req.size;
269 els->io.rsp_len = els->io.rsp.size;
270 els->io.rpi = node->rnode.indicator;
271 els->io.vpi = node->nport->indicator;
272 els->io.s_id = node->nport->fc_id;
273 els->io.d_id = node->rnode.fc_id;
275 if (node->rnode.attached)
276 els->io.rpi_registered = true;
278 els->cb = efc_els_req_cb;
280 rc = efc->tt.send_els(efc, &els->io);
284 cbdata.status = EFC_STATUS_INVALID;
285 cbdata.ext_status = EFC_STATUS_INVALID;
286 cbdata.els_rsp = els->io.rsp;
287 efc_log_err(efc, "efc_els_send failed: %d\n", rc);
288 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
294 efc_els_retry(struct efc_els_io_req *els)
297 struct efc_node_cb cbdata;
300 efc = els->node->efc;
301 cbdata.status = EFC_STATUS_INVALID;
302 cbdata.ext_status = EFC_STATUS_INVALID;
303 cbdata.els_rsp = els->io.rsp;
305 if (els->els_retries_remaining) {
306 els->els_retries_remaining--;
307 rc = efc->tt.send_els(efc, &els->io);
313 efc_log_err(efc, "ELS retries exhausted\n");
314 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
319 efc_els_acc_cb(void *arg, u32 length, int status, u32 ext_status)
321 struct efc_els_io_req *els;
322 struct efc_node *node;
324 struct efc_node_cb cbdata;
330 cbdata.status = status;
331 cbdata.ext_status = ext_status;
332 cbdata.header = NULL;
333 cbdata.els_rsp = els->io.rsp;
335 /* Post node event */
337 case SLI4_FC_WCQE_STATUS_SUCCESS:
338 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_OK, &cbdata);
341 default: /* Other error */
342 efc_log_warn(efc, "[%s] %-8s failed status x%x, ext x%x\n",
343 node->display_name, els->display_name,
345 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
353 efc_els_send_rsp(struct efc_els_io_req *els, u32 rsplen)
356 struct efc_node_cb cbdata;
357 struct efc_node *node = els->node;
358 struct efc *efc = node->efc;
360 /* increment ELS completion counter */
361 node->els_cmpl_cnt++;
363 els->io.io_type = EFC_DISC_IO_ELS_RESP;
364 els->cb = efc_els_acc_cb;
366 /* Prepare the IO request details */
367 els->io.xmit_len = rsplen;
368 els->io.rsp_len = els->io.rsp.size;
369 els->io.rpi = node->rnode.indicator;
370 els->io.vpi = node->nport->indicator;
371 if (node->nport->fc_id != U32_MAX)
372 els->io.s_id = node->nport->fc_id;
374 els->io.s_id = els->io.iparam.els.s_id;
375 els->io.d_id = node->rnode.fc_id;
378 els->io.rpi_registered = true;
380 rc = efc->tt.send_els(efc, &els->io);
384 cbdata.status = EFC_STATUS_INVALID;
385 cbdata.ext_status = EFC_STATUS_INVALID;
386 cbdata.els_rsp = els->io.rsp;
387 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
393 efc_send_plogi(struct efc_node *node)
395 struct efc_els_io_req *els;
396 struct efc *efc = node->efc;
397 struct fc_els_flogi *plogi;
401 els = efc_els_io_alloc(node, sizeof(*plogi));
403 efc_log_err(efc, "IO alloc failed\n");
406 els->display_name = "plogi";
408 /* Build PLOGI request */
409 plogi = els->io.req.virt;
411 memcpy(plogi, node->nport->service_params, sizeof(*plogi));
413 plogi->fl_cmd = ELS_PLOGI;
414 memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
416 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
420 efc_send_flogi(struct efc_node *node)
422 struct efc_els_io_req *els;
424 struct fc_els_flogi *flogi;
430 els = efc_els_io_alloc(node, sizeof(*flogi));
432 efc_log_err(efc, "IO alloc failed\n");
436 els->display_name = "flogi";
438 /* Build FLOGI request */
439 flogi = els->io.req.virt;
441 memcpy(flogi, node->nport->service_params, sizeof(*flogi));
442 flogi->fl_cmd = ELS_FLOGI;
443 memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
445 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
449 efc_send_fdisc(struct efc_node *node)
451 struct efc_els_io_req *els;
453 struct fc_els_flogi *fdisc;
459 els = efc_els_io_alloc(node, sizeof(*fdisc));
461 efc_log_err(efc, "IO alloc failed\n");
465 els->display_name = "fdisc";
467 /* Build FDISC request */
468 fdisc = els->io.req.virt;
470 memcpy(fdisc, node->nport->service_params, sizeof(*fdisc));
471 fdisc->fl_cmd = ELS_FDISC;
472 memset(fdisc->_fl_resvd, 0, sizeof(fdisc->_fl_resvd));
474 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
478 efc_send_prli(struct efc_node *node)
480 struct efc *efc = node->efc;
481 struct efc_els_io_req *els;
483 struct fc_els_prli prli;
484 struct fc_els_spp spp;
489 els = efc_els_io_alloc(node, sizeof(*pp));
491 efc_log_err(efc, "IO alloc failed\n");
495 els->display_name = "prli";
497 /* Build PRLI request */
498 pp = els->io.req.virt;
500 memset(pp, 0, sizeof(*pp));
502 pp->prli.prli_cmd = ELS_PRLI;
503 pp->prli.prli_spp_len = 16;
504 pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
505 pp->spp.spp_type = FC_TYPE_FCP;
506 pp->spp.spp_type_ext = 0;
507 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
508 pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
509 (node->nport->enable_ini ?
510 FCP_SPPF_INIT_FCN : 0) |
511 (node->nport->enable_tgt ?
512 FCP_SPPF_TARG_FCN : 0));
514 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
518 efc_send_logo(struct efc_node *node)
520 struct efc *efc = node->efc;
521 struct efc_els_io_req *els;
522 struct fc_els_logo *logo;
523 struct fc_els_flogi *sparams;
527 sparams = (struct fc_els_flogi *)node->nport->service_params;
529 els = efc_els_io_alloc(node, sizeof(*logo));
531 efc_log_err(efc, "IO alloc failed\n");
535 els->display_name = "logo";
537 /* Build LOGO request */
539 logo = els->io.req.virt;
541 memset(logo, 0, sizeof(*logo));
542 logo->fl_cmd = ELS_LOGO;
543 hton24(logo->fl_n_port_id, node->rnode.nport->fc_id);
544 logo->fl_n_port_wwn = sparams->fl_wwpn;
546 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
550 efc_send_adisc(struct efc_node *node)
552 struct efc *efc = node->efc;
553 struct efc_els_io_req *els;
554 struct fc_els_adisc *adisc;
555 struct fc_els_flogi *sparams;
556 struct efc_nport *nport = node->nport;
560 sparams = (struct fc_els_flogi *)node->nport->service_params;
562 els = efc_els_io_alloc(node, sizeof(*adisc));
564 efc_log_err(efc, "IO alloc failed\n");
568 els->display_name = "adisc";
570 /* Build ADISC request */
572 adisc = els->io.req.virt;
574 memset(adisc, 0, sizeof(*adisc));
575 adisc->adisc_cmd = ELS_ADISC;
576 hton24(adisc->adisc_hard_addr, nport->fc_id);
577 adisc->adisc_wwpn = sparams->fl_wwpn;
578 adisc->adisc_wwnn = sparams->fl_wwnn;
579 hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
581 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
585 efc_send_scr(struct efc_node *node)
587 struct efc_els_io_req *els;
588 struct efc *efc = node->efc;
589 struct fc_els_scr *req;
593 els = efc_els_io_alloc(node, sizeof(*req));
595 efc_log_err(efc, "IO alloc failed\n");
599 els->display_name = "scr";
601 req = els->io.req.virt;
603 memset(req, 0, sizeof(*req));
604 req->scr_cmd = ELS_SCR;
605 req->scr_reg_func = ELS_SCRF_FULL;
607 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
611 efc_send_ls_rjt(struct efc_node *node, u32 ox_id, u32 reason_code,
612 u32 reason_code_expl, u32 vendor_unique)
614 struct efc *efc = node->efc;
615 struct efc_els_io_req *els = NULL;
616 struct fc_els_ls_rjt *rjt;
618 els = efc_els_io_alloc(node, sizeof(*rjt));
620 efc_log_err(efc, "els IO alloc failed\n");
626 els->display_name = "ls_rjt";
628 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
629 els->io.iparam.els.ox_id = ox_id;
631 rjt = els->io.req.virt;
632 memset(rjt, 0, sizeof(*rjt));
634 rjt->er_cmd = ELS_LS_RJT;
635 rjt->er_reason = reason_code;
636 rjt->er_explan = reason_code_expl;
638 return efc_els_send_rsp(els, sizeof(*rjt));
642 efc_send_plogi_acc(struct efc_node *node, u32 ox_id)
644 struct efc *efc = node->efc;
645 struct efc_els_io_req *els = NULL;
646 struct fc_els_flogi *plogi;
647 struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params;
651 els = efc_els_io_alloc(node, sizeof(*plogi));
653 efc_log_err(efc, "els IO alloc failed\n");
657 els->display_name = "plogi_acc";
659 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
660 els->io.iparam.els.ox_id = ox_id;
662 plogi = els->io.req.virt;
664 /* copy our port's service parameters to payload */
665 memcpy(plogi, node->nport->service_params, sizeof(*plogi));
666 plogi->fl_cmd = ELS_LS_ACC;
667 memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
669 /* Set Application header support bit if requested */
670 if (req->fl_csp.sp_features & cpu_to_be16(FC_SP_FT_BCAST))
671 plogi->fl_csp.sp_features |= cpu_to_be16(FC_SP_FT_BCAST);
673 return efc_els_send_rsp(els, sizeof(*plogi));
677 efc_send_flogi_p2p_acc(struct efc_node *node, u32 ox_id, u32 s_id)
679 struct efc *efc = node->efc;
680 struct efc_els_io_req *els = NULL;
681 struct fc_els_flogi *flogi;
685 els = efc_els_io_alloc(node, sizeof(*flogi));
687 efc_log_err(efc, "els IO alloc failed\n");
691 els->display_name = "flogi_p2p_acc";
693 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
694 els->io.iparam.els.ox_id = ox_id;
695 els->io.iparam.els.s_id = s_id;
697 flogi = els->io.req.virt;
699 /* copy our port's service parameters to payload */
700 memcpy(flogi, node->nport->service_params, sizeof(*flogi));
701 flogi->fl_cmd = ELS_LS_ACC;
702 memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
704 memset(flogi->fl_cssp, 0, sizeof(flogi->fl_cssp));
706 return efc_els_send_rsp(els, sizeof(*flogi));
710 efc_send_prli_acc(struct efc_node *node, u32 ox_id)
712 struct efc *efc = node->efc;
713 struct efc_els_io_req *els = NULL;
715 struct fc_els_prli prli;
716 struct fc_els_spp spp;
721 els = efc_els_io_alloc(node, sizeof(*pp));
723 efc_log_err(efc, "els IO alloc failed\n");
727 els->display_name = "prli_acc";
729 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
730 els->io.iparam.els.ox_id = ox_id;
732 pp = els->io.req.virt;
733 memset(pp, 0, sizeof(*pp));
735 pp->prli.prli_cmd = ELS_LS_ACC;
736 pp->prli.prli_spp_len = 0x10;
737 pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
738 pp->spp.spp_type = FC_TYPE_FCP;
739 pp->spp.spp_type_ext = 0;
740 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR | FC_SPP_RESP_ACK;
742 pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
743 (node->nport->enable_ini ?
744 FCP_SPPF_INIT_FCN : 0) |
745 (node->nport->enable_tgt ?
746 FCP_SPPF_TARG_FCN : 0));
748 return efc_els_send_rsp(els, sizeof(*pp));
752 efc_send_prlo_acc(struct efc_node *node, u32 ox_id)
754 struct efc *efc = node->efc;
755 struct efc_els_io_req *els = NULL;
757 struct fc_els_prlo prlo;
758 struct fc_els_spp spp;
763 els = efc_els_io_alloc(node, sizeof(*pp));
765 efc_log_err(efc, "els IO alloc failed\n");
769 els->display_name = "prlo_acc";
771 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
772 els->io.iparam.els.ox_id = ox_id;
774 pp = els->io.req.virt;
775 memset(pp, 0, sizeof(*pp));
776 pp->prlo.prlo_cmd = ELS_LS_ACC;
777 pp->prlo.prlo_obs = 0x10;
778 pp->prlo.prlo_len = cpu_to_be16(sizeof(*pp));
780 pp->spp.spp_type = FC_TYPE_FCP;
781 pp->spp.spp_type_ext = 0;
782 pp->spp.spp_flags = FC_SPP_RESP_ACK;
784 return efc_els_send_rsp(els, sizeof(*pp));
788 efc_send_ls_acc(struct efc_node *node, u32 ox_id)
790 struct efc *efc = node->efc;
791 struct efc_els_io_req *els = NULL;
792 struct fc_els_ls_acc *acc;
796 els = efc_els_io_alloc(node, sizeof(*acc));
798 efc_log_err(efc, "els IO alloc failed\n");
802 els->display_name = "ls_acc";
804 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
805 els->io.iparam.els.ox_id = ox_id;
807 acc = els->io.req.virt;
808 memset(acc, 0, sizeof(*acc));
810 acc->la_cmd = ELS_LS_ACC;
812 return efc_els_send_rsp(els, sizeof(*acc));
816 efc_send_logo_acc(struct efc_node *node, u32 ox_id)
818 struct efc_els_io_req *els = NULL;
819 struct efc *efc = node->efc;
820 struct fc_els_ls_acc *logo;
824 els = efc_els_io_alloc(node, sizeof(*logo));
826 efc_log_err(efc, "els IO alloc failed\n");
830 els->display_name = "logo_acc";
832 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
833 els->io.iparam.els.ox_id = ox_id;
835 logo = els->io.req.virt;
836 memset(logo, 0, sizeof(*logo));
838 logo->la_cmd = ELS_LS_ACC;
840 return efc_els_send_rsp(els, sizeof(*logo));
844 efc_send_adisc_acc(struct efc_node *node, u32 ox_id)
846 struct efc *efc = node->efc;
847 struct efc_els_io_req *els = NULL;
848 struct fc_els_adisc *adisc;
849 struct fc_els_flogi *sparams;
853 els = efc_els_io_alloc(node, sizeof(*adisc));
855 efc_log_err(efc, "els IO alloc failed\n");
859 els->display_name = "adisc_acc";
861 /* Go ahead and send the ELS_ACC */
862 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
863 els->io.iparam.els.ox_id = ox_id;
865 sparams = (struct fc_els_flogi *)node->nport->service_params;
866 adisc = els->io.req.virt;
867 memset(adisc, 0, sizeof(*adisc));
868 adisc->adisc_cmd = ELS_LS_ACC;
869 adisc->adisc_wwpn = sparams->fl_wwpn;
870 adisc->adisc_wwnn = sparams->fl_wwnn;
871 hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
873 return efc_els_send_rsp(els, sizeof(*adisc));
877 fcct_build_req_header(struct fc_ct_hdr *hdr, u16 cmd, u16 max_size)
879 hdr->ct_rev = FC_CT_REV;
880 hdr->ct_fs_type = FC_FST_DIR;
881 hdr->ct_fs_subtype = FC_NS_SUBTYPE;
883 hdr->ct_cmd = cpu_to_be16(cmd);
885 hdr->ct_mr_size = cpu_to_be16(max_size / (sizeof(u32)));
892 efc_ns_send_rftid(struct efc_node *node)
894 struct efc *efc = node->efc;
895 struct efc_els_io_req *els;
897 struct fc_ct_hdr hdr;
898 struct fc_ns_rft_id rftid;
903 els = efc_els_io_alloc(node, sizeof(*ct));
905 efc_log_err(efc, "IO alloc failed\n");
909 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
910 els->io.iparam.ct.type = FC_TYPE_CT;
911 els->io.iparam.ct.df_ctl = 0;
912 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
914 els->display_name = "rftid";
916 ct = els->io.req.virt;
917 memset(ct, 0, sizeof(*ct));
918 fcct_build_req_header(&ct->hdr, FC_NS_RFT_ID,
919 sizeof(struct fc_ns_rft_id));
921 hton24(ct->rftid.fr_fid.fp_fid, node->rnode.nport->fc_id);
922 ct->rftid.fr_fts.ff_type_map[FC_TYPE_FCP / FC_NS_BPW] =
923 cpu_to_be32(1 << (FC_TYPE_FCP % FC_NS_BPW));
925 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
929 efc_ns_send_rffid(struct efc_node *node)
931 struct efc *efc = node->efc;
932 struct efc_els_io_req *els;
934 struct fc_ct_hdr hdr;
935 struct fc_ns_rff_id rffid;
940 els = efc_els_io_alloc(node, sizeof(*ct));
942 efc_log_err(efc, "IO alloc failed\n");
946 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
947 els->io.iparam.ct.type = FC_TYPE_CT;
948 els->io.iparam.ct.df_ctl = 0;
949 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
951 els->display_name = "rffid";
952 ct = els->io.req.virt;
954 memset(ct, 0, sizeof(*ct));
955 fcct_build_req_header(&ct->hdr, FC_NS_RFF_ID,
956 sizeof(struct fc_ns_rff_id));
958 hton24(ct->rffid.fr_fid.fp_fid, node->rnode.nport->fc_id);
959 if (node->nport->enable_ini)
960 ct->rffid.fr_feat |= FCP_FEAT_INIT;
961 if (node->nport->enable_tgt)
962 ct->rffid.fr_feat |= FCP_FEAT_TARG;
963 ct->rffid.fr_type = FC_TYPE_FCP;
965 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
969 efc_ns_send_gidpt(struct efc_node *node)
971 struct efc_els_io_req *els = NULL;
972 struct efc *efc = node->efc;
974 struct fc_ct_hdr hdr;
975 struct fc_ns_gid_pt gidpt;
980 els = efc_els_io_alloc_size(node, sizeof(*ct), EFC_ELS_GID_PT_RSP_LEN);
982 efc_log_err(efc, "IO alloc failed\n");
986 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
987 els->io.iparam.ct.type = FC_TYPE_CT;
988 els->io.iparam.ct.df_ctl = 0;
989 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
991 els->display_name = "gidpt";
993 ct = els->io.req.virt;
995 memset(ct, 0, sizeof(*ct));
996 fcct_build_req_header(&ct->hdr, FC_NS_GID_PT,
997 sizeof(struct fc_ns_gid_pt));
999 ct->gidpt.fn_pt_type = FC_TYPE_FCP;
1001 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
1005 efc_els_io_cleanup(struct efc_els_io_req *els, int evt, void *arg)
1007 /* don't want further events that could come; e.g. abort requests
1008 * from the node state machine; thus, disable state machine
1010 els->els_req_free = true;
1011 efc_node_post_els_resp(els->node, evt, arg);
1013 efc_els_io_free(els);
1017 efc_ct_acc_cb(void *arg, u32 length, int status, u32 ext_status)
1019 struct efc_els_io_req *els = arg;
1021 efc_els_io_free(els);
1027 efc_send_ct_rsp(struct efc *efc, struct efc_node *node, u16 ox_id,
1028 struct fc_ct_hdr *ct_hdr, u32 cmd_rsp_code,
1029 u32 reason_code, u32 reason_code_explanation)
1031 struct efc_els_io_req *els = NULL;
1032 struct fc_ct_hdr *rsp = NULL;
1034 els = efc_els_io_alloc(node, 256);
1036 efc_log_err(efc, "IO alloc failed\n");
1040 rsp = els->io.rsp.virt;
1044 fcct_build_req_header(rsp, cmd_rsp_code, 0);
1045 rsp->ct_reason = reason_code;
1046 rsp->ct_explan = reason_code_explanation;
1048 els->display_name = "ct_rsp";
1049 els->cb = efc_ct_acc_cb;
1051 /* Prepare the IO request details */
1052 els->io.io_type = EFC_DISC_IO_CT_RESP;
1053 els->io.xmit_len = sizeof(*rsp);
1055 els->io.rpi = node->rnode.indicator;
1056 els->io.d_id = node->rnode.fc_id;
1058 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
1060 els->io.iparam.ct.ox_id = ox_id;
1061 els->io.iparam.ct.r_ctl = 3;
1062 els->io.iparam.ct.type = FC_TYPE_CT;
1063 els->io.iparam.ct.df_ctl = 0;
1064 els->io.iparam.ct.timeout = 5;
1066 if (efc->tt.send_els(efc, &els->io)) {
1067 efc_els_io_free(els);
1074 efc_send_bls_acc(struct efc_node *node, struct fc_frame_header *hdr)
1076 struct sli_bls_params bls;
1077 struct fc_ba_acc *acc;
1078 struct efc *efc = node->efc;
1080 memset(&bls, 0, sizeof(bls));
1081 bls.ox_id = be16_to_cpu(hdr->fh_ox_id);
1082 bls.rx_id = be16_to_cpu(hdr->fh_rx_id);
1083 bls.s_id = ntoh24(hdr->fh_d_id);
1084 bls.d_id = node->rnode.fc_id;
1085 bls.rpi = node->rnode.indicator;
1086 bls.vpi = node->nport->indicator;
1088 acc = (void *)bls.payload;
1089 acc->ba_ox_id = cpu_to_be16(bls.ox_id);
1090 acc->ba_rx_id = cpu_to_be16(bls.rx_id);
1091 acc->ba_high_seq_cnt = cpu_to_be16(U16_MAX);
1093 return efc->tt.send_bls(efc, FC_RCTL_BA_ACC, &bls);