0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "efc.h"
0012 #include "efc_els.h"
0013 #include "../libefc_sli/sli4.h"
0014
0015 #define EFC_LOG_ENABLE_ELS_TRACE(efc) \
0016 (((efc) != NULL) ? (((efc)->logmask & (1U << 1)) != 0) : 0)
0017
0018 #define node_els_trace() \
0019 do { \
0020 if (EFC_LOG_ENABLE_ELS_TRACE(efc)) \
0021 efc_log_info(efc, "[%s] %-20s\n", \
0022 node->display_name, __func__); \
0023 } while (0)
0024
0025 #define els_io_printf(els, fmt, ...) \
0026 efc_log_err((struct efc *)els->node->efc,\
0027 "[%s] %-8s " fmt, \
0028 els->node->display_name,\
0029 els->display_name, ##__VA_ARGS__)
0030
0031 #define EFC_ELS_RSP_LEN 1024
0032 #define EFC_ELS_GID_PT_RSP_LEN 8096
0033
0034 struct efc_els_io_req *
0035 efc_els_io_alloc(struct efc_node *node, u32 reqlen)
0036 {
0037 return efc_els_io_alloc_size(node, reqlen, EFC_ELS_RSP_LEN);
0038 }
0039
0040 struct efc_els_io_req *
0041 efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen)
0042 {
0043 struct efc *efc;
0044 struct efc_els_io_req *els;
0045 unsigned long flags = 0;
0046
0047 efc = node->efc;
0048
0049 if (!node->els_io_enabled) {
0050 efc_log_err(efc, "els io alloc disabled\n");
0051 return NULL;
0052 }
0053
0054 els = mempool_alloc(efc->els_io_pool, GFP_ATOMIC);
0055 if (!els) {
0056 atomic_add_return(1, &efc->els_io_alloc_failed_count);
0057 return NULL;
0058 }
0059
0060
0061 kref_init(&els->ref);
0062 els->release = _efc_els_io_free;
0063
0064
0065 els->node = node;
0066
0067
0068 els->io.req.size = reqlen;
0069 els->io.req.virt = dma_alloc_coherent(&efc->pci->dev, els->io.req.size,
0070 &els->io.req.phys, GFP_KERNEL);
0071 if (!els->io.req.virt) {
0072 mempool_free(els, efc->els_io_pool);
0073 return NULL;
0074 }
0075
0076 els->io.rsp.size = rsplen;
0077 els->io.rsp.virt = dma_alloc_coherent(&efc->pci->dev, els->io.rsp.size,
0078 &els->io.rsp.phys, GFP_KERNEL);
0079 if (!els->io.rsp.virt) {
0080 dma_free_coherent(&efc->pci->dev, els->io.req.size,
0081 els->io.req.virt, els->io.req.phys);
0082 mempool_free(els, efc->els_io_pool);
0083 els = NULL;
0084 }
0085
0086 if (els) {
0087
0088 els->els_retries_remaining = EFC_FC_ELS_DEFAULT_RETRIES;
0089
0090
0091 INIT_LIST_HEAD(&els->list_entry);
0092 spin_lock_irqsave(&node->els_ios_lock, flags);
0093 list_add_tail(&els->list_entry, &node->els_ios_list);
0094 spin_unlock_irqrestore(&node->els_ios_lock, flags);
0095 }
0096
0097 return els;
0098 }
0099
0100 void
0101 efc_els_io_free(struct efc_els_io_req *els)
0102 {
0103 kref_put(&els->ref, els->release);
0104 }
0105
0106 void
0107 _efc_els_io_free(struct kref *arg)
0108 {
0109 struct efc_els_io_req *els =
0110 container_of(arg, struct efc_els_io_req, ref);
0111 struct efc *efc;
0112 struct efc_node *node;
0113 int send_empty_event = false;
0114 unsigned long flags = 0;
0115
0116 node = els->node;
0117 efc = node->efc;
0118
0119 spin_lock_irqsave(&node->els_ios_lock, flags);
0120
0121 list_del(&els->list_entry);
0122
0123
0124
0125
0126
0127 send_empty_event = (!node->els_io_enabled &&
0128 list_empty(&node->els_ios_list));
0129
0130 spin_unlock_irqrestore(&node->els_ios_lock, flags);
0131
0132
0133 dma_free_coherent(&efc->pci->dev, els->io.rsp.size,
0134 els->io.rsp.virt, els->io.rsp.phys);
0135 dma_free_coherent(&efc->pci->dev, els->io.req.size,
0136 els->io.req.virt, els->io.req.phys);
0137
0138 mempool_free(els, efc->els_io_pool);
0139
0140 if (send_empty_event)
0141 efc_scsi_io_list_empty(node->efc, node);
0142 }
0143
0144 static void
0145 efc_els_retry(struct efc_els_io_req *els);
0146
0147 static void
0148 efc_els_delay_timer_cb(struct timer_list *t)
0149 {
0150 struct efc_els_io_req *els = from_timer(els, t, delay_timer);
0151
0152
0153 efc_els_retry(els);
0154 }
0155
0156 static int
0157 efc_els_req_cb(void *arg, u32 length, int status, u32 ext_status)
0158 {
0159 struct efc_els_io_req *els;
0160 struct efc_node *node;
0161 struct efc *efc;
0162 struct efc_node_cb cbdata;
0163 u32 reason_code;
0164
0165 els = arg;
0166 node = els->node;
0167 efc = node->efc;
0168
0169 if (status)
0170 els_io_printf(els, "status x%x ext x%x\n", status, ext_status);
0171
0172
0173 els->io.rsp.len = length;
0174
0175 cbdata.status = status;
0176 cbdata.ext_status = ext_status;
0177 cbdata.header = NULL;
0178 cbdata.els_rsp = els->io.rsp;
0179
0180
0181 cbdata.rsp_len = length;
0182
0183
0184
0185
0186
0187 if (length > els->io.rsp.size) {
0188 efc_log_warn(efc,
0189 "ELS response returned len=%d > buflen=%zu\n",
0190 length, els->io.rsp.size);
0191 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
0192 return 0;
0193 }
0194
0195
0196 switch (status) {
0197 case SLI4_FC_WCQE_STATUS_SUCCESS:
0198 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_OK, &cbdata);
0199 break;
0200
0201 case SLI4_FC_WCQE_STATUS_LS_RJT:
0202 reason_code = (ext_status >> 16) & 0xff;
0203
0204
0205 switch (reason_code) {
0206 case ELS_RJT_BUSY:
0207 els->node->els_req_cnt--;
0208 els_io_printf(els,
0209 "LS_RJT Logical Busy, delay and retry\n");
0210 timer_setup(&els->delay_timer,
0211 efc_els_delay_timer_cb, 0);
0212 mod_timer(&els->delay_timer,
0213 jiffies + msecs_to_jiffies(5000));
0214 break;
0215 default:
0216 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_RJT,
0217 &cbdata);
0218 break;
0219 }
0220 break;
0221
0222 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
0223 switch (ext_status) {
0224 case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT:
0225 efc_els_retry(els);
0226 break;
0227 default:
0228 efc_log_err(efc, "LOCAL_REJECT with ext status:%x\n",
0229 ext_status);
0230 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL,
0231 &cbdata);
0232 break;
0233 }
0234 break;
0235 default:
0236 efc_log_warn(efc, "els req failed status x%x, ext_status x%x\n",
0237 status, ext_status);
0238 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
0239 break;
0240 }
0241
0242 return 0;
0243 }
0244
0245 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
0246 u32 ext_status)
0247 {
0248 struct efc_els_io_req *els =
0249 container_of(io, struct efc_els_io_req, io);
0250
0251 WARN_ON_ONCE(!els->cb);
0252
0253 ((efc_hw_srrs_cb_t)els->cb) (els, len, status, ext_status);
0254 }
0255
0256 static int efc_els_send_req(struct efc_node *node, struct efc_els_io_req *els,
0257 enum efc_disc_io_type io_type)
0258 {
0259 int rc = 0;
0260 struct efc *efc = node->efc;
0261 struct efc_node_cb cbdata;
0262
0263
0264 els->node->els_req_cnt++;
0265
0266
0267 els->io.io_type = io_type;
0268 els->io.xmit_len = els->io.req.size;
0269 els->io.rsp_len = els->io.rsp.size;
0270 els->io.rpi = node->rnode.indicator;
0271 els->io.vpi = node->nport->indicator;
0272 els->io.s_id = node->nport->fc_id;
0273 els->io.d_id = node->rnode.fc_id;
0274
0275 if (node->rnode.attached)
0276 els->io.rpi_registered = true;
0277
0278 els->cb = efc_els_req_cb;
0279
0280 rc = efc->tt.send_els(efc, &els->io);
0281 if (!rc)
0282 return rc;
0283
0284 cbdata.status = EFC_STATUS_INVALID;
0285 cbdata.ext_status = EFC_STATUS_INVALID;
0286 cbdata.els_rsp = els->io.rsp;
0287 efc_log_err(efc, "efc_els_send failed: %d\n", rc);
0288 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
0289
0290 return rc;
0291 }
0292
0293 static void
0294 efc_els_retry(struct efc_els_io_req *els)
0295 {
0296 struct efc *efc;
0297 struct efc_node_cb cbdata;
0298 u32 rc;
0299
0300 efc = els->node->efc;
0301 cbdata.status = EFC_STATUS_INVALID;
0302 cbdata.ext_status = EFC_STATUS_INVALID;
0303 cbdata.els_rsp = els->io.rsp;
0304
0305 if (els->els_retries_remaining) {
0306 els->els_retries_remaining--;
0307 rc = efc->tt.send_els(efc, &els->io);
0308 } else {
0309 rc = -EIO;
0310 }
0311
0312 if (rc) {
0313 efc_log_err(efc, "ELS retries exhausted\n");
0314 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
0315 }
0316 }
0317
0318 static int
0319 efc_els_acc_cb(void *arg, u32 length, int status, u32 ext_status)
0320 {
0321 struct efc_els_io_req *els;
0322 struct efc_node *node;
0323 struct efc *efc;
0324 struct efc_node_cb cbdata;
0325
0326 els = arg;
0327 node = els->node;
0328 efc = node->efc;
0329
0330 cbdata.status = status;
0331 cbdata.ext_status = ext_status;
0332 cbdata.header = NULL;
0333 cbdata.els_rsp = els->io.rsp;
0334
0335
0336 switch (status) {
0337 case SLI4_FC_WCQE_STATUS_SUCCESS:
0338 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_OK, &cbdata);
0339 break;
0340
0341 default:
0342 efc_log_warn(efc, "[%s] %-8s failed status x%x, ext x%x\n",
0343 node->display_name, els->display_name,
0344 status, ext_status);
0345 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
0346 break;
0347 }
0348
0349 return 0;
0350 }
0351
0352 static int
0353 efc_els_send_rsp(struct efc_els_io_req *els, u32 rsplen)
0354 {
0355 int rc = 0;
0356 struct efc_node_cb cbdata;
0357 struct efc_node *node = els->node;
0358 struct efc *efc = node->efc;
0359
0360
0361 node->els_cmpl_cnt++;
0362
0363 els->io.io_type = EFC_DISC_IO_ELS_RESP;
0364 els->cb = efc_els_acc_cb;
0365
0366
0367 els->io.xmit_len = rsplen;
0368 els->io.rsp_len = els->io.rsp.size;
0369 els->io.rpi = node->rnode.indicator;
0370 els->io.vpi = node->nport->indicator;
0371 if (node->nport->fc_id != U32_MAX)
0372 els->io.s_id = node->nport->fc_id;
0373 else
0374 els->io.s_id = els->io.iparam.els.s_id;
0375 els->io.d_id = node->rnode.fc_id;
0376
0377 if (node->attached)
0378 els->io.rpi_registered = true;
0379
0380 rc = efc->tt.send_els(efc, &els->io);
0381 if (!rc)
0382 return rc;
0383
0384 cbdata.status = EFC_STATUS_INVALID;
0385 cbdata.ext_status = EFC_STATUS_INVALID;
0386 cbdata.els_rsp = els->io.rsp;
0387 efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
0388
0389 return rc;
0390 }
0391
0392 int
0393 efc_send_plogi(struct efc_node *node)
0394 {
0395 struct efc_els_io_req *els;
0396 struct efc *efc = node->efc;
0397 struct fc_els_flogi *plogi;
0398
0399 node_els_trace();
0400
0401 els = efc_els_io_alloc(node, sizeof(*plogi));
0402 if (!els) {
0403 efc_log_err(efc, "IO alloc failed\n");
0404 return -EIO;
0405 }
0406 els->display_name = "plogi";
0407
0408
0409 plogi = els->io.req.virt;
0410
0411 memcpy(plogi, node->nport->service_params, sizeof(*plogi));
0412
0413 plogi->fl_cmd = ELS_PLOGI;
0414 memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
0415
0416 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0417 }
0418
0419 int
0420 efc_send_flogi(struct efc_node *node)
0421 {
0422 struct efc_els_io_req *els;
0423 struct efc *efc;
0424 struct fc_els_flogi *flogi;
0425
0426 efc = node->efc;
0427
0428 node_els_trace();
0429
0430 els = efc_els_io_alloc(node, sizeof(*flogi));
0431 if (!els) {
0432 efc_log_err(efc, "IO alloc failed\n");
0433 return -EIO;
0434 }
0435
0436 els->display_name = "flogi";
0437
0438
0439 flogi = els->io.req.virt;
0440
0441 memcpy(flogi, node->nport->service_params, sizeof(*flogi));
0442 flogi->fl_cmd = ELS_FLOGI;
0443 memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
0444
0445 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0446 }
0447
0448 int
0449 efc_send_fdisc(struct efc_node *node)
0450 {
0451 struct efc_els_io_req *els;
0452 struct efc *efc;
0453 struct fc_els_flogi *fdisc;
0454
0455 efc = node->efc;
0456
0457 node_els_trace();
0458
0459 els = efc_els_io_alloc(node, sizeof(*fdisc));
0460 if (!els) {
0461 efc_log_err(efc, "IO alloc failed\n");
0462 return -EIO;
0463 }
0464
0465 els->display_name = "fdisc";
0466
0467
0468 fdisc = els->io.req.virt;
0469
0470 memcpy(fdisc, node->nport->service_params, sizeof(*fdisc));
0471 fdisc->fl_cmd = ELS_FDISC;
0472 memset(fdisc->_fl_resvd, 0, sizeof(fdisc->_fl_resvd));
0473
0474 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0475 }
0476
0477 int
0478 efc_send_prli(struct efc_node *node)
0479 {
0480 struct efc *efc = node->efc;
0481 struct efc_els_io_req *els;
0482 struct {
0483 struct fc_els_prli prli;
0484 struct fc_els_spp spp;
0485 } *pp;
0486
0487 node_els_trace();
0488
0489 els = efc_els_io_alloc(node, sizeof(*pp));
0490 if (!els) {
0491 efc_log_err(efc, "IO alloc failed\n");
0492 return -EIO;
0493 }
0494
0495 els->display_name = "prli";
0496
0497
0498 pp = els->io.req.virt;
0499
0500 memset(pp, 0, sizeof(*pp));
0501
0502 pp->prli.prli_cmd = ELS_PRLI;
0503 pp->prli.prli_spp_len = 16;
0504 pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
0505 pp->spp.spp_type = FC_TYPE_FCP;
0506 pp->spp.spp_type_ext = 0;
0507 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
0508 pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
0509 (node->nport->enable_ini ?
0510 FCP_SPPF_INIT_FCN : 0) |
0511 (node->nport->enable_tgt ?
0512 FCP_SPPF_TARG_FCN : 0));
0513
0514 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0515 }
0516
0517 int
0518 efc_send_logo(struct efc_node *node)
0519 {
0520 struct efc *efc = node->efc;
0521 struct efc_els_io_req *els;
0522 struct fc_els_logo *logo;
0523 struct fc_els_flogi *sparams;
0524
0525 node_els_trace();
0526
0527 sparams = (struct fc_els_flogi *)node->nport->service_params;
0528
0529 els = efc_els_io_alloc(node, sizeof(*logo));
0530 if (!els) {
0531 efc_log_err(efc, "IO alloc failed\n");
0532 return -EIO;
0533 }
0534
0535 els->display_name = "logo";
0536
0537
0538
0539 logo = els->io.req.virt;
0540
0541 memset(logo, 0, sizeof(*logo));
0542 logo->fl_cmd = ELS_LOGO;
0543 hton24(logo->fl_n_port_id, node->rnode.nport->fc_id);
0544 logo->fl_n_port_wwn = sparams->fl_wwpn;
0545
0546 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0547 }
0548
0549 int
0550 efc_send_adisc(struct efc_node *node)
0551 {
0552 struct efc *efc = node->efc;
0553 struct efc_els_io_req *els;
0554 struct fc_els_adisc *adisc;
0555 struct fc_els_flogi *sparams;
0556 struct efc_nport *nport = node->nport;
0557
0558 node_els_trace();
0559
0560 sparams = (struct fc_els_flogi *)node->nport->service_params;
0561
0562 els = efc_els_io_alloc(node, sizeof(*adisc));
0563 if (!els) {
0564 efc_log_err(efc, "IO alloc failed\n");
0565 return -EIO;
0566 }
0567
0568 els->display_name = "adisc";
0569
0570
0571
0572 adisc = els->io.req.virt;
0573
0574 memset(adisc, 0, sizeof(*adisc));
0575 adisc->adisc_cmd = ELS_ADISC;
0576 hton24(adisc->adisc_hard_addr, nport->fc_id);
0577 adisc->adisc_wwpn = sparams->fl_wwpn;
0578 adisc->adisc_wwnn = sparams->fl_wwnn;
0579 hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
0580
0581 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0582 }
0583
0584 int
0585 efc_send_scr(struct efc_node *node)
0586 {
0587 struct efc_els_io_req *els;
0588 struct efc *efc = node->efc;
0589 struct fc_els_scr *req;
0590
0591 node_els_trace();
0592
0593 els = efc_els_io_alloc(node, sizeof(*req));
0594 if (!els) {
0595 efc_log_err(efc, "IO alloc failed\n");
0596 return -EIO;
0597 }
0598
0599 els->display_name = "scr";
0600
0601 req = els->io.req.virt;
0602
0603 memset(req, 0, sizeof(*req));
0604 req->scr_cmd = ELS_SCR;
0605 req->scr_reg_func = ELS_SCRF_FULL;
0606
0607 return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
0608 }
0609
0610 int
0611 efc_send_ls_rjt(struct efc_node *node, u32 ox_id, u32 reason_code,
0612 u32 reason_code_expl, u32 vendor_unique)
0613 {
0614 struct efc *efc = node->efc;
0615 struct efc_els_io_req *els = NULL;
0616 struct fc_els_ls_rjt *rjt;
0617
0618 els = efc_els_io_alloc(node, sizeof(*rjt));
0619 if (!els) {
0620 efc_log_err(efc, "els IO alloc failed\n");
0621 return -EIO;
0622 }
0623
0624 node_els_trace();
0625
0626 els->display_name = "ls_rjt";
0627
0628 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0629 els->io.iparam.els.ox_id = ox_id;
0630
0631 rjt = els->io.req.virt;
0632 memset(rjt, 0, sizeof(*rjt));
0633
0634 rjt->er_cmd = ELS_LS_RJT;
0635 rjt->er_reason = reason_code;
0636 rjt->er_explan = reason_code_expl;
0637
0638 return efc_els_send_rsp(els, sizeof(*rjt));
0639 }
0640
0641 int
0642 efc_send_plogi_acc(struct efc_node *node, u32 ox_id)
0643 {
0644 struct efc *efc = node->efc;
0645 struct efc_els_io_req *els = NULL;
0646 struct fc_els_flogi *plogi;
0647 struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params;
0648
0649 node_els_trace();
0650
0651 els = efc_els_io_alloc(node, sizeof(*plogi));
0652 if (!els) {
0653 efc_log_err(efc, "els IO alloc failed\n");
0654 return -EIO;
0655 }
0656
0657 els->display_name = "plogi_acc";
0658
0659 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0660 els->io.iparam.els.ox_id = ox_id;
0661
0662 plogi = els->io.req.virt;
0663
0664
0665 memcpy(plogi, node->nport->service_params, sizeof(*plogi));
0666 plogi->fl_cmd = ELS_LS_ACC;
0667 memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
0668
0669
0670 if (req->fl_csp.sp_features & cpu_to_be16(FC_SP_FT_BCAST))
0671 plogi->fl_csp.sp_features |= cpu_to_be16(FC_SP_FT_BCAST);
0672
0673 return efc_els_send_rsp(els, sizeof(*plogi));
0674 }
0675
0676 int
0677 efc_send_flogi_p2p_acc(struct efc_node *node, u32 ox_id, u32 s_id)
0678 {
0679 struct efc *efc = node->efc;
0680 struct efc_els_io_req *els = NULL;
0681 struct fc_els_flogi *flogi;
0682
0683 node_els_trace();
0684
0685 els = efc_els_io_alloc(node, sizeof(*flogi));
0686 if (!els) {
0687 efc_log_err(efc, "els IO alloc failed\n");
0688 return -EIO;
0689 }
0690
0691 els->display_name = "flogi_p2p_acc";
0692
0693 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0694 els->io.iparam.els.ox_id = ox_id;
0695 els->io.iparam.els.s_id = s_id;
0696
0697 flogi = els->io.req.virt;
0698
0699
0700 memcpy(flogi, node->nport->service_params, sizeof(*flogi));
0701 flogi->fl_cmd = ELS_LS_ACC;
0702 memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
0703
0704 memset(flogi->fl_cssp, 0, sizeof(flogi->fl_cssp));
0705
0706 return efc_els_send_rsp(els, sizeof(*flogi));
0707 }
0708
0709 int
0710 efc_send_prli_acc(struct efc_node *node, u32 ox_id)
0711 {
0712 struct efc *efc = node->efc;
0713 struct efc_els_io_req *els = NULL;
0714 struct {
0715 struct fc_els_prli prli;
0716 struct fc_els_spp spp;
0717 } *pp;
0718
0719 node_els_trace();
0720
0721 els = efc_els_io_alloc(node, sizeof(*pp));
0722 if (!els) {
0723 efc_log_err(efc, "els IO alloc failed\n");
0724 return -EIO;
0725 }
0726
0727 els->display_name = "prli_acc";
0728
0729 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0730 els->io.iparam.els.ox_id = ox_id;
0731
0732 pp = els->io.req.virt;
0733 memset(pp, 0, sizeof(*pp));
0734
0735 pp->prli.prli_cmd = ELS_LS_ACC;
0736 pp->prli.prli_spp_len = 0x10;
0737 pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
0738 pp->spp.spp_type = FC_TYPE_FCP;
0739 pp->spp.spp_type_ext = 0;
0740 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR | FC_SPP_RESP_ACK;
0741
0742 pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
0743 (node->nport->enable_ini ?
0744 FCP_SPPF_INIT_FCN : 0) |
0745 (node->nport->enable_tgt ?
0746 FCP_SPPF_TARG_FCN : 0));
0747
0748 return efc_els_send_rsp(els, sizeof(*pp));
0749 }
0750
0751 int
0752 efc_send_prlo_acc(struct efc_node *node, u32 ox_id)
0753 {
0754 struct efc *efc = node->efc;
0755 struct efc_els_io_req *els = NULL;
0756 struct {
0757 struct fc_els_prlo prlo;
0758 struct fc_els_spp spp;
0759 } *pp;
0760
0761 node_els_trace();
0762
0763 els = efc_els_io_alloc(node, sizeof(*pp));
0764 if (!els) {
0765 efc_log_err(efc, "els IO alloc failed\n");
0766 return -EIO;
0767 }
0768
0769 els->display_name = "prlo_acc";
0770
0771 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0772 els->io.iparam.els.ox_id = ox_id;
0773
0774 pp = els->io.req.virt;
0775 memset(pp, 0, sizeof(*pp));
0776 pp->prlo.prlo_cmd = ELS_LS_ACC;
0777 pp->prlo.prlo_obs = 0x10;
0778 pp->prlo.prlo_len = cpu_to_be16(sizeof(*pp));
0779
0780 pp->spp.spp_type = FC_TYPE_FCP;
0781 pp->spp.spp_type_ext = 0;
0782 pp->spp.spp_flags = FC_SPP_RESP_ACK;
0783
0784 return efc_els_send_rsp(els, sizeof(*pp));
0785 }
0786
0787 int
0788 efc_send_ls_acc(struct efc_node *node, u32 ox_id)
0789 {
0790 struct efc *efc = node->efc;
0791 struct efc_els_io_req *els = NULL;
0792 struct fc_els_ls_acc *acc;
0793
0794 node_els_trace();
0795
0796 els = efc_els_io_alloc(node, sizeof(*acc));
0797 if (!els) {
0798 efc_log_err(efc, "els IO alloc failed\n");
0799 return -EIO;
0800 }
0801
0802 els->display_name = "ls_acc";
0803
0804 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0805 els->io.iparam.els.ox_id = ox_id;
0806
0807 acc = els->io.req.virt;
0808 memset(acc, 0, sizeof(*acc));
0809
0810 acc->la_cmd = ELS_LS_ACC;
0811
0812 return efc_els_send_rsp(els, sizeof(*acc));
0813 }
0814
0815 int
0816 efc_send_logo_acc(struct efc_node *node, u32 ox_id)
0817 {
0818 struct efc_els_io_req *els = NULL;
0819 struct efc *efc = node->efc;
0820 struct fc_els_ls_acc *logo;
0821
0822 node_els_trace();
0823
0824 els = efc_els_io_alloc(node, sizeof(*logo));
0825 if (!els) {
0826 efc_log_err(efc, "els IO alloc failed\n");
0827 return -EIO;
0828 }
0829
0830 els->display_name = "logo_acc";
0831
0832 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0833 els->io.iparam.els.ox_id = ox_id;
0834
0835 logo = els->io.req.virt;
0836 memset(logo, 0, sizeof(*logo));
0837
0838 logo->la_cmd = ELS_LS_ACC;
0839
0840 return efc_els_send_rsp(els, sizeof(*logo));
0841 }
0842
0843 int
0844 efc_send_adisc_acc(struct efc_node *node, u32 ox_id)
0845 {
0846 struct efc *efc = node->efc;
0847 struct efc_els_io_req *els = NULL;
0848 struct fc_els_adisc *adisc;
0849 struct fc_els_flogi *sparams;
0850
0851 node_els_trace();
0852
0853 els = efc_els_io_alloc(node, sizeof(*adisc));
0854 if (!els) {
0855 efc_log_err(efc, "els IO alloc failed\n");
0856 return -EIO;
0857 }
0858
0859 els->display_name = "adisc_acc";
0860
0861
0862 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
0863 els->io.iparam.els.ox_id = ox_id;
0864
0865 sparams = (struct fc_els_flogi *)node->nport->service_params;
0866 adisc = els->io.req.virt;
0867 memset(adisc, 0, sizeof(*adisc));
0868 adisc->adisc_cmd = ELS_LS_ACC;
0869 adisc->adisc_wwpn = sparams->fl_wwpn;
0870 adisc->adisc_wwnn = sparams->fl_wwnn;
0871 hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
0872
0873 return efc_els_send_rsp(els, sizeof(*adisc));
0874 }
0875
0876 static inline void
0877 fcct_build_req_header(struct fc_ct_hdr *hdr, u16 cmd, u16 max_size)
0878 {
0879 hdr->ct_rev = FC_CT_REV;
0880 hdr->ct_fs_type = FC_FST_DIR;
0881 hdr->ct_fs_subtype = FC_NS_SUBTYPE;
0882 hdr->ct_options = 0;
0883 hdr->ct_cmd = cpu_to_be16(cmd);
0884
0885 hdr->ct_mr_size = cpu_to_be16(max_size / (sizeof(u32)));
0886 hdr->ct_reason = 0;
0887 hdr->ct_explan = 0;
0888 hdr->ct_vendor = 0;
0889 }
0890
0891 int
0892 efc_ns_send_rftid(struct efc_node *node)
0893 {
0894 struct efc *efc = node->efc;
0895 struct efc_els_io_req *els;
0896 struct {
0897 struct fc_ct_hdr hdr;
0898 struct fc_ns_rft_id rftid;
0899 } *ct;
0900
0901 node_els_trace();
0902
0903 els = efc_els_io_alloc(node, sizeof(*ct));
0904 if (!els) {
0905 efc_log_err(efc, "IO alloc failed\n");
0906 return -EIO;
0907 }
0908
0909 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
0910 els->io.iparam.ct.type = FC_TYPE_CT;
0911 els->io.iparam.ct.df_ctl = 0;
0912 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
0913
0914 els->display_name = "rftid";
0915
0916 ct = els->io.req.virt;
0917 memset(ct, 0, sizeof(*ct));
0918 fcct_build_req_header(&ct->hdr, FC_NS_RFT_ID,
0919 sizeof(struct fc_ns_rft_id));
0920
0921 hton24(ct->rftid.fr_fid.fp_fid, node->rnode.nport->fc_id);
0922 ct->rftid.fr_fts.ff_type_map[FC_TYPE_FCP / FC_NS_BPW] =
0923 cpu_to_be32(1 << (FC_TYPE_FCP % FC_NS_BPW));
0924
0925 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
0926 }
0927
0928 int
0929 efc_ns_send_rffid(struct efc_node *node)
0930 {
0931 struct efc *efc = node->efc;
0932 struct efc_els_io_req *els;
0933 struct {
0934 struct fc_ct_hdr hdr;
0935 struct fc_ns_rff_id rffid;
0936 } *ct;
0937
0938 node_els_trace();
0939
0940 els = efc_els_io_alloc(node, sizeof(*ct));
0941 if (!els) {
0942 efc_log_err(efc, "IO alloc failed\n");
0943 return -EIO;
0944 }
0945
0946 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
0947 els->io.iparam.ct.type = FC_TYPE_CT;
0948 els->io.iparam.ct.df_ctl = 0;
0949 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
0950
0951 els->display_name = "rffid";
0952 ct = els->io.req.virt;
0953
0954 memset(ct, 0, sizeof(*ct));
0955 fcct_build_req_header(&ct->hdr, FC_NS_RFF_ID,
0956 sizeof(struct fc_ns_rff_id));
0957
0958 hton24(ct->rffid.fr_fid.fp_fid, node->rnode.nport->fc_id);
0959 if (node->nport->enable_ini)
0960 ct->rffid.fr_feat |= FCP_FEAT_INIT;
0961 if (node->nport->enable_tgt)
0962 ct->rffid.fr_feat |= FCP_FEAT_TARG;
0963 ct->rffid.fr_type = FC_TYPE_FCP;
0964
0965 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
0966 }
0967
0968 int
0969 efc_ns_send_gidpt(struct efc_node *node)
0970 {
0971 struct efc_els_io_req *els = NULL;
0972 struct efc *efc = node->efc;
0973 struct {
0974 struct fc_ct_hdr hdr;
0975 struct fc_ns_gid_pt gidpt;
0976 } *ct;
0977
0978 node_els_trace();
0979
0980 els = efc_els_io_alloc_size(node, sizeof(*ct), EFC_ELS_GID_PT_RSP_LEN);
0981 if (!els) {
0982 efc_log_err(efc, "IO alloc failed\n");
0983 return -EIO;
0984 }
0985
0986 els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
0987 els->io.iparam.ct.type = FC_TYPE_CT;
0988 els->io.iparam.ct.df_ctl = 0;
0989 els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
0990
0991 els->display_name = "gidpt";
0992
0993 ct = els->io.req.virt;
0994
0995 memset(ct, 0, sizeof(*ct));
0996 fcct_build_req_header(&ct->hdr, FC_NS_GID_PT,
0997 sizeof(struct fc_ns_gid_pt));
0998
0999 ct->gidpt.fn_pt_type = FC_TYPE_FCP;
1000
1001 return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
1002 }
1003
1004 void
1005 efc_els_io_cleanup(struct efc_els_io_req *els, int evt, void *arg)
1006 {
1007
1008
1009
1010 els->els_req_free = true;
1011 efc_node_post_els_resp(els->node, evt, arg);
1012
1013 efc_els_io_free(els);
1014 }
1015
1016 static int
1017 efc_ct_acc_cb(void *arg, u32 length, int status, u32 ext_status)
1018 {
1019 struct efc_els_io_req *els = arg;
1020
1021 efc_els_io_free(els);
1022
1023 return 0;
1024 }
1025
1026 int
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)
1030 {
1031 struct efc_els_io_req *els = NULL;
1032 struct fc_ct_hdr *rsp = NULL;
1033
1034 els = efc_els_io_alloc(node, 256);
1035 if (!els) {
1036 efc_log_err(efc, "IO alloc failed\n");
1037 return -EIO;
1038 }
1039
1040 rsp = els->io.rsp.virt;
1041
1042 *rsp = *ct_hdr;
1043
1044 fcct_build_req_header(rsp, cmd_rsp_code, 0);
1045 rsp->ct_reason = reason_code;
1046 rsp->ct_explan = reason_code_explanation;
1047
1048 els->display_name = "ct_rsp";
1049 els->cb = efc_ct_acc_cb;
1050
1051
1052 els->io.io_type = EFC_DISC_IO_CT_RESP;
1053 els->io.xmit_len = sizeof(*rsp);
1054
1055 els->io.rpi = node->rnode.indicator;
1056 els->io.d_id = node->rnode.fc_id;
1057
1058 memset(&els->io.iparam, 0, sizeof(els->io.iparam));
1059
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;
1065
1066 if (efc->tt.send_els(efc, &els->io)) {
1067 efc_els_io_free(els);
1068 return -EIO;
1069 }
1070 return 0;
1071 }
1072
1073 int
1074 efc_send_bls_acc(struct efc_node *node, struct fc_frame_header *hdr)
1075 {
1076 struct sli_bls_params bls;
1077 struct fc_ba_acc *acc;
1078 struct efc *efc = node->efc;
1079
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;
1087
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);
1092
1093 return efc->tt.send_bls(efc, FC_RCTL_BA_ACC, &bls);
1094 }