0001
0002
0003
0004
0005
0006
0007 #include "efc.h"
0008
0009 int
0010 efc_remote_node_cb(void *arg, int event, void *data)
0011 {
0012 struct efc *efc = arg;
0013 struct efc_remote_node *rnode = data;
0014 struct efc_node *node = rnode->node;
0015 unsigned long flags = 0;
0016
0017 spin_lock_irqsave(&efc->lock, flags);
0018 efc_node_post_event(node, event, NULL);
0019 spin_unlock_irqrestore(&efc->lock, flags);
0020
0021 return 0;
0022 }
0023
0024 struct efc_node *
0025 efc_node_find(struct efc_nport *nport, u32 port_id)
0026 {
0027
0028 return xa_load(&nport->lookup, port_id);
0029 }
0030
0031 static void
0032 _efc_node_free(struct kref *arg)
0033 {
0034 struct efc_node *node = container_of(arg, struct efc_node, ref);
0035 struct efc *efc = node->efc;
0036 struct efc_dma *dma;
0037
0038 dma = &node->sparm_dma_buf;
0039 dma_pool_free(efc->node_dma_pool, dma->virt, dma->phys);
0040 memset(dma, 0, sizeof(struct efc_dma));
0041 mempool_free(node, efc->node_pool);
0042 }
0043
0044 struct efc_node *efc_node_alloc(struct efc_nport *nport,
0045 u32 port_id, bool init, bool targ)
0046 {
0047 int rc;
0048 struct efc_node *node = NULL;
0049 struct efc *efc = nport->efc;
0050 struct efc_dma *dma;
0051
0052 if (nport->shutting_down) {
0053 efc_log_debug(efc, "node allocation when shutting down %06x",
0054 port_id);
0055 return NULL;
0056 }
0057
0058 node = mempool_alloc(efc->node_pool, GFP_ATOMIC);
0059 if (!node) {
0060 efc_log_err(efc, "node allocation failed %06x", port_id);
0061 return NULL;
0062 }
0063 memset(node, 0, sizeof(*node));
0064
0065 dma = &node->sparm_dma_buf;
0066 dma->size = NODE_SPARAMS_SIZE;
0067 dma->virt = dma_pool_zalloc(efc->node_dma_pool, GFP_ATOMIC, &dma->phys);
0068 if (!dma->virt) {
0069 efc_log_err(efc, "node dma alloc failed\n");
0070 goto dma_fail;
0071 }
0072 node->rnode.indicator = U32_MAX;
0073 node->nport = nport;
0074
0075 node->efc = efc;
0076 node->init = init;
0077 node->targ = targ;
0078
0079 spin_lock_init(&node->pend_frames_lock);
0080 INIT_LIST_HEAD(&node->pend_frames);
0081 spin_lock_init(&node->els_ios_lock);
0082 INIT_LIST_HEAD(&node->els_ios_list);
0083 node->els_io_enabled = true;
0084
0085 rc = efc_cmd_node_alloc(efc, &node->rnode, port_id, nport);
0086 if (rc) {
0087 efc_log_err(efc, "efc_hw_node_alloc failed: %d\n", rc);
0088 goto hw_alloc_fail;
0089 }
0090
0091 node->rnode.node = node;
0092 node->sm.app = node;
0093 node->evtdepth = 0;
0094
0095 efc_node_update_display_name(node);
0096
0097 rc = xa_err(xa_store(&nport->lookup, port_id, node, GFP_ATOMIC));
0098 if (rc) {
0099 efc_log_err(efc, "Node lookup store failed: %d\n", rc);
0100 goto xa_fail;
0101 }
0102
0103
0104 kref_init(&node->ref);
0105 node->release = _efc_node_free;
0106 kref_get(&nport->ref);
0107
0108 return node;
0109
0110 xa_fail:
0111 efc_node_free_resources(efc, &node->rnode);
0112 hw_alloc_fail:
0113 dma_pool_free(efc->node_dma_pool, dma->virt, dma->phys);
0114 dma_fail:
0115 mempool_free(node, efc->node_pool);
0116 return NULL;
0117 }
0118
0119 void
0120 efc_node_free(struct efc_node *node)
0121 {
0122 struct efc_nport *nport;
0123 struct efc *efc;
0124 int rc = 0;
0125 struct efc_node *ns = NULL;
0126
0127 nport = node->nport;
0128 efc = node->efc;
0129
0130 node_printf(node, "Free'd\n");
0131
0132 if (node->refound) {
0133
0134
0135
0136
0137 ns = efc_node_find(node->nport, FC_FID_DIR_SERV);
0138 }
0139
0140 if (!node->nport) {
0141 efc_log_err(efc, "Node already Freed\n");
0142 return;
0143 }
0144
0145
0146 rc = efc_node_free_resources(efc, &node->rnode);
0147 if (rc < 0)
0148 efc_log_err(efc, "efc_hw_node_free failed: %d\n", rc);
0149
0150
0151 if (timer_pending(&node->gidpt_delay_timer))
0152 del_timer(&node->gidpt_delay_timer);
0153
0154 xa_erase(&nport->lookup, node->rnode.fc_id);
0155
0156
0157
0158
0159
0160
0161
0162 if (xa_empty(&nport->lookup))
0163 efc_sm_post_event(&nport->sm, EFC_EVT_ALL_CHILD_NODES_FREE,
0164 NULL);
0165
0166 node->nport = NULL;
0167 node->sm.current_state = NULL;
0168
0169 kref_put(&nport->ref, nport->release);
0170 kref_put(&node->ref, node->release);
0171
0172 if (ns) {
0173
0174 efc_node_post_event(ns, EFC_EVT_RSCN_RCVD, NULL);
0175 }
0176 }
0177
0178 static void
0179 efc_dma_copy_in(struct efc_dma *dma, void *buffer, u32 buffer_length)
0180 {
0181 if (!dma || !buffer || !buffer_length)
0182 return;
0183
0184 if (buffer_length > dma->size)
0185 buffer_length = dma->size;
0186
0187 memcpy(dma->virt, buffer, buffer_length);
0188 dma->len = buffer_length;
0189 }
0190
0191 int
0192 efc_node_attach(struct efc_node *node)
0193 {
0194 int rc = 0;
0195 struct efc_nport *nport = node->nport;
0196 struct efc_domain *domain = nport->domain;
0197 struct efc *efc = node->efc;
0198
0199 if (!domain->attached) {
0200 efc_log_err(efc, "Warning: unattached domain\n");
0201 return -EIO;
0202 }
0203
0204
0205 efc_node_build_eui_name(node->wwpn, sizeof(node->wwpn),
0206 efc_node_get_wwpn(node));
0207 efc_node_build_eui_name(node->wwnn, sizeof(node->wwnn),
0208 efc_node_get_wwnn(node));
0209
0210 efc_dma_copy_in(&node->sparm_dma_buf, node->service_params + 4,
0211 sizeof(node->service_params) - 4);
0212
0213
0214 rc = efc_cmd_node_attach(efc, &node->rnode, &node->sparm_dma_buf);
0215 if (rc < 0)
0216 efc_log_debug(efc, "efc_hw_node_attach failed: %d\n", rc);
0217
0218 return rc;
0219 }
0220
0221 void
0222 efc_node_fcid_display(u32 fc_id, char *buffer, u32 buffer_length)
0223 {
0224 switch (fc_id) {
0225 case FC_FID_FLOGI:
0226 snprintf(buffer, buffer_length, "fabric");
0227 break;
0228 case FC_FID_FCTRL:
0229 snprintf(buffer, buffer_length, "fabctl");
0230 break;
0231 case FC_FID_DIR_SERV:
0232 snprintf(buffer, buffer_length, "nserve");
0233 break;
0234 default:
0235 if (fc_id == FC_FID_DOM_MGR) {
0236 snprintf(buffer, buffer_length, "dctl%02x",
0237 (fc_id & 0x0000ff));
0238 } else {
0239 snprintf(buffer, buffer_length, "%06x", fc_id);
0240 }
0241 break;
0242 }
0243 }
0244
0245 void
0246 efc_node_update_display_name(struct efc_node *node)
0247 {
0248 u32 port_id = node->rnode.fc_id;
0249 struct efc_nport *nport = node->nport;
0250 char portid_display[16];
0251
0252 efc_node_fcid_display(port_id, portid_display, sizeof(portid_display));
0253
0254 snprintf(node->display_name, sizeof(node->display_name), "%s.%s",
0255 nport->display_name, portid_display);
0256 }
0257
0258 void
0259 efc_node_send_ls_io_cleanup(struct efc_node *node)
0260 {
0261 if (node->send_ls_acc != EFC_NODE_SEND_LS_ACC_NONE) {
0262 efc_log_debug(node->efc, "[%s] cleaning up LS_ACC oxid=0x%x\n",
0263 node->display_name, node->ls_acc_oxid);
0264
0265 node->send_ls_acc = EFC_NODE_SEND_LS_ACC_NONE;
0266 node->ls_acc_io = NULL;
0267 }
0268 }
0269
0270 static void efc_node_handle_implicit_logo(struct efc_node *node)
0271 {
0272 int rc;
0273
0274
0275
0276
0277
0278
0279 WARN_ON(node->send_ls_acc != EFC_NODE_SEND_LS_ACC_PLOGI);
0280 node_printf(node, "Reason: implicit logout, re-authenticate\n");
0281
0282
0283 node->req_free = false;
0284 rc = efc_node_attach(node);
0285 efc_node_transition(node, __efc_d_wait_node_attach, NULL);
0286 node->els_io_enabled = true;
0287
0288 if (rc < 0)
0289 efc_node_post_event(node, EFC_EVT_NODE_ATTACH_FAIL, NULL);
0290 }
0291
0292 static void efc_node_handle_explicit_logo(struct efc_node *node)
0293 {
0294 s8 pend_frames_empty;
0295 unsigned long flags = 0;
0296
0297
0298 efc_node_send_ls_io_cleanup(node);
0299
0300 spin_lock_irqsave(&node->pend_frames_lock, flags);
0301 pend_frames_empty = list_empty(&node->pend_frames);
0302 spin_unlock_irqrestore(&node->pend_frames_lock, flags);
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312 node_printf(node, "Shutdown: explicit logo pend=%d ", !pend_frames_empty);
0313 node_printf(node, "nport.ini=%d node.tgt=%d\n",
0314 node->nport->enable_ini, node->targ);
0315 if (!pend_frames_empty || (node->nport->enable_ini && node->targ)) {
0316 u8 send_plogi = false;
0317
0318 if (node->nport->enable_ini && node->targ) {
0319
0320
0321
0322
0323
0324
0325 send_plogi = true;
0326 }
0327
0328
0329
0330
0331
0332 node->els_io_enabled = true;
0333 node->req_free = false;
0334
0335
0336
0337
0338
0339
0340 efc_node_init_device(node, send_plogi);
0341 }
0342
0343 }
0344
0345 static void
0346 efc_node_purge_pending(struct efc_node *node)
0347 {
0348 struct efc *efc = node->efc;
0349 struct efc_hw_sequence *frame, *next;
0350 unsigned long flags = 0;
0351
0352 spin_lock_irqsave(&node->pend_frames_lock, flags);
0353
0354 list_for_each_entry_safe(frame, next, &node->pend_frames, list_entry) {
0355 list_del(&frame->list_entry);
0356 efc->tt.hw_seq_free(efc, frame);
0357 }
0358
0359 spin_unlock_irqrestore(&node->pend_frames_lock, flags);
0360 }
0361
0362 void
0363 __efc_node_shutdown(struct efc_sm_ctx *ctx,
0364 enum efc_sm_event evt, void *arg)
0365 {
0366 struct efc_node *node = ctx->app;
0367
0368 efc_node_evt_set(ctx, evt, __func__);
0369
0370 node_sm_trace();
0371
0372 switch (evt) {
0373 case EFC_EVT_ENTER: {
0374 efc_node_hold_frames(node);
0375 WARN_ON(!efc_els_io_list_empty(node, &node->els_ios_list));
0376
0377 node->req_free = true;
0378
0379 switch (node->shutdown_reason) {
0380 case EFC_NODE_SHUTDOWN_IMPLICIT_LOGO:
0381
0382
0383
0384
0385
0386
0387 efc_node_handle_implicit_logo(node);
0388 break;
0389
0390 case EFC_NODE_SHUTDOWN_EXPLICIT_LOGO:
0391 efc_node_handle_explicit_logo(node);
0392 break;
0393
0394 case EFC_NODE_SHUTDOWN_DEFAULT:
0395 default: {
0396
0397
0398
0399
0400
0401
0402
0403
0404 efc_node_send_ls_io_cleanup(node);
0405
0406 node_printf(node,
0407 "Shutdown reason: default, purge pending\n");
0408 efc_node_purge_pending(node);
0409 break;
0410 }
0411 }
0412
0413 break;
0414 }
0415 case EFC_EVT_EXIT:
0416 efc_node_accept_frames(node);
0417 break;
0418
0419 default:
0420 __efc_node_common(__func__, ctx, evt, arg);
0421 }
0422 }
0423
0424 static bool
0425 efc_node_check_els_quiesced(struct efc_node *node)
0426 {
0427
0428 if (node->els_req_cnt == 0 && node->els_cmpl_cnt == 0 &&
0429 efc_els_io_list_empty(node, &node->els_ios_list)) {
0430 if (!node->attached) {
0431
0432 node_printf(node, "HW node not attached\n");
0433 efc_node_transition(node,
0434 __efc_node_wait_ios_shutdown,
0435 NULL);
0436 } else {
0437
0438
0439
0440
0441 node_printf(node, "HW node still attached\n");
0442 efc_node_transition(node, __efc_node_wait_node_free,
0443 NULL);
0444 }
0445 return true;
0446 }
0447 return false;
0448 }
0449
0450 void
0451 efc_node_initiate_cleanup(struct efc_node *node)
0452 {
0453
0454
0455
0456
0457 if (!efc_node_check_els_quiesced(node)) {
0458 efc_node_hold_frames(node);
0459 efc_node_transition(node, __efc_node_wait_els_shutdown, NULL);
0460 }
0461 }
0462
0463 void
0464 __efc_node_wait_els_shutdown(struct efc_sm_ctx *ctx,
0465 enum efc_sm_event evt, void *arg)
0466 {
0467 bool check_quiesce = false;
0468 struct efc_node *node = ctx->app;
0469
0470 efc_node_evt_set(ctx, evt, __func__);
0471
0472 node_sm_trace();
0473
0474 switch (evt) {
0475 case EFC_EVT_ENTER:
0476 efc_node_hold_frames(node);
0477 if (efc_els_io_list_empty(node, &node->els_ios_list)) {
0478 node_printf(node, "All ELS IOs complete\n");
0479 check_quiesce = true;
0480 }
0481 break;
0482 case EFC_EVT_EXIT:
0483 efc_node_accept_frames(node);
0484 break;
0485
0486 case EFC_EVT_SRRS_ELS_REQ_OK:
0487 case EFC_EVT_SRRS_ELS_REQ_FAIL:
0488 case EFC_EVT_SRRS_ELS_REQ_RJT:
0489 case EFC_EVT_ELS_REQ_ABORTED:
0490 if (WARN_ON(!node->els_req_cnt))
0491 break;
0492 node->els_req_cnt--;
0493 check_quiesce = true;
0494 break;
0495
0496 case EFC_EVT_SRRS_ELS_CMPL_OK:
0497 case EFC_EVT_SRRS_ELS_CMPL_FAIL:
0498 if (WARN_ON(!node->els_cmpl_cnt))
0499 break;
0500 node->els_cmpl_cnt--;
0501 check_quiesce = true;
0502 break;
0503
0504 case EFC_EVT_ALL_CHILD_NODES_FREE:
0505
0506 node_printf(node, "All ELS IOs complete\n");
0507 WARN_ON(!efc_els_io_list_empty(node, &node->els_ios_list));
0508 check_quiesce = true;
0509 break;
0510
0511 case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY:
0512 check_quiesce = true;
0513 break;
0514
0515 case EFC_EVT_DOMAIN_ATTACH_OK:
0516
0517 break;
0518
0519
0520 case EFC_EVT_SHUTDOWN:
0521
0522 node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT;
0523 fallthrough;
0524
0525 case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO:
0526 case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO:
0527 node_printf(node, "%s received\n", efc_sm_event_name(evt));
0528 break;
0529
0530 default:
0531 __efc_node_common(__func__, ctx, evt, arg);
0532 }
0533
0534 if (check_quiesce)
0535 efc_node_check_els_quiesced(node);
0536 }
0537
0538 void
0539 __efc_node_wait_node_free(struct efc_sm_ctx *ctx,
0540 enum efc_sm_event evt, void *arg)
0541 {
0542 struct efc_node *node = ctx->app;
0543
0544 efc_node_evt_set(ctx, evt, __func__);
0545
0546 node_sm_trace();
0547
0548 switch (evt) {
0549 case EFC_EVT_ENTER:
0550 efc_node_hold_frames(node);
0551 break;
0552
0553 case EFC_EVT_EXIT:
0554 efc_node_accept_frames(node);
0555 break;
0556
0557 case EFC_EVT_NODE_FREE_OK:
0558
0559 node->attached = false;
0560 efc_node_transition(node, __efc_node_wait_ios_shutdown, NULL);
0561 break;
0562
0563 case EFC_EVT_ALL_CHILD_NODES_FREE:
0564 case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY:
0565
0566 break;
0567
0568 case EFC_EVT_DOMAIN_ATTACH_OK:
0569
0570 break;
0571
0572
0573 case EFC_EVT_SHUTDOWN:
0574
0575 node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT;
0576 fallthrough;
0577
0578 case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO:
0579 case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO:
0580 node_printf(node, "%s received\n", efc_sm_event_name(evt));
0581 break;
0582 default:
0583 __efc_node_common(__func__, ctx, evt, arg);
0584 }
0585 }
0586
0587 void
0588 __efc_node_wait_ios_shutdown(struct efc_sm_ctx *ctx,
0589 enum efc_sm_event evt, void *arg)
0590 {
0591 struct efc_node *node = ctx->app;
0592 struct efc *efc = node->efc;
0593
0594 efc_node_evt_set(ctx, evt, __func__);
0595
0596 node_sm_trace();
0597
0598 switch (evt) {
0599 case EFC_EVT_ENTER:
0600 efc_node_hold_frames(node);
0601
0602
0603 if (efc_els_io_list_empty(node, &node->els_ios_list))
0604
0605 efc_node_transition(node, __efc_node_shutdown, NULL);
0606 break;
0607
0608 case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY:
0609 case EFC_EVT_ALL_CHILD_NODES_FREE:
0610 if (efc_els_io_list_empty(node, &node->els_ios_list))
0611 efc_node_transition(node, __efc_node_shutdown, NULL);
0612 break;
0613
0614 case EFC_EVT_EXIT:
0615 efc_node_accept_frames(node);
0616 break;
0617
0618 case EFC_EVT_SRRS_ELS_REQ_FAIL:
0619
0620 if (WARN_ON(!node->els_req_cnt))
0621 break;
0622 node->els_req_cnt--;
0623 break;
0624
0625
0626 case EFC_EVT_SHUTDOWN:
0627
0628 node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT;
0629 fallthrough;
0630
0631 case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO:
0632 case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO:
0633 efc_log_debug(efc, "[%s] %-20s\n", node->display_name,
0634 efc_sm_event_name(evt));
0635 break;
0636 case EFC_EVT_DOMAIN_ATTACH_OK:
0637
0638 break;
0639 default:
0640 __efc_node_common(__func__, ctx, evt, arg);
0641 }
0642 }
0643
0644 void
0645 __efc_node_common(const char *funcname, struct efc_sm_ctx *ctx,
0646 enum efc_sm_event evt, void *arg)
0647 {
0648 struct efc_node *node = NULL;
0649 struct efc *efc = NULL;
0650 struct efc_node_cb *cbdata = arg;
0651
0652 node = ctx->app;
0653 efc = node->efc;
0654
0655 switch (evt) {
0656 case EFC_EVT_ENTER:
0657 case EFC_EVT_REENTER:
0658 case EFC_EVT_EXIT:
0659 case EFC_EVT_NPORT_TOPOLOGY_NOTIFY:
0660 case EFC_EVT_NODE_MISSING:
0661 case EFC_EVT_FCP_CMD_RCVD:
0662 break;
0663
0664 case EFC_EVT_NODE_REFOUND:
0665 node->refound = true;
0666 break;
0667
0668
0669
0670
0671
0672 case EFC_EVT_NODE_ATTACH_OK:
0673 node->attached = true;
0674 break;
0675
0676 case EFC_EVT_NODE_FREE_OK:
0677 case EFC_EVT_NODE_ATTACH_FAIL:
0678 node->attached = false;
0679 break;
0680
0681
0682
0683
0684
0685
0686 case EFC_EVT_SRRS_ELS_CMPL_OK:
0687 case EFC_EVT_SRRS_ELS_CMPL_FAIL:
0688 if (WARN_ON(!node->els_cmpl_cnt))
0689 break;
0690 node->els_cmpl_cnt--;
0691 break;
0692
0693
0694
0695
0696
0697
0698 case EFC_EVT_SRRS_ELS_REQ_OK:
0699 case EFC_EVT_SRRS_ELS_REQ_FAIL:
0700 case EFC_EVT_SRRS_ELS_REQ_RJT:
0701 case EFC_EVT_ELS_REQ_ABORTED:
0702 if (WARN_ON(!node->els_req_cnt))
0703 break;
0704 node->els_req_cnt--;
0705 break;
0706
0707 case EFC_EVT_ELS_RCVD: {
0708 struct fc_frame_header *hdr = cbdata->header->dma.virt;
0709
0710
0711
0712
0713
0714 efc_log_debug(efc,
0715 "[%s] (%s) ELS x%02x, LS_RJT not supported\n",
0716 node->display_name, funcname,
0717 ((u8 *)cbdata->payload->dma.virt)[0]);
0718
0719 efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id),
0720 ELS_RJT_UNSUP, ELS_EXPL_NONE, 0);
0721 break;
0722 }
0723
0724 case EFC_EVT_PLOGI_RCVD:
0725 case EFC_EVT_FLOGI_RCVD:
0726 case EFC_EVT_LOGO_RCVD:
0727 case EFC_EVT_PRLI_RCVD:
0728 case EFC_EVT_PRLO_RCVD:
0729 case EFC_EVT_PDISC_RCVD:
0730 case EFC_EVT_FDISC_RCVD:
0731 case EFC_EVT_ADISC_RCVD:
0732 case EFC_EVT_RSCN_RCVD:
0733 case EFC_EVT_SCR_RCVD: {
0734 struct fc_frame_header *hdr = cbdata->header->dma.virt;
0735
0736
0737 efc_log_debug(efc, "[%s] (%s) %s sending ELS_RJT\n",
0738 node->display_name, funcname,
0739 efc_sm_event_name(evt));
0740
0741 efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id),
0742 ELS_RJT_UNAB, ELS_EXPL_NONE, 0);
0743 break;
0744 }
0745 case EFC_EVT_ABTS_RCVD: {
0746 efc_log_debug(efc, "[%s] (%s) %s sending BA_ACC\n",
0747 node->display_name, funcname,
0748 efc_sm_event_name(evt));
0749
0750
0751 efc_send_bls_acc(node, cbdata->header->dma.virt);
0752 break;
0753 }
0754
0755 default:
0756 efc_log_debug(node->efc, "[%s] %-20s %-20s not handled\n",
0757 node->display_name, funcname,
0758 efc_sm_event_name(evt));
0759 }
0760 }
0761
0762 void
0763 efc_node_save_sparms(struct efc_node *node, void *payload)
0764 {
0765 memcpy(node->service_params, payload, sizeof(node->service_params));
0766 }
0767
0768 void
0769 efc_node_post_event(struct efc_node *node,
0770 enum efc_sm_event evt, void *arg)
0771 {
0772 bool free_node = false;
0773
0774 node->evtdepth++;
0775
0776 efc_sm_post_event(&node->sm, evt, arg);
0777
0778
0779
0780
0781
0782
0783
0784 if (!node->hold_frames && node->evtdepth == 1)
0785 efc_process_node_pending(node);
0786
0787 node->evtdepth--;
0788
0789
0790
0791
0792
0793 if (node->evtdepth == 0 && node->req_free)
0794 free_node = true;
0795
0796 if (free_node)
0797 efc_node_free(node);
0798 }
0799
0800 void
0801 efc_node_transition(struct efc_node *node,
0802 void (*state)(struct efc_sm_ctx *,
0803 enum efc_sm_event, void *), void *data)
0804 {
0805 struct efc_sm_ctx *ctx = &node->sm;
0806
0807 if (ctx->current_state == state) {
0808 efc_node_post_event(node, EFC_EVT_REENTER, data);
0809 } else {
0810 efc_node_post_event(node, EFC_EVT_EXIT, data);
0811 ctx->current_state = state;
0812 efc_node_post_event(node, EFC_EVT_ENTER, data);
0813 }
0814 }
0815
0816 void
0817 efc_node_build_eui_name(char *buf, u32 buf_len, uint64_t eui_name)
0818 {
0819 memset(buf, 0, buf_len);
0820
0821 snprintf(buf, buf_len, "eui.%016llX", (unsigned long long)eui_name);
0822 }
0823
0824 u64
0825 efc_node_get_wwpn(struct efc_node *node)
0826 {
0827 struct fc_els_flogi *sp =
0828 (struct fc_els_flogi *)node->service_params;
0829
0830 return be64_to_cpu(sp->fl_wwpn);
0831 }
0832
0833 u64
0834 efc_node_get_wwnn(struct efc_node *node)
0835 {
0836 struct fc_els_flogi *sp =
0837 (struct fc_els_flogi *)node->service_params;
0838
0839 return be64_to_cpu(sp->fl_wwnn);
0840 }
0841
0842 int
0843 efc_node_check_els_req(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg,
0844 u8 cmd, void (*efc_node_common_func)(const char *,
0845 struct efc_sm_ctx *, enum efc_sm_event, void *),
0846 const char *funcname)
0847 {
0848 return 0;
0849 }
0850
0851 int
0852 efc_node_check_ns_req(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg,
0853 u16 cmd, void (*efc_node_common_func)(const char *,
0854 struct efc_sm_ctx *, enum efc_sm_event, void *),
0855 const char *funcname)
0856 {
0857 return 0;
0858 }
0859
0860 int
0861 efc_els_io_list_empty(struct efc_node *node, struct list_head *list)
0862 {
0863 int empty;
0864 unsigned long flags = 0;
0865
0866 spin_lock_irqsave(&node->els_ios_lock, flags);
0867 empty = list_empty(list);
0868 spin_unlock_irqrestore(&node->els_ios_lock, flags);
0869 return empty;
0870 }
0871
0872 void
0873 efc_node_pause(struct efc_node *node,
0874 void (*state)(struct efc_sm_ctx *,
0875 enum efc_sm_event, void *))
0876
0877 {
0878 node->nodedb_state = state;
0879 efc_node_transition(node, __efc_node_paused, NULL);
0880 }
0881
0882 void
0883 __efc_node_paused(struct efc_sm_ctx *ctx,
0884 enum efc_sm_event evt, void *arg)
0885 {
0886 struct efc_node *node = ctx->app;
0887
0888 efc_node_evt_set(ctx, evt, __func__);
0889
0890 node_sm_trace();
0891
0892
0893
0894
0895
0896 switch (evt) {
0897 case EFC_EVT_ENTER:
0898 node_printf(node, "Paused\n");
0899 break;
0900
0901 case EFC_EVT_RESUME: {
0902 void (*pf)(struct efc_sm_ctx *ctx,
0903 enum efc_sm_event evt, void *arg);
0904
0905 pf = node->nodedb_state;
0906
0907 node->nodedb_state = NULL;
0908 efc_node_transition(node, pf, NULL);
0909 break;
0910 }
0911
0912 case EFC_EVT_DOMAIN_ATTACH_OK:
0913 break;
0914
0915 case EFC_EVT_SHUTDOWN:
0916 node->req_free = true;
0917 break;
0918
0919 default:
0920 __efc_node_common(__func__, ctx, evt, arg);
0921 }
0922 }
0923
0924 void
0925 efc_node_recv_els_frame(struct efc_node *node,
0926 struct efc_hw_sequence *seq)
0927 {
0928 u32 prli_size = sizeof(struct fc_els_prli) + sizeof(struct fc_els_spp);
0929 struct {
0930 u32 cmd;
0931 enum efc_sm_event evt;
0932 u32 payload_size;
0933 } els_cmd_list[] = {
0934 {ELS_PLOGI, EFC_EVT_PLOGI_RCVD, sizeof(struct fc_els_flogi)},
0935 {ELS_FLOGI, EFC_EVT_FLOGI_RCVD, sizeof(struct fc_els_flogi)},
0936 {ELS_LOGO, EFC_EVT_LOGO_RCVD, sizeof(struct fc_els_ls_acc)},
0937 {ELS_PRLI, EFC_EVT_PRLI_RCVD, prli_size},
0938 {ELS_PRLO, EFC_EVT_PRLO_RCVD, prli_size},
0939 {ELS_PDISC, EFC_EVT_PDISC_RCVD, MAX_ACC_REJECT_PAYLOAD},
0940 {ELS_FDISC, EFC_EVT_FDISC_RCVD, MAX_ACC_REJECT_PAYLOAD},
0941 {ELS_ADISC, EFC_EVT_ADISC_RCVD, sizeof(struct fc_els_adisc)},
0942 {ELS_RSCN, EFC_EVT_RSCN_RCVD, MAX_ACC_REJECT_PAYLOAD},
0943 {ELS_SCR, EFC_EVT_SCR_RCVD, MAX_ACC_REJECT_PAYLOAD},
0944 };
0945 struct efc_node_cb cbdata;
0946 u8 *buf = seq->payload->dma.virt;
0947 enum efc_sm_event evt = EFC_EVT_ELS_RCVD;
0948 u32 i;
0949
0950 memset(&cbdata, 0, sizeof(cbdata));
0951 cbdata.header = seq->header;
0952 cbdata.payload = seq->payload;
0953
0954
0955 for (i = 0; i < ARRAY_SIZE(els_cmd_list); i++) {
0956 if (els_cmd_list[i].cmd == buf[0]) {
0957 evt = els_cmd_list[i].evt;
0958 break;
0959 }
0960 }
0961
0962 efc_node_post_event(node, evt, &cbdata);
0963 }
0964
0965 void
0966 efc_node_recv_ct_frame(struct efc_node *node,
0967 struct efc_hw_sequence *seq)
0968 {
0969 struct fc_ct_hdr *iu = seq->payload->dma.virt;
0970 struct fc_frame_header *hdr = seq->header->dma.virt;
0971 struct efc *efc = node->efc;
0972 u16 gscmd = be16_to_cpu(iu->ct_cmd);
0973
0974 efc_log_err(efc, "[%s] Received cmd :%x sending CT_REJECT\n",
0975 node->display_name, gscmd);
0976 efc_send_ct_rsp(efc, node, be16_to_cpu(hdr->fh_ox_id), iu,
0977 FC_FS_RJT, FC_FS_RJT_UNSUP, 0);
0978 }
0979
0980 void
0981 efc_node_recv_fcp_cmd(struct efc_node *node, struct efc_hw_sequence *seq)
0982 {
0983 struct efc_node_cb cbdata;
0984
0985 memset(&cbdata, 0, sizeof(cbdata));
0986 cbdata.header = seq->header;
0987 cbdata.payload = seq->payload;
0988
0989 efc_node_post_event(node, EFC_EVT_FCP_CMD_RCVD, &cbdata);
0990 }
0991
0992 void
0993 efc_process_node_pending(struct efc_node *node)
0994 {
0995 struct efc *efc = node->efc;
0996 struct efc_hw_sequence *seq = NULL;
0997 u32 pend_frames_processed = 0;
0998 unsigned long flags = 0;
0999
1000 for (;;) {
1001
1002
1003
1004
1005 if (node->hold_frames)
1006 break;
1007
1008 seq = NULL;
1009
1010 spin_lock_irqsave(&node->pend_frames_lock, flags);
1011
1012 if (!list_empty(&node->pend_frames)) {
1013 seq = list_first_entry(&node->pend_frames,
1014 struct efc_hw_sequence, list_entry);
1015 list_del(&seq->list_entry);
1016 }
1017 spin_unlock_irqrestore(&node->pend_frames_lock, flags);
1018
1019 if (!seq) {
1020 pend_frames_processed = node->pend_frames_processed;
1021 node->pend_frames_processed = 0;
1022 break;
1023 }
1024 node->pend_frames_processed++;
1025
1026
1027 efc_node_dispatch_frame(node, seq);
1028 efc->tt.hw_seq_free(efc, seq);
1029 }
1030
1031 if (pend_frames_processed != 0)
1032 efc_log_debug(efc, "%u node frames held and processed\n",
1033 pend_frames_processed);
1034 }
1035
1036 void
1037 efc_scsi_sess_reg_complete(struct efc_node *node, u32 status)
1038 {
1039 unsigned long flags = 0;
1040 enum efc_sm_event evt = EFC_EVT_NODE_SESS_REG_OK;
1041 struct efc *efc = node->efc;
1042
1043 if (status)
1044 evt = EFC_EVT_NODE_SESS_REG_FAIL;
1045
1046 spin_lock_irqsave(&efc->lock, flags);
1047
1048 efc_node_post_event(node, evt, NULL);
1049 spin_unlock_irqrestore(&efc->lock, flags);
1050 }
1051
1052 void
1053 efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node)
1054 {
1055 unsigned long flags = 0;
1056
1057 spin_lock_irqsave(&efc->lock, flags);
1058
1059 efc_node_post_event(node, EFC_EVT_NODE_DEL_INI_COMPLETE, NULL);
1060 spin_unlock_irqrestore(&efc->lock, flags);
1061 }
1062
1063 void
1064 efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node)
1065 {
1066 unsigned long flags = 0;
1067
1068 spin_lock_irqsave(&efc->lock, flags);
1069
1070 efc_node_post_event(node, EFC_EVT_NODE_DEL_TGT_COMPLETE, NULL);
1071 spin_unlock_irqrestore(&efc->lock, flags);
1072 }
1073
1074 void
1075 efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node)
1076 {
1077 unsigned long flags = 0;
1078
1079 spin_lock_irqsave(&efc->lock, flags);
1080 efc_node_post_event(node, EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY, NULL);
1081 spin_unlock_irqrestore(&efc->lock, flags);
1082 }
1083
1084 void efc_node_post_els_resp(struct efc_node *node, u32 evt, void *arg)
1085 {
1086 struct efc *efc = node->efc;
1087 unsigned long flags = 0;
1088
1089 spin_lock_irqsave(&efc->lock, flags);
1090 efc_node_post_event(node, evt, arg);
1091 spin_unlock_irqrestore(&efc->lock, flags);
1092 }
1093
1094 void efc_node_post_shutdown(struct efc_node *node, void *arg)
1095 {
1096 unsigned long flags = 0;
1097 struct efc *efc = node->efc;
1098
1099 spin_lock_irqsave(&efc->lock, flags);
1100 efc_node_post_event(node, EFC_EVT_SHUTDOWN, arg);
1101 spin_unlock_irqrestore(&efc->lock, flags);
1102 }