1 // SPDX-License-Identifier: GPL-2.0-only
3 * Marvell Fibre Channel HBA Driver
4 * Copyright (c) 2021 Marvell
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <scsi/scsi_tcq.h>
14 static struct edif_sa_index_entry *qla_edif_sadb_find_sa_index_entry(uint16_t nport_handle,
15 struct list_head *sa_list);
16 static uint16_t qla_edif_sadb_get_sa_index(fc_port_t *fcport,
17 struct qla_sa_update_frame *sa_frame);
18 static int qla_edif_sadb_delete_sa_index(fc_port_t *fcport, uint16_t nport_handle,
20 static int qla_pur_get_pending(scsi_qla_host_t *, fc_port_t *, struct bsg_job *);
23 struct list_head list;
29 struct edif_sa_update_aen sa_aen;
33 static struct els_sub_cmd {
37 {SEND_ELS, "send ELS"},
38 {SEND_ELS_REPLY, "send ELS Reply"},
39 {PULL_ELS, "retrieve ELS"},
42 const char *sc_to_str(uint16_t cmd)
45 struct els_sub_cmd *e;
47 for (i = 0; i < ARRAY_SIZE(sc_str); i++) {
55 static struct edif_list_entry *qla_edif_list_find_sa_index(fc_port_t *fcport,
58 struct edif_list_entry *entry;
59 struct edif_list_entry *tentry;
60 struct list_head *indx_list = &fcport->edif.edif_indx_list;
62 list_for_each_entry_safe(entry, tentry, indx_list, next) {
63 if (entry->handle == handle)
69 /* timeout called when no traffic and delayed rx sa_index delete */
70 static void qla2x00_sa_replace_iocb_timeout(struct timer_list *t)
72 struct edif_list_entry *edif_entry = from_timer(edif_entry, t, timer);
73 fc_port_t *fcport = edif_entry->fcport;
74 struct scsi_qla_host *vha = fcport->vha;
75 struct edif_sa_ctl *sa_ctl;
76 uint16_t nport_handle;
77 unsigned long flags = 0;
79 ql_dbg(ql_dbg_edif, vha, 0x3069,
80 "%s: nport_handle 0x%x, SA REPL Delay Timeout, %8phC portid=%06x\n",
81 __func__, edif_entry->handle, fcport->port_name, fcport->d_id.b24);
84 * if delete_sa_index is valid then no one has serviced this
87 spin_lock_irqsave(&fcport->edif.indx_list_lock, flags);
90 * delete_sa_index is invalidated when we find the new sa_index in
91 * the incoming data stream. If it is not invalidated then we are
92 * still looking for the new sa_index because there is no I/O and we
93 * need to just force the rx delete and move on. Otherwise
94 * we could get another rekey which will result in an error 66.
96 if (edif_entry->delete_sa_index != INVALID_EDIF_SA_INDEX) {
97 uint16_t delete_sa_index = edif_entry->delete_sa_index;
99 edif_entry->delete_sa_index = INVALID_EDIF_SA_INDEX;
100 nport_handle = edif_entry->handle;
101 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
103 sa_ctl = qla_edif_find_sa_ctl_by_index(fcport,
107 ql_dbg(ql_dbg_edif, vha, 0x3063,
108 "%s: sa_ctl: %p, delete index %d, update index: %d, lid: 0x%x\n",
109 __func__, sa_ctl, delete_sa_index, edif_entry->update_sa_index,
112 sa_ctl->flags = EDIF_SA_CTL_FLG_DEL;
113 set_bit(EDIF_SA_CTL_REPL, &sa_ctl->state);
114 qla_post_sa_replace_work(fcport->vha, fcport,
115 nport_handle, sa_ctl);
118 ql_dbg(ql_dbg_edif, vha, 0x3063,
119 "%s: sa_ctl not found for delete_sa_index: %d\n",
120 __func__, edif_entry->delete_sa_index);
123 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
128 * create a new list entry for this nport handle and
129 * add an sa_update index to the list - called for sa_update
131 static int qla_edif_list_add_sa_update_index(fc_port_t *fcport,
132 uint16_t sa_index, uint16_t handle)
134 struct edif_list_entry *entry;
135 unsigned long flags = 0;
137 /* if the entry exists, then just update the sa_index */
138 entry = qla_edif_list_find_sa_index(fcport, handle);
140 entry->update_sa_index = sa_index;
146 * This is the normal path - there should be no existing entry
147 * when update is called. The exception is at startup
148 * when update is called for the first two sa_indexes
149 * followed by a delete of the first sa_index
151 entry = kzalloc((sizeof(struct edif_list_entry)), GFP_ATOMIC);
155 INIT_LIST_HEAD(&entry->next);
156 entry->handle = handle;
157 entry->update_sa_index = sa_index;
158 entry->delete_sa_index = INVALID_EDIF_SA_INDEX;
161 timer_setup(&entry->timer, qla2x00_sa_replace_iocb_timeout, 0);
162 spin_lock_irqsave(&fcport->edif.indx_list_lock, flags);
163 list_add_tail(&entry->next, &fcport->edif.edif_indx_list);
164 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
168 /* remove an entry from the list */
169 static void qla_edif_list_delete_sa_index(fc_port_t *fcport, struct edif_list_entry *entry)
171 unsigned long flags = 0;
173 spin_lock_irqsave(&fcport->edif.indx_list_lock, flags);
174 list_del(&entry->next);
175 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
178 int qla_post_sa_replace_work(struct scsi_qla_host *vha,
179 fc_port_t *fcport, uint16_t nport_handle, struct edif_sa_ctl *sa_ctl)
181 struct qla_work_evt *e;
183 e = qla2x00_alloc_work(vha, QLA_EVT_SA_REPLACE);
185 return QLA_FUNCTION_FAILED;
187 e->u.sa_update.fcport = fcport;
188 e->u.sa_update.sa_ctl = sa_ctl;
189 e->u.sa_update.nport_handle = nport_handle;
190 fcport->flags |= FCF_ASYNC_ACTIVE;
191 return qla2x00_post_work(vha, e);
195 qla_edif_sa_ctl_init(scsi_qla_host_t *vha, struct fc_port *fcport)
197 ql_dbg(ql_dbg_edif, vha, 0x2058,
198 "Init SA_CTL List for fcport - nn %8phN pn %8phN portid=%06x.\n",
199 fcport->node_name, fcport->port_name, fcport->d_id.b24);
201 fcport->edif.tx_rekey_cnt = 0;
202 fcport->edif.rx_rekey_cnt = 0;
204 fcport->edif.tx_bytes = 0;
205 fcport->edif.rx_bytes = 0;
208 static int qla_bsg_check(scsi_qla_host_t *vha, struct bsg_job *bsg_job,
211 struct extra_auth_els *p;
212 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
213 struct qla_bsg_auth_els_request *req =
214 (struct qla_bsg_auth_els_request *)bsg_job->request;
216 if (!vha->hw->flags.edif_enabled) {
217 ql_dbg(ql_dbg_edif, vha, 0x9105,
218 "%s edif not enabled\n", __func__);
221 if (DBELL_INACTIVE(vha)) {
222 ql_dbg(ql_dbg_edif, vha, 0x09102,
223 "%s doorbell not enabled\n", __func__);
230 if (p->sub_cmd == PULL_ELS) {
231 struct qla_bsg_auth_els_reply *rpl =
232 (struct qla_bsg_auth_els_reply *)bsg_job->reply;
234 qla_pur_get_pending(vha, fcport, bsg_job);
236 ql_dbg(ql_dbg_edif, vha, 0x911d,
237 "%s %s %8phN sid=%x. xchg %x, nb=%xh bsg ptr %p\n",
238 __func__, sc_to_str(p->sub_cmd), fcport->port_name,
239 fcport->d_id.b24, rpl->rx_xchg_address,
240 rpl->r.reply_payload_rcv_len, bsg_job);
248 bsg_job_done(bsg_job, bsg_reply->result,
249 bsg_reply->reply_payload_rcv_len);
254 qla2x00_find_fcport_by_pid(scsi_qla_host_t *vha, port_id_t *id)
259 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
260 if ((f->flags & FCF_FCSP_DEVICE)) {
261 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x2058,
262 "Found secure fcport - nn %8phN pn %8phN portid=0x%x, 0x%x.\n",
263 f->node_name, f->port_name,
264 f->d_id.b24, id->b24);
265 if (f->d_id.b24 == id->b24)
273 * qla_edif_app_check(): check for valid application id.
274 * @vha: host adapter pointer
275 * @appid: application id
276 * Return: false = fail, true = pass
279 qla_edif_app_check(scsi_qla_host_t *vha, struct app_id appid)
281 /* check that the app is allow/known to the driver */
283 if (appid.app_vid == EDIF_APP_ID) {
284 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x911d, "%s app id ok\n", __func__);
287 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s app id not ok (%x)",
288 __func__, appid.app_vid);
294 qla_edif_free_sa_ctl(fc_port_t *fcport, struct edif_sa_ctl *sa_ctl,
297 unsigned long flags = 0;
299 spin_lock_irqsave(&fcport->edif.sa_list_lock, flags);
300 list_del(&sa_ctl->next);
301 spin_unlock_irqrestore(&fcport->edif.sa_list_lock, flags);
303 fcport->edif.tx_rekey_cnt--;
305 fcport->edif.rx_rekey_cnt--;
309 /* return an index to the freepool */
310 static void qla_edif_add_sa_index_to_freepool(fc_port_t *fcport, int dir,
314 struct scsi_qla_host *vha = fcport->vha;
315 struct qla_hw_data *ha = vha->hw;
316 unsigned long flags = 0;
317 u16 lsa_index = sa_index;
319 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x3063,
320 "%s: entry\n", __func__);
323 sa_id_map = ha->edif_tx_sa_id_map;
324 lsa_index -= EDIF_TX_SA_INDEX_BASE;
326 sa_id_map = ha->edif_rx_sa_id_map;
329 spin_lock_irqsave(&ha->sadb_fp_lock, flags);
330 clear_bit(lsa_index, sa_id_map);
331 spin_unlock_irqrestore(&ha->sadb_fp_lock, flags);
332 ql_dbg(ql_dbg_edif, vha, 0x3063,
333 "%s: index %d added to free pool\n", __func__, sa_index);
336 static void __qla2x00_release_all_sadb(struct scsi_qla_host *vha,
337 struct fc_port *fcport, struct edif_sa_index_entry *entry,
340 struct edif_list_entry *edif_entry;
341 struct edif_sa_ctl *sa_ctl;
345 for (i = 0; i < 2; i++) {
346 if (entry->sa_pair[i].sa_index == INVALID_EDIF_SA_INDEX)
349 if (fcport->loop_id != entry->handle) {
350 ql_dbg(ql_dbg_edif, vha, 0x3063,
351 "%s: ** WARNING %d** entry handle: 0x%x, lid: 0x%x, sa_index: %d\n",
352 __func__, i, entry->handle, fcport->loop_id,
353 entry->sa_pair[i].sa_index);
356 /* release the sa_ctl */
357 sa_ctl = qla_edif_find_sa_ctl_by_index(fcport,
358 entry->sa_pair[i].sa_index, pdir);
360 qla_edif_find_sa_ctl_by_index(fcport, sa_ctl->index, pdir)) {
361 ql_dbg(ql_dbg_edif, vha, 0x3063,
362 "%s: freeing sa_ctl for index %d\n", __func__, sa_ctl->index);
363 qla_edif_free_sa_ctl(fcport, sa_ctl, sa_ctl->index);
365 ql_dbg(ql_dbg_edif, vha, 0x3063,
366 "%s: sa_ctl NOT freed, sa_ctl: %p\n", __func__, sa_ctl);
369 /* Release the index */
370 ql_dbg(ql_dbg_edif, vha, 0x3063,
371 "%s: freeing sa_index %d, nph: 0x%x\n",
372 __func__, entry->sa_pair[i].sa_index, entry->handle);
374 dir = (entry->sa_pair[i].sa_index <
375 EDIF_TX_SA_INDEX_BASE) ? 0 : 1;
376 qla_edif_add_sa_index_to_freepool(fcport, dir,
377 entry->sa_pair[i].sa_index);
379 /* Delete timer on RX */
380 if (pdir != SAU_FLG_TX) {
382 qla_edif_list_find_sa_index(fcport, entry->handle);
384 ql_dbg(ql_dbg_edif, vha, 0x5033,
385 "%s: remove edif_entry %p, update_sa_index: 0x%x, delete_sa_index: 0x%x\n",
386 __func__, edif_entry, edif_entry->update_sa_index,
387 edif_entry->delete_sa_index);
388 qla_edif_list_delete_sa_index(fcport, edif_entry);
390 * valid delete_sa_index indicates there is a rx
391 * delayed delete queued
393 if (edif_entry->delete_sa_index !=
394 INVALID_EDIF_SA_INDEX) {
395 del_timer(&edif_entry->timer);
397 /* build and send the aen */
398 fcport->edif.rx_sa_set = 1;
399 fcport->edif.rx_sa_pending = 0;
400 qla_edb_eventcreate(vha,
401 VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
402 QL_VND_SA_STAT_SUCCESS,
403 QL_VND_RX_SA_KEY, fcport);
405 ql_dbg(ql_dbg_edif, vha, 0x5033,
406 "%s: release edif_entry %p, update_sa_index: 0x%x, delete_sa_index: 0x%x\n",
407 __func__, edif_entry, edif_entry->update_sa_index,
408 edif_entry->delete_sa_index);
415 ql_dbg(ql_dbg_edif, vha, 0x3063,
416 "%s: %d %s keys released\n",
417 __func__, key_cnt, pdir ? "tx" : "rx");
420 /* find an release all outstanding sadb sa_indicies */
421 void qla2x00_release_all_sadb(struct scsi_qla_host *vha, struct fc_port *fcport)
423 struct edif_sa_index_entry *entry, *tmp;
424 struct qla_hw_data *ha = vha->hw;
427 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x3063,
428 "%s: Starting...\n", __func__);
430 spin_lock_irqsave(&ha->sadb_lock, flags);
432 list_for_each_entry_safe(entry, tmp, &ha->sadb_rx_index_list, next) {
433 if (entry->fcport == fcport) {
434 list_del(&entry->next);
435 spin_unlock_irqrestore(&ha->sadb_lock, flags);
436 __qla2x00_release_all_sadb(vha, fcport, entry, 0);
438 spin_lock_irqsave(&ha->sadb_lock, flags);
443 list_for_each_entry_safe(entry, tmp, &ha->sadb_tx_index_list, next) {
444 if (entry->fcport == fcport) {
445 list_del(&entry->next);
446 spin_unlock_irqrestore(&ha->sadb_lock, flags);
448 __qla2x00_release_all_sadb(vha, fcport, entry, SAU_FLG_TX);
451 spin_lock_irqsave(&ha->sadb_lock, flags);
455 spin_unlock_irqrestore(&ha->sadb_lock, flags);
459 * qla_edif_app_start: application has announce its present
460 * @vha: host adapter pointer
461 * @bsg_job: user request
463 * Set/activate doorbell. Reset current sessions and re-login with
467 qla_edif_app_start(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
470 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
471 struct app_start appstart;
472 struct app_start_reply appreply;
473 struct fc_port *fcport, *tf;
475 ql_log(ql_log_info, vha, 0x1313,
476 "EDIF application registration with driver, FC device connections will be re-established.\n");
478 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
479 bsg_job->request_payload.sg_cnt, &appstart,
480 sizeof(struct app_start));
482 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s app_vid=%x app_start_flags %x\n",
483 __func__, appstart.app_info.app_vid, appstart.app_start_flags);
485 if (DBELL_INACTIVE(vha)) {
486 /* mark doorbell as active since an app is now present */
487 vha->e_dbell.db_flags |= EDB_ACTIVE;
489 ql_dbg(ql_dbg_edif, vha, 0x911e, "%s doorbell already active\n",
493 if (N2N_TOPO(vha->hw)) {
494 if (vha->hw->flags.n2n_fw_acc_sec)
495 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
497 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
498 qla2xxx_wake_dpc(vha);
500 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
501 ql_dbg(ql_dbg_edif, vha, 0x2058,
502 "FCSP - nn %8phN pn %8phN portid=%06x.\n",
503 fcport->node_name, fcport->port_name,
505 ql_dbg(ql_dbg_edif, vha, 0xf084,
506 "%s: se_sess %p / sess %p from port %8phC "
507 "loop_id %#04x s_id %06x logout %d "
508 "keep %d els_logo %d disc state %d auth state %d"
510 __func__, fcport->se_sess, fcport,
511 fcport->port_name, fcport->loop_id,
512 fcport->d_id.b24, fcport->logout_on_delete,
513 fcport->keep_nport_handle, fcport->send_els_logo,
514 fcport->disc_state, fcport->edif.auth_state,
515 fcport->edif.app_stop);
517 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
520 fcport->edif.app_started = 1;
521 fcport->login_retry = vha->hw->login_retry_count;
524 fcport->edif.app_stop = 0;
526 ql_dbg(ql_dbg_edif, vha, 0x911e,
527 "%s wwpn %8phC calling qla_edif_reset_auth_wait\n",
528 __func__, fcport->port_name);
529 fcport->edif.app_sess_online = 0;
530 qlt_schedule_sess_for_deletion(fcport);
531 qla_edif_sa_ctl_init(vha, fcport);
535 if (vha->pur_cinfo.enode_flags != ENODE_ACTIVE) {
536 /* mark as active since an app is now present */
537 vha->pur_cinfo.enode_flags = ENODE_ACTIVE;
539 ql_dbg(ql_dbg_edif, vha, 0x911f, "%s enode already active\n",
543 appreply.host_support_edif = vha->hw->flags.edif_enabled;
544 appreply.edif_enode_active = vha->pur_cinfo.enode_flags;
545 appreply.edif_edb_active = vha->e_dbell.db_flags;
547 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
549 SET_DID_STATUS(bsg_reply->result, DID_OK);
551 bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
552 bsg_job->reply_payload.sg_cnt,
554 sizeof(struct app_start_reply));
556 ql_dbg(ql_dbg_edif, vha, 0x911d,
557 "%s app start completed with 0x%x\n",
564 * qla_edif_app_stop - app has announced it's exiting.
565 * @vha: host adapter pointer
566 * @bsg_job: user space command pointer
568 * Free any in flight messages, clear all doorbell events
569 * to application. Reject any message relate to security.
572 qla_edif_app_stop(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
574 struct app_stop appstop;
575 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
576 struct fc_port *fcport, *tf;
578 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
579 bsg_job->request_payload.sg_cnt, &appstop,
580 sizeof(struct app_stop));
582 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s Stopping APP: app_vid=%x\n",
583 __func__, appstop.app_info.app_vid);
585 /* Call db stop and enode stop functions */
587 /* if we leave this running short waits are operational < 16 secs */
588 qla_enode_stop(vha); /* stop enode */
589 qla_edb_stop(vha); /* stop db */
591 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
592 if (!(fcport->flags & FCF_FCSP_DEVICE))
595 if (fcport->flags & FCF_FCSP_DEVICE) {
596 ql_dbg(ql_dbg_edif, vha, 0xf084,
597 "%s: sess %p from port %8phC lid %#04x s_id %06x logout %d keep %d els_logo %d\n",
599 fcport->port_name, fcport->loop_id, fcport->d_id.b24,
600 fcport->logout_on_delete, fcport->keep_nport_handle,
601 fcport->send_els_logo);
603 if (atomic_read(&vha->loop_state) == LOOP_DOWN)
606 fcport->edif.app_stop = 1;
607 ql_dbg(ql_dbg_edif, vha, 0x911e,
608 "%s wwpn %8phC calling qla_edif_reset_auth_wait\n",
609 __func__, fcport->port_name);
611 fcport->send_els_logo = 1;
612 qlt_schedule_sess_for_deletion(fcport);
614 /* qla_edif_flush_sa_ctl_lists(fcport); */
615 fcport->edif.app_started = 0;
619 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
620 SET_DID_STATUS(bsg_reply->result, DID_OK);
622 /* no return interface to app - it assumes we cleaned up ok */
628 qla_edif_app_chk_sa_update(scsi_qla_host_t *vha, fc_port_t *fcport,
629 struct app_plogi_reply *appplogireply)
633 if (!(fcport->edif.rx_sa_set && fcport->edif.tx_sa_set)) {
634 ql_dbg(ql_dbg_edif, vha, 0x911e,
635 "%s: wwpn %8phC Both SA indexes has not been SET TX %d, RX %d.\n",
636 __func__, fcport->port_name, fcport->edif.tx_sa_set,
637 fcport->edif.rx_sa_set);
638 appplogireply->prli_status = 0;
641 ql_dbg(ql_dbg_edif, vha, 0x911e,
642 "%s wwpn %8phC Both SA(s) updated.\n", __func__,
644 fcport->edif.rx_sa_set = fcport->edif.tx_sa_set = 0;
645 fcport->edif.rx_sa_pending = fcport->edif.tx_sa_pending = 0;
646 appplogireply->prli_status = 1;
652 * qla_edif_app_authok - authentication by app succeeded. Driver can proceed
654 * @vha: host adapter pointer
655 * @bsg_job: user request
658 qla_edif_app_authok(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
661 struct auth_complete_cmd appplogiok;
662 struct app_plogi_reply appplogireply = {0};
663 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
664 fc_port_t *fcport = NULL;
665 port_id_t portid = {0};
667 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
668 bsg_job->request_payload.sg_cnt, &appplogiok,
669 sizeof(struct auth_complete_cmd));
671 switch (appplogiok.type) {
673 fcport = qla2x00_find_fcport_by_wwpn(vha,
674 appplogiok.u.wwpn, 0);
676 ql_dbg(ql_dbg_edif, vha, 0x911d,
677 "%s wwpn lookup failed: %8phC\n",
678 __func__, appplogiok.u.wwpn);
681 fcport = qla2x00_find_fcport_by_pid(vha, &appplogiok.u.d_id);
683 ql_dbg(ql_dbg_edif, vha, 0x911d,
684 "%s d_id lookup failed: %x\n", __func__,
688 ql_dbg(ql_dbg_edif, vha, 0x911d,
689 "%s undefined type: %x\n", __func__,
695 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
700 * if port is online then this is a REKEY operation
701 * Only do sa update checking
703 if (atomic_read(&fcport->state) == FCS_ONLINE) {
704 ql_dbg(ql_dbg_edif, vha, 0x911d,
705 "%s Skipping PRLI complete based on rekey\n", __func__);
706 appplogireply.prli_status = 1;
707 SET_DID_STATUS(bsg_reply->result, DID_OK);
708 qla_edif_app_chk_sa_update(vha, fcport, &appplogireply);
712 /* make sure in AUTH_PENDING or else reject */
713 if (fcport->disc_state != DSC_LOGIN_AUTH_PEND) {
714 ql_dbg(ql_dbg_edif, vha, 0x911e,
715 "%s wwpn %8phC is not in auth pending state (%x)\n",
716 __func__, fcport->port_name, fcport->disc_state);
717 SET_DID_STATUS(bsg_reply->result, DID_OK);
718 appplogireply.prli_status = 0;
722 SET_DID_STATUS(bsg_reply->result, DID_OK);
723 appplogireply.prli_status = 1;
724 fcport->edif.authok = 1;
725 if (!(fcport->edif.rx_sa_set && fcport->edif.tx_sa_set)) {
726 ql_dbg(ql_dbg_edif, vha, 0x911e,
727 "%s: wwpn %8phC Both SA indexes has not been SET TX %d, RX %d.\n",
728 __func__, fcport->port_name, fcport->edif.tx_sa_set,
729 fcport->edif.rx_sa_set);
730 SET_DID_STATUS(bsg_reply->result, DID_OK);
731 appplogireply.prli_status = 0;
735 ql_dbg(ql_dbg_edif, vha, 0x911e,
736 "%s wwpn %8phC Both SA(s) updated.\n", __func__,
738 fcport->edif.rx_sa_set = fcport->edif.tx_sa_set = 0;
739 fcport->edif.rx_sa_pending = fcport->edif.tx_sa_pending = 0;
742 if (qla_ini_mode_enabled(vha)) {
743 ql_dbg(ql_dbg_edif, vha, 0x911e,
744 "%s AUTH complete - RESUME with prli for wwpn %8phC\n",
745 __func__, fcport->port_name);
746 qla24xx_post_prli_work(vha, fcport);
750 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
751 bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
752 bsg_job->reply_payload.sg_cnt,
754 sizeof(struct app_plogi_reply));
760 * qla_edif_app_authfail - authentication by app has failed. Driver is given
761 * notice to tear down current session.
762 * @vha: host adapter pointer
763 * @bsg_job: user request
766 qla_edif_app_authfail(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
769 struct auth_complete_cmd appplogifail;
770 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
771 fc_port_t *fcport = NULL;
772 port_id_t portid = {0};
774 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s app auth fail\n", __func__);
776 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
777 bsg_job->request_payload.sg_cnt, &appplogifail,
778 sizeof(struct auth_complete_cmd));
781 * TODO: edif: app has failed this plogi. Inform driver to
782 * take any action (if any).
784 switch (appplogifail.type) {
786 fcport = qla2x00_find_fcport_by_wwpn(vha,
787 appplogifail.u.wwpn, 0);
788 SET_DID_STATUS(bsg_reply->result, DID_OK);
791 fcport = qla2x00_find_fcport_by_pid(vha, &appplogifail.u.d_id);
793 ql_dbg(ql_dbg_edif, vha, 0x911d,
794 "%s d_id lookup failed: %x\n", __func__,
796 SET_DID_STATUS(bsg_reply->result, DID_OK);
799 ql_dbg(ql_dbg_edif, vha, 0x911e,
800 "%s undefined type: %x\n", __func__,
802 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
803 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
808 ql_dbg(ql_dbg_edif, vha, 0x911d,
809 "%s fcport is 0x%p\n", __func__, fcport);
812 /* set/reset edif values and flags */
813 ql_dbg(ql_dbg_edif, vha, 0x911e,
814 "%s reset the auth process - %8phC, loopid=%x portid=%06x.\n",
815 __func__, fcport->port_name, fcport->loop_id, fcport->d_id.b24);
817 if (qla_ini_mode_enabled(fcport->vha)) {
818 fcport->send_els_logo = 1;
819 qlt_schedule_sess_for_deletion(fcport);
827 * qla_edif_app_getfcinfo - app would like to read session info (wwpn, nportid,
828 * [initiator|target] mode. It can specific session with specific nport id or
830 * @vha: host adapter pointer
831 * @bsg_job: user request pointer
834 qla_edif_app_getfcinfo(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
838 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
839 struct app_pinfo_req app_req;
840 struct app_pinfo_reply *app_reply;
843 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s app get fcinfo\n", __func__);
845 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
846 bsg_job->request_payload.sg_cnt, &app_req,
847 sizeof(struct app_pinfo_req));
849 app_reply = kzalloc((sizeof(struct app_pinfo_reply) +
850 sizeof(struct app_pinfo) * app_req.num_ports), GFP_KERNEL);
853 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
856 struct fc_port *fcport = NULL, *tf;
858 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
859 if (!(fcport->flags & FCF_FCSP_DEVICE))
862 tdid = app_req.remote_pid;
864 ql_dbg(ql_dbg_edif, vha, 0x2058,
865 "APP request entry - portid=%06x.\n", tdid.b24);
867 /* Ran out of space */
868 if (pcnt > app_req.num_ports)
871 if (tdid.b24 != 0 && tdid.b24 != fcport->d_id.b24)
874 app_reply->ports[pcnt].rekey_count =
875 fcport->edif.rekey_cnt;
877 app_reply->ports[pcnt].remote_type =
878 VND_CMD_RTYPE_UNKNOWN;
879 if (fcport->port_type & (FCT_NVME_TARGET | FCT_TARGET))
880 app_reply->ports[pcnt].remote_type |=
881 VND_CMD_RTYPE_TARGET;
882 if (fcport->port_type & (FCT_NVME_INITIATOR | FCT_INITIATOR))
883 app_reply->ports[pcnt].remote_type |=
884 VND_CMD_RTYPE_INITIATOR;
886 app_reply->ports[pcnt].remote_pid = fcport->d_id;
888 ql_dbg(ql_dbg_edif, vha, 0x2058,
889 "Found FC_SP fcport - nn %8phN pn %8phN pcnt %d portid=%06x secure %d.\n",
890 fcport->node_name, fcport->port_name, pcnt,
891 fcport->d_id.b24, fcport->flags & FCF_FCSP_DEVICE);
893 switch (fcport->edif.auth_state) {
894 case VND_CMD_AUTH_STATE_ELS_RCVD:
895 if (fcport->disc_state == DSC_LOGIN_AUTH_PEND) {
896 fcport->edif.auth_state = VND_CMD_AUTH_STATE_NEEDED;
897 app_reply->ports[pcnt].auth_state =
898 VND_CMD_AUTH_STATE_NEEDED;
900 app_reply->ports[pcnt].auth_state =
901 VND_CMD_AUTH_STATE_ELS_RCVD;
905 app_reply->ports[pcnt].auth_state = fcport->edif.auth_state;
909 memcpy(app_reply->ports[pcnt].remote_wwpn,
910 fcport->port_name, 8);
912 app_reply->ports[pcnt].remote_state =
913 (atomic_read(&fcport->state) ==
921 app_reply->port_count = pcnt;
922 SET_DID_STATUS(bsg_reply->result, DID_OK);
925 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
926 bsg_reply->reply_payload_rcv_len = sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
927 bsg_job->reply_payload.sg_cnt,
929 sizeof(struct app_pinfo_reply) + sizeof(struct app_pinfo) * pcnt);
937 * qla_edif_app_getstats - app would like to read various statistics info
938 * @vha: host adapter pointer
939 * @bsg_job: user request
942 qla_edif_app_getstats(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
945 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
948 struct app_sinfo_req app_req;
949 struct app_stats_reply *app_reply;
952 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
953 bsg_job->request_payload.sg_cnt, &app_req,
954 sizeof(struct app_sinfo_req));
955 if (app_req.num_ports == 0) {
956 ql_dbg(ql_dbg_async, vha, 0x911d,
957 "%s app did not indicate number of ports to return\n",
959 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
963 size = sizeof(struct app_stats_reply) +
964 (sizeof(struct app_sinfo) * app_req.num_ports);
966 app_reply = kzalloc(size, GFP_KERNEL);
968 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
971 struct fc_port *fcport = NULL, *tf;
973 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
974 if (fcport->edif.enable) {
975 if (pcnt > app_req.num_ports)
978 app_reply->elem[pcnt].rekey_count =
979 fcport->edif.rekey_cnt;
980 app_reply->elem[pcnt].tx_bytes =
981 fcport->edif.tx_bytes;
982 app_reply->elem[pcnt].rx_bytes =
983 fcport->edif.rx_bytes;
985 memcpy(app_reply->elem[pcnt].remote_wwpn,
986 fcport->port_name, 8);
991 app_reply->elem_count = pcnt;
992 SET_DID_STATUS(bsg_reply->result, DID_OK);
995 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
996 bsg_reply->reply_payload_rcv_len =
997 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
998 bsg_job->reply_payload.sg_cnt, app_reply,
999 sizeof(struct app_stats_reply) + (sizeof(struct app_sinfo) * pcnt));
1007 qla_edif_app_mgmt(struct bsg_job *bsg_job)
1009 struct fc_bsg_request *bsg_request = bsg_job->request;
1010 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1011 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1012 scsi_qla_host_t *vha = shost_priv(host);
1013 struct app_id appcheck;
1016 uint32_t vnd_sc = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1018 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s vnd subcmd=%x\n",
1021 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1022 bsg_job->request_payload.sg_cnt, &appcheck,
1023 sizeof(struct app_id));
1025 if (!vha->hw->flags.edif_enabled ||
1026 test_bit(VPORT_DELETE, &vha->dpc_flags)) {
1027 ql_dbg(ql_dbg_edif, vha, 0x911d,
1028 "%s edif not enabled or vp delete. bsg ptr done %p. dpc_flags %lx\n",
1029 __func__, bsg_job, vha->dpc_flags);
1031 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1035 if (!qla_edif_app_check(vha, appcheck)) {
1036 ql_dbg(ql_dbg_edif, vha, 0x911d,
1037 "%s app checked failed.\n",
1040 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1041 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1046 case QL_VND_SC_SA_UPDATE:
1048 rval = qla24xx_sadb_update(bsg_job);
1050 case QL_VND_SC_APP_START:
1051 rval = qla_edif_app_start(vha, bsg_job);
1053 case QL_VND_SC_APP_STOP:
1054 rval = qla_edif_app_stop(vha, bsg_job);
1056 case QL_VND_SC_AUTH_OK:
1057 rval = qla_edif_app_authok(vha, bsg_job);
1059 case QL_VND_SC_AUTH_FAIL:
1060 rval = qla_edif_app_authfail(vha, bsg_job);
1062 case QL_VND_SC_GET_FCINFO:
1063 rval = qla_edif_app_getfcinfo(vha, bsg_job);
1065 case QL_VND_SC_GET_STATS:
1066 rval = qla_edif_app_getstats(vha, bsg_job);
1069 ql_dbg(ql_dbg_edif, vha, 0x911d, "%s unknown cmd=%x\n",
1071 bsg_request->rqst_data.h_vendor.vendor_cmd[1]);
1072 rval = EXT_STATUS_INVALID_PARAM;
1079 ql_dbg(ql_dbg_user, vha, 0x7009,
1080 "%s: %d bsg ptr done %p\n", __func__, __LINE__, bsg_job);
1081 bsg_job_done(bsg_job, bsg_reply->result,
1082 bsg_reply->reply_payload_rcv_len);
1088 static struct edif_sa_ctl *
1089 qla_edif_add_sa_ctl(fc_port_t *fcport, struct qla_sa_update_frame *sa_frame,
1092 struct edif_sa_ctl *sa_ctl;
1093 struct qla_sa_update_frame *sap;
1094 int index = sa_frame->fast_sa_index;
1095 unsigned long flags = 0;
1097 sa_ctl = kzalloc(sizeof(*sa_ctl), GFP_KERNEL);
1099 /* couldn't get space */
1100 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1101 "unable to allocate SA CTL\n");
1106 * need to allocate sa_index here and save it
1107 * in both sa_ctl->index and sa_frame->fast_sa_index;
1108 * If alloc fails then delete sa_ctl and return NULL
1110 INIT_LIST_HEAD(&sa_ctl->next);
1111 sap = &sa_ctl->sa_frame;
1113 sa_ctl->index = index;
1114 sa_ctl->fcport = fcport;
1117 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1118 "%s: Added sa_ctl %p, index %d, state 0x%lx\n",
1119 __func__, sa_ctl, sa_ctl->index, sa_ctl->state);
1120 spin_lock_irqsave(&fcport->edif.sa_list_lock, flags);
1121 if (dir == SAU_FLG_TX)
1122 list_add_tail(&sa_ctl->next, &fcport->edif.tx_sa_list);
1124 list_add_tail(&sa_ctl->next, &fcport->edif.rx_sa_list);
1125 spin_unlock_irqrestore(&fcport->edif.sa_list_lock, flags);
1131 qla_edif_flush_sa_ctl_lists(fc_port_t *fcport)
1133 struct edif_sa_ctl *sa_ctl, *tsa_ctl;
1134 unsigned long flags = 0;
1136 spin_lock_irqsave(&fcport->edif.sa_list_lock, flags);
1138 list_for_each_entry_safe(sa_ctl, tsa_ctl, &fcport->edif.tx_sa_list,
1140 list_del(&sa_ctl->next);
1144 list_for_each_entry_safe(sa_ctl, tsa_ctl, &fcport->edif.rx_sa_list,
1146 list_del(&sa_ctl->next);
1150 spin_unlock_irqrestore(&fcport->edif.sa_list_lock, flags);
1153 struct edif_sa_ctl *
1154 qla_edif_find_sa_ctl_by_index(fc_port_t *fcport, int index, int dir)
1156 struct edif_sa_ctl *sa_ctl, *tsa_ctl;
1157 struct list_head *sa_list;
1159 if (dir == SAU_FLG_TX)
1160 sa_list = &fcport->edif.tx_sa_list;
1162 sa_list = &fcport->edif.rx_sa_list;
1164 list_for_each_entry_safe(sa_ctl, tsa_ctl, sa_list, next) {
1165 if (test_bit(EDIF_SA_CTL_USED, &sa_ctl->state) &&
1166 sa_ctl->index == index)
1172 /* add the sa to the correct list */
1174 qla24xx_check_sadb_avail_slot(struct bsg_job *bsg_job, fc_port_t *fcport,
1175 struct qla_sa_update_frame *sa_frame)
1177 struct edif_sa_ctl *sa_ctl = NULL;
1181 dir = (sa_frame->flags & SAU_FLG_TX);
1183 /* map the spi to an sa_index */
1184 sa_index = qla_edif_sadb_get_sa_index(fcport, sa_frame);
1185 if (sa_index == RX_DELETE_NO_EDIF_SA_INDEX) {
1186 /* process rx delete */
1187 ql_dbg(ql_dbg_edif, fcport->vha, 0x3063,
1188 "%s: rx delete for lid 0x%x, spi 0x%x, no entry found\n",
1189 __func__, fcport->loop_id, sa_frame->spi);
1191 /* build and send the aen */
1192 fcport->edif.rx_sa_set = 1;
1193 fcport->edif.rx_sa_pending = 0;
1194 qla_edb_eventcreate(fcport->vha,
1195 VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
1196 QL_VND_SA_STAT_SUCCESS,
1197 QL_VND_RX_SA_KEY, fcport);
1199 /* force a return of good bsg status; */
1200 return RX_DELETE_NO_EDIF_SA_INDEX;
1201 } else if (sa_index == INVALID_EDIF_SA_INDEX) {
1202 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1203 "%s: Failed to get sa_index for spi 0x%x, dir: %d\n",
1204 __func__, sa_frame->spi, dir);
1205 return INVALID_EDIF_SA_INDEX;
1208 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1209 "%s: index %d allocated to spi 0x%x, dir: %d, nport_handle: 0x%x\n",
1210 __func__, sa_index, sa_frame->spi, dir, fcport->loop_id);
1212 /* This is a local copy of sa_frame. */
1213 sa_frame->fast_sa_index = sa_index;
1214 /* create the sa_ctl */
1215 sa_ctl = qla_edif_add_sa_ctl(fcport, sa_frame, dir);
1217 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1218 "%s: Failed to add sa_ctl for spi 0x%x, dir: %d, sa_index: %d\n",
1219 __func__, sa_frame->spi, dir, sa_index);
1223 set_bit(EDIF_SA_CTL_USED, &sa_ctl->state);
1225 if (dir == SAU_FLG_TX)
1226 fcport->edif.tx_rekey_cnt++;
1228 fcport->edif.rx_rekey_cnt++;
1230 ql_dbg(ql_dbg_edif, fcport->vha, 0x9100,
1231 "%s: Found sa_ctl %p, index %d, state 0x%lx, tx_cnt %d, rx_cnt %d, nport_handle: 0x%x\n",
1232 __func__, sa_ctl, sa_ctl->index, sa_ctl->state,
1233 fcport->edif.tx_rekey_cnt,
1234 fcport->edif.rx_rekey_cnt, fcport->loop_id);
1239 #define QLA_SA_UPDATE_FLAGS_RX_KEY 0x0
1240 #define QLA_SA_UPDATE_FLAGS_TX_KEY 0x2
1243 qla24xx_sadb_update(struct bsg_job *bsg_job)
1245 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1246 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1247 scsi_qla_host_t *vha = shost_priv(host);
1248 fc_port_t *fcport = NULL;
1250 struct edif_list_entry *edif_entry = NULL;
1254 struct qla_sa_update_frame sa_frame;
1255 struct srb_iocb *iocb_cmd;
1257 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x911d,
1258 "%s entered, vha: 0x%p\n", __func__, vha);
1260 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1261 bsg_job->request_payload.sg_cnt, &sa_frame,
1262 sizeof(struct qla_sa_update_frame));
1264 /* Check if host is online */
1265 if (!vha->flags.online) {
1266 ql_log(ql_log_warn, vha, 0x70a1, "Host is not online\n");
1268 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1272 if (DBELL_INACTIVE(vha)) {
1273 ql_log(ql_log_warn, vha, 0x70a1, "App not started\n");
1275 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1279 fcport = qla2x00_find_fcport_by_pid(vha, &sa_frame.port_id);
1282 if (sa_frame.flags == QLA_SA_UPDATE_FLAGS_TX_KEY)
1283 fcport->edif.tx_bytes = 0;
1284 if (sa_frame.flags == QLA_SA_UPDATE_FLAGS_RX_KEY)
1285 fcport->edif.rx_bytes = 0;
1289 ql_dbg(ql_dbg_edif, vha, 0x70a3, "Failed to find port= %06x\n",
1290 sa_frame.port_id.b24);
1292 SET_DID_STATUS(bsg_reply->result, DID_TARGET_FAILURE);
1296 /* make sure the nport_handle is valid */
1297 if (fcport->loop_id == FC_NO_LOOP_ID) {
1298 ql_dbg(ql_dbg_edif, vha, 0x70e1,
1299 "%s: %8phN lid=FC_NO_LOOP_ID, spi: 0x%x, DS %d, returning NO_CONNECT\n",
1300 __func__, fcport->port_name, sa_frame.spi,
1301 fcport->disc_state);
1303 SET_DID_STATUS(bsg_reply->result, DID_NO_CONNECT);
1307 /* allocate and queue an sa_ctl */
1308 result = qla24xx_check_sadb_avail_slot(bsg_job, fcport, &sa_frame);
1310 /* failure of bsg */
1311 if (result == INVALID_EDIF_SA_INDEX) {
1312 ql_dbg(ql_dbg_edif, vha, 0x70e1,
1313 "%s: %8phN, skipping update.\n",
1314 __func__, fcport->port_name);
1316 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1319 /* rx delete failure */
1320 } else if (result == RX_DELETE_NO_EDIF_SA_INDEX) {
1321 ql_dbg(ql_dbg_edif, vha, 0x70e1,
1322 "%s: %8phN, skipping rx delete.\n",
1323 __func__, fcport->port_name);
1324 SET_DID_STATUS(bsg_reply->result, DID_OK);
1328 ql_dbg(ql_dbg_edif, vha, 0x70e1,
1329 "%s: %8phN, sa_index in sa_frame: %d flags %xh\n",
1330 __func__, fcport->port_name, sa_frame.fast_sa_index,
1333 /* looking for rx index and delete */
1334 if (((sa_frame.flags & SAU_FLG_TX) == 0) &&
1335 (sa_frame.flags & SAU_FLG_INV)) {
1336 uint16_t nport_handle = fcport->loop_id;
1337 uint16_t sa_index = sa_frame.fast_sa_index;
1340 * make sure we have an existing rx key, otherwise just process
1341 * this as a straight delete just like TX
1342 * This is NOT a normal case, it indicates an error recovery or key cleanup
1343 * by the ipsec code above us.
1345 edif_entry = qla_edif_list_find_sa_index(fcport, fcport->loop_id);
1347 ql_dbg(ql_dbg_edif, vha, 0x911d,
1348 "%s: WARNING: no active sa_index for nport_handle 0x%x, forcing delete for sa_index 0x%x\n",
1349 __func__, fcport->loop_id, sa_index);
1350 goto force_rx_delete;
1354 * if we have a forced delete for rx, remove the sa_index from the edif list
1355 * and proceed with normal delete. The rx delay timer should not be running
1357 if ((sa_frame.flags & SAU_FLG_FORCE_DELETE) == SAU_FLG_FORCE_DELETE) {
1358 qla_edif_list_delete_sa_index(fcport, edif_entry);
1359 ql_dbg(ql_dbg_edif, vha, 0x911d,
1360 "%s: FORCE DELETE flag found for nport_handle 0x%x, sa_index 0x%x, forcing DELETE\n",
1361 __func__, fcport->loop_id, sa_index);
1363 goto force_rx_delete;
1369 * if delete_sa_index is not invalid then there is already
1370 * a delayed index in progress, return bsg bad status
1372 if (edif_entry->delete_sa_index != INVALID_EDIF_SA_INDEX) {
1373 struct edif_sa_ctl *sa_ctl;
1375 ql_dbg(ql_dbg_edif, vha, 0x911d,
1376 "%s: delete for lid 0x%x, delete_sa_index %d is pending\n",
1377 __func__, edif_entry->handle, edif_entry->delete_sa_index);
1379 /* free up the sa_ctl that was allocated with the sa_index */
1380 sa_ctl = qla_edif_find_sa_ctl_by_index(fcport, sa_index,
1381 (sa_frame.flags & SAU_FLG_TX));
1383 ql_dbg(ql_dbg_edif, vha, 0x3063,
1384 "%s: freeing sa_ctl for index %d\n",
1385 __func__, sa_ctl->index);
1386 qla_edif_free_sa_ctl(fcport, sa_ctl, sa_ctl->index);
1389 /* release the sa_index */
1390 ql_dbg(ql_dbg_edif, vha, 0x3063,
1391 "%s: freeing sa_index %d, nph: 0x%x\n",
1392 __func__, sa_index, nport_handle);
1393 qla_edif_sadb_delete_sa_index(fcport, nport_handle, sa_index);
1396 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
1400 fcport->edif.rekey_cnt++;
1402 /* configure and start the rx delay timer */
1403 edif_entry->fcport = fcport;
1404 edif_entry->timer.expires = jiffies + RX_DELAY_DELETE_TIMEOUT * HZ;
1406 ql_dbg(ql_dbg_edif, vha, 0x911d,
1407 "%s: adding timer, entry: %p, delete sa_index %d, lid 0x%x to edif_list\n",
1408 __func__, edif_entry, sa_index, nport_handle);
1411 * Start the timer when we queue the delayed rx delete.
1412 * This is an activity timer that goes off if we have not
1413 * received packets with the new sa_index
1415 add_timer(&edif_entry->timer);
1418 * sa_delete for rx key with an active rx key including this one
1419 * add the delete rx sa index to the hash so we can look for it
1420 * in the rsp queue. Do this after making any changes to the
1421 * edif_entry as part of the rx delete.
1424 ql_dbg(ql_dbg_edif, vha, 0x911d,
1425 "%s: delete sa_index %d, lid 0x%x to edif_list. bsg done ptr %p\n",
1426 __func__, sa_index, nport_handle, bsg_job);
1428 edif_entry->delete_sa_index = sa_index;
1430 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1431 bsg_reply->result = DID_OK << 16;
1436 * rx index and update
1437 * add the index to the list and continue with normal update
1439 } else if (((sa_frame.flags & SAU_FLG_TX) == 0) &&
1440 ((sa_frame.flags & SAU_FLG_INV) == 0)) {
1441 /* sa_update for rx key */
1442 uint32_t nport_handle = fcport->loop_id;
1443 uint16_t sa_index = sa_frame.fast_sa_index;
1447 * add the update rx sa index to the hash so we can look for it
1448 * in the rsp queue and continue normally
1451 ql_dbg(ql_dbg_edif, vha, 0x911d,
1452 "%s: adding update sa_index %d, lid 0x%x to edif_list\n",
1453 __func__, sa_index, nport_handle);
1455 result = qla_edif_list_add_sa_update_index(fcport, sa_index,
1458 ql_dbg(ql_dbg_edif, vha, 0x911d,
1459 "%s: SA_UPDATE failed to add new sa index %d to list for lid 0x%x\n",
1460 __func__, sa_index, nport_handle);
1463 if (sa_frame.flags & SAU_FLG_GMAC_MODE)
1464 fcport->edif.aes_gmac = 1;
1466 fcport->edif.aes_gmac = 0;
1470 * sa_update for both rx and tx keys, sa_delete for tx key
1471 * immediately process the request
1473 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1476 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
1480 sp->type = SRB_SA_UPDATE;
1481 sp->name = "bsg_sa_update";
1482 sp->u.bsg_job = bsg_job;
1483 /* sp->free = qla2x00_bsg_sp_free; */
1484 sp->free = qla2x00_rel_sp;
1485 sp->done = qla2x00_bsg_job_done;
1486 iocb_cmd = &sp->u.iocb_cmd;
1487 iocb_cmd->u.sa_update.sa_frame = sa_frame;
1489 rval = qla2x00_start_sp(sp);
1490 if (rval != QLA_SUCCESS) {
1491 ql_log(ql_dbg_edif, vha, 0x70e3,
1492 "qla2x00_start_sp failed=%d.\n", rval);
1496 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
1500 ql_dbg(ql_dbg_edif, vha, 0x911d,
1501 "%s: %s sent, hdl=%x, portid=%06x.\n",
1502 __func__, sp->name, sp->handle, fcport->d_id.b24);
1504 fcport->edif.rekey_cnt++;
1505 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1506 SET_DID_STATUS(bsg_reply->result, DID_OK);
1511 * send back error status
1514 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1515 ql_dbg(ql_dbg_edif, vha, 0x911d,
1516 "%s:status: FAIL, result: 0x%x, bsg ptr done %p\n",
1517 __func__, bsg_reply->result, bsg_job);
1518 bsg_job_done(bsg_job, bsg_reply->result,
1519 bsg_reply->reply_payload_rcv_len);
1525 qla_enode_free(scsi_qla_host_t *vha, struct enode *node)
1527 node->ntype = N_UNDEF;
1532 * qla_enode_init - initialize enode structs & lock
1533 * @vha: host adapter pointer
1535 * should only be called when driver attaching
1538 qla_enode_init(scsi_qla_host_t *vha)
1540 struct qla_hw_data *ha = vha->hw;
1543 if (vha->pur_cinfo.enode_flags == ENODE_ACTIVE) {
1544 /* list still active - error */
1545 ql_dbg(ql_dbg_edif, vha, 0x09102, "%s enode still active\n",
1550 /* initialize lock which protects pur_core & init list */
1551 spin_lock_init(&vha->pur_cinfo.pur_lock);
1552 INIT_LIST_HEAD(&vha->pur_cinfo.head);
1554 snprintf(name, sizeof(name), "%s_%d_purex", QLA2XXX_DRIVER_NAME,
1559 * qla_enode_stop - stop and clear and enode data
1560 * @vha: host adapter pointer
1562 * called when app notified it is exiting
1565 qla_enode_stop(scsi_qla_host_t *vha)
1567 unsigned long flags;
1568 struct enode *node, *q;
1570 if (vha->pur_cinfo.enode_flags != ENODE_ACTIVE) {
1571 /* doorbell list not enabled */
1572 ql_dbg(ql_dbg_edif, vha, 0x09102,
1573 "%s enode not active\n", __func__);
1577 /* grab lock so list doesn't move */
1578 spin_lock_irqsave(&vha->pur_cinfo.pur_lock, flags);
1580 vha->pur_cinfo.enode_flags &= ~ENODE_ACTIVE; /* mark it not active */
1582 /* hopefully this is a null list at this point */
1583 list_for_each_entry_safe(node, q, &vha->pur_cinfo.head, list) {
1584 ql_dbg(ql_dbg_edif, vha, 0x910f,
1585 "%s freeing enode type=%x, cnt=%x\n", __func__, node->ntype,
1586 node->dinfo.nodecnt);
1587 list_del_init(&node->list);
1588 qla_enode_free(vha, node);
1590 spin_unlock_irqrestore(&vha->pur_cinfo.pur_lock, flags);
1593 static void qla_enode_clear(scsi_qla_host_t *vha, port_id_t portid)
1595 unsigned long flags;
1596 struct enode *e, *tmp;
1597 struct purexevent *purex;
1598 LIST_HEAD(enode_list);
1600 if (vha->pur_cinfo.enode_flags != ENODE_ACTIVE) {
1601 ql_dbg(ql_dbg_edif, vha, 0x09102,
1602 "%s enode not active\n", __func__);
1605 spin_lock_irqsave(&vha->pur_cinfo.pur_lock, flags);
1606 list_for_each_entry_safe(e, tmp, &vha->pur_cinfo.head, list) {
1607 purex = &e->u.purexinfo;
1608 if (purex->pur_info.pur_sid.b24 == portid.b24) {
1609 ql_dbg(ql_dbg_edif, vha, 0x911d,
1610 "%s free ELS sid=%06x. xchg %x, nb=%xh\n",
1611 __func__, portid.b24,
1612 purex->pur_info.pur_rx_xchg_address,
1613 purex->pur_info.pur_bytes_rcvd);
1615 list_del_init(&e->list);
1616 list_add_tail(&e->list, &enode_list);
1619 spin_unlock_irqrestore(&vha->pur_cinfo.pur_lock, flags);
1621 list_for_each_entry_safe(e, tmp, &enode_list, list) {
1622 list_del_init(&e->list);
1623 qla_enode_free(vha, e);
1628 * allocate enode struct and populate buffer
1629 * returns: enode pointer with buffers
1632 static struct enode *
1633 qla_enode_alloc(scsi_qla_host_t *vha, uint32_t ntype)
1636 struct purexevent *purex;
1638 node = kzalloc(RX_ELS_SIZE, GFP_ATOMIC);
1642 purex = &node->u.purexinfo;
1643 purex->msgp = (u8 *)(node + 1);
1644 purex->msgp_len = ELS_MAX_PAYLOAD;
1646 node->ntype = ntype;
1647 INIT_LIST_HEAD(&node->list);
1652 qla_enode_add(scsi_qla_host_t *vha, struct enode *ptr)
1654 unsigned long flags;
1656 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x9109,
1657 "%s add enode for type=%x, cnt=%x\n",
1658 __func__, ptr->ntype, ptr->dinfo.nodecnt);
1660 spin_lock_irqsave(&vha->pur_cinfo.pur_lock, flags);
1661 list_add_tail(&ptr->list, &vha->pur_cinfo.head);
1662 spin_unlock_irqrestore(&vha->pur_cinfo.pur_lock, flags);
1667 static struct enode *
1668 qla_enode_find(scsi_qla_host_t *vha, uint32_t ntype, uint32_t p1, uint32_t p2)
1670 struct enode *node_rtn = NULL;
1671 struct enode *list_node, *q;
1672 unsigned long flags;
1674 struct purexevent *purex;
1676 /* secure the list from moving under us */
1677 spin_lock_irqsave(&vha->pur_cinfo.pur_lock, flags);
1679 list_for_each_entry_safe(list_node, q, &vha->pur_cinfo.head, list) {
1681 /* node type determines what p1 and p2 are */
1682 purex = &list_node->u.purexinfo;
1685 if (purex->pur_info.pur_sid.b24 == sid) {
1686 /* found it and its complete */
1687 node_rtn = list_node;
1688 list_del(&list_node->list);
1693 spin_unlock_irqrestore(&vha->pur_cinfo.pur_lock, flags);
1699 * qla_pur_get_pending - read/return authentication message sent
1701 * @vha: host adapter pointer
1702 * @fcport: session pointer
1703 * @bsg_job: user request where the message is copy to.
1706 qla_pur_get_pending(scsi_qla_host_t *vha, fc_port_t *fcport,
1707 struct bsg_job *bsg_job)
1710 struct purexevent *purex;
1711 struct qla_bsg_auth_els_reply *rpl =
1712 (struct qla_bsg_auth_els_reply *)bsg_job->reply;
1714 bsg_job->reply_len = sizeof(*rpl);
1716 ptr = qla_enode_find(vha, N_PUREX, fcport->d_id.b24, PUR_GET);
1718 ql_dbg(ql_dbg_edif, vha, 0x9111,
1719 "%s no enode data found for %8phN sid=%06x\n",
1720 __func__, fcport->port_name, fcport->d_id.b24);
1721 SET_DID_STATUS(rpl->r.result, DID_IMM_RETRY);
1726 * enode is now off the linked list and is ours to deal with
1728 purex = &ptr->u.purexinfo;
1730 /* Copy info back to caller */
1731 rpl->rx_xchg_address = purex->pur_info.pur_rx_xchg_address;
1733 SET_DID_STATUS(rpl->r.result, DID_OK);
1734 rpl->r.reply_payload_rcv_len =
1735 sg_pcopy_from_buffer(bsg_job->reply_payload.sg_list,
1736 bsg_job->reply_payload.sg_cnt, purex->msgp,
1737 purex->pur_info.pur_bytes_rcvd, 0);
1739 /* data copy / passback completed - destroy enode */
1740 qla_enode_free(vha, ptr);
1745 /* it is assume qpair lock is held */
1747 qla_els_reject_iocb(scsi_qla_host_t *vha, struct qla_qpair *qp,
1748 struct qla_els_pt_arg *a)
1750 struct els_entry_24xx *els_iocb;
1752 els_iocb = __qla2x00_alloc_iocbs(qp, NULL);
1754 ql_log(ql_log_warn, vha, 0x700c,
1755 "qla2x00_alloc_iocbs failed.\n");
1756 return QLA_FUNCTION_FAILED;
1759 qla_els_pt_iocb(vha, els_iocb, a);
1761 ql_dbg(ql_dbg_edif, vha, 0x0183,
1762 "Sending ELS reject ox_id %04x s:%06x -> d:%06x\n",
1763 a->ox_id, a->sid.b24, a->did.b24);
1764 ql_dump_buffer(ql_dbg_edif + ql_dbg_verbose, vha, 0x0185,
1765 vha->hw->elsrej.c, sizeof(*vha->hw->elsrej.c));
1766 /* flush iocb to mem before notifying hw doorbell */
1768 qla2x00_start_iocbs(vha, qp->req);
1773 qla_edb_init(scsi_qla_host_t *vha)
1775 if (DBELL_ACTIVE(vha)) {
1776 /* list already init'd - error */
1777 ql_dbg(ql_dbg_edif, vha, 0x09102,
1778 "edif db already initialized, cannot reinit\n");
1782 /* initialize lock which protects doorbell & init list */
1783 spin_lock_init(&vha->e_dbell.db_lock);
1784 INIT_LIST_HEAD(&vha->e_dbell.head);
1786 /* create and initialize doorbell */
1787 init_completion(&vha->e_dbell.dbell);
1791 qla_edb_node_free(scsi_qla_host_t *vha, struct edb_node *node)
1794 * releases the space held by this edb node entry
1795 * this function does _not_ free the edb node itself
1796 * NB: the edb node entry passed should not be on any list
1798 * currently for doorbell there's no additional cleanup
1799 * needed, but here as a placeholder for furture use.
1803 ql_dbg(ql_dbg_edif, vha, 0x09122,
1804 "%s error - no valid node passed\n", __func__);
1808 node->ntype = N_UNDEF;
1811 static void qla_edb_clear(scsi_qla_host_t *vha, port_id_t portid)
1813 unsigned long flags;
1814 struct edb_node *e, *tmp;
1816 LIST_HEAD(edb_list);
1818 if (DBELL_INACTIVE(vha)) {
1819 /* doorbell list not enabled */
1820 ql_dbg(ql_dbg_edif, vha, 0x09102,
1821 "%s doorbell not enabled\n", __func__);
1825 /* grab lock so list doesn't move */
1826 spin_lock_irqsave(&vha->e_dbell.db_lock, flags);
1827 list_for_each_entry_safe(e, tmp, &vha->e_dbell.head, list) {
1829 case VND_CMD_AUTH_STATE_NEEDED:
1830 case VND_CMD_AUTH_STATE_SESSION_SHUTDOWN:
1831 sid = e->u.plogi_did;
1833 case VND_CMD_AUTH_STATE_ELS_RCVD:
1836 case VND_CMD_AUTH_STATE_SAUPDATE_COMPL:
1837 /* app wants to see this */
1840 ql_log(ql_log_warn, vha, 0x09102,
1841 "%s unknown node type: %x\n", __func__, e->ntype);
1845 if (sid.b24 == portid.b24) {
1846 ql_dbg(ql_dbg_edif, vha, 0x910f,
1847 "%s free doorbell event : node type = %x %p\n",
1848 __func__, e->ntype, e);
1849 list_del_init(&e->list);
1850 list_add_tail(&e->list, &edb_list);
1853 spin_unlock_irqrestore(&vha->e_dbell.db_lock, flags);
1855 list_for_each_entry_safe(e, tmp, &edb_list, list) {
1856 qla_edb_node_free(vha, e);
1857 list_del_init(&e->list);
1862 /* function called when app is stopping */
1865 qla_edb_stop(scsi_qla_host_t *vha)
1867 unsigned long flags;
1868 struct edb_node *node, *q;
1870 if (DBELL_INACTIVE(vha)) {
1871 /* doorbell list not enabled */
1872 ql_dbg(ql_dbg_edif, vha, 0x09102,
1873 "%s doorbell not enabled\n", __func__);
1877 /* grab lock so list doesn't move */
1878 spin_lock_irqsave(&vha->e_dbell.db_lock, flags);
1880 vha->e_dbell.db_flags &= ~EDB_ACTIVE; /* mark it not active */
1881 /* hopefully this is a null list at this point */
1882 list_for_each_entry_safe(node, q, &vha->e_dbell.head, list) {
1883 ql_dbg(ql_dbg_edif, vha, 0x910f,
1884 "%s freeing edb_node type=%x\n",
1885 __func__, node->ntype);
1886 qla_edb_node_free(vha, node);
1887 list_del(&node->list);
1891 spin_unlock_irqrestore(&vha->e_dbell.db_lock, flags);
1893 /* wake up doorbell waiters - they'll be dismissed with error code */
1894 complete_all(&vha->e_dbell.dbell);
1897 static struct edb_node *
1898 qla_edb_node_alloc(scsi_qla_host_t *vha, uint32_t ntype)
1900 struct edb_node *node;
1902 node = kzalloc(sizeof(*node), GFP_ATOMIC);
1904 /* couldn't get space */
1905 ql_dbg(ql_dbg_edif, vha, 0x9100,
1906 "edb node unable to be allocated\n");
1910 node->ntype = ntype;
1911 INIT_LIST_HEAD(&node->list);
1915 /* adds a already allocated enode to the linked list */
1917 qla_edb_node_add(scsi_qla_host_t *vha, struct edb_node *ptr)
1919 unsigned long flags;
1921 if (DBELL_INACTIVE(vha)) {
1922 /* doorbell list not enabled */
1923 ql_dbg(ql_dbg_edif, vha, 0x09102,
1924 "%s doorbell not enabled\n", __func__);
1928 spin_lock_irqsave(&vha->e_dbell.db_lock, flags);
1929 list_add_tail(&ptr->list, &vha->e_dbell.head);
1930 spin_unlock_irqrestore(&vha->e_dbell.db_lock, flags);
1932 /* ring doorbell for waiters */
1933 complete(&vha->e_dbell.dbell);
1938 /* adds event to doorbell list */
1940 qla_edb_eventcreate(scsi_qla_host_t *vha, uint32_t dbtype,
1941 uint32_t data, uint32_t data2, fc_port_t *sfcport)
1943 struct edb_node *edbnode;
1944 fc_port_t *fcport = sfcport;
1947 if (!vha->hw->flags.edif_enabled) {
1948 /* edif not enabled */
1952 if (DBELL_INACTIVE(vha)) {
1954 fcport->edif.auth_state = dbtype;
1955 /* doorbell list not enabled */
1956 ql_dbg(ql_dbg_edif, vha, 0x09102,
1957 "%s doorbell not enabled (type=%d\n", __func__, dbtype);
1961 edbnode = qla_edb_node_alloc(vha, dbtype);
1963 ql_dbg(ql_dbg_edif, vha, 0x09102,
1964 "%s unable to alloc db node\n", __func__);
1969 id.b.domain = (data >> 16) & 0xff;
1970 id.b.area = (data >> 8) & 0xff;
1971 id.b.al_pa = data & 0xff;
1972 ql_dbg(ql_dbg_edif, vha, 0x09222,
1973 "%s: Arrived s_id: %06x\n", __func__,
1975 fcport = qla2x00_find_fcport_by_pid(vha, &id);
1977 ql_dbg(ql_dbg_edif, vha, 0x09102,
1978 "%s can't find fcport for sid= 0x%x - ignoring\n",
1985 /* populate the edb node */
1987 case VND_CMD_AUTH_STATE_NEEDED:
1988 case VND_CMD_AUTH_STATE_SESSION_SHUTDOWN:
1989 edbnode->u.plogi_did.b24 = fcport->d_id.b24;
1991 case VND_CMD_AUTH_STATE_ELS_RCVD:
1992 edbnode->u.els_sid.b24 = fcport->d_id.b24;
1994 case VND_CMD_AUTH_STATE_SAUPDATE_COMPL:
1995 edbnode->u.sa_aen.port_id = fcport->d_id;
1996 edbnode->u.sa_aen.status = data;
1997 edbnode->u.sa_aen.key_type = data2;
2000 ql_dbg(ql_dbg_edif, vha, 0x09102,
2001 "%s unknown type: %x\n", __func__, dbtype);
2002 qla_edb_node_free(vha, edbnode);
2008 if (edbnode && (!qla_edb_node_add(vha, edbnode))) {
2009 ql_dbg(ql_dbg_edif, vha, 0x09102,
2010 "%s unable to add dbnode\n", __func__);
2011 qla_edb_node_free(vha, edbnode);
2015 if (edbnode && fcport)
2016 fcport->edif.auth_state = dbtype;
2017 ql_dbg(ql_dbg_edif, vha, 0x09102,
2018 "%s Doorbell produced : type=%d %p\n", __func__, dbtype, edbnode);
2021 static struct edb_node *
2022 qla_edb_getnext(scsi_qla_host_t *vha)
2024 unsigned long flags;
2025 struct edb_node *edbnode = NULL;
2027 spin_lock_irqsave(&vha->e_dbell.db_lock, flags);
2029 /* db nodes are fifo - no qualifications done */
2030 if (!list_empty(&vha->e_dbell.head)) {
2031 edbnode = list_first_entry(&vha->e_dbell.head,
2032 struct edb_node, list);
2033 list_del(&edbnode->list);
2036 spin_unlock_irqrestore(&vha->e_dbell.db_lock, flags);
2042 qla_edif_timer(scsi_qla_host_t *vha)
2044 struct qla_hw_data *ha = vha->hw;
2046 if (!vha->vp_idx && N2N_TOPO(ha) && ha->flags.n2n_fw_acc_sec) {
2047 if (DBELL_INACTIVE(vha) &&
2048 ha->edif_post_stop_cnt_down) {
2049 ha->edif_post_stop_cnt_down--;
2052 * turn off auto 'Plogi Acc + secure=1' feature
2053 * Set Add FW option[3]
2056 if (ha->edif_post_stop_cnt_down == 0) {
2057 ql_dbg(ql_dbg_async, vha, 0x911d,
2058 "%s chip reset to turn off PLOGI ACC + secure\n",
2060 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2063 ha->edif_post_stop_cnt_down = 60;
2069 * app uses separate thread to read this. It'll wait until the doorbell
2070 * is rung by the driver or the max wait time has expired
2073 edif_doorbell_show(struct device *dev, struct device_attribute *attr,
2076 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2077 struct edb_node *dbnode = NULL;
2078 struct edif_app_dbell *ap = (struct edif_app_dbell *)buf;
2079 uint32_t dat_siz, buf_size, sz;
2081 /* TODO: app currently hardcoded to 256. Will transition to bsg */
2084 /* stop new threads from waiting if we're not init'd */
2085 if (DBELL_INACTIVE(vha)) {
2086 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x09122,
2087 "%s error - edif db not enabled\n", __func__);
2091 if (!vha->hw->flags.edif_enabled) {
2092 /* edif not enabled */
2093 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x09122,
2094 "%s error - edif not enabled\n", __func__);
2099 while ((sz - buf_size) >= sizeof(struct edb_node)) {
2100 /* remove the next item from the doorbell list */
2102 dbnode = qla_edb_getnext(vha);
2104 ap->event_code = dbnode->ntype;
2105 switch (dbnode->ntype) {
2106 case VND_CMD_AUTH_STATE_SESSION_SHUTDOWN:
2107 case VND_CMD_AUTH_STATE_NEEDED:
2108 ap->port_id = dbnode->u.plogi_did;
2109 dat_siz += sizeof(ap->port_id);
2111 case VND_CMD_AUTH_STATE_ELS_RCVD:
2112 ap->port_id = dbnode->u.els_sid;
2113 dat_siz += sizeof(ap->port_id);
2115 case VND_CMD_AUTH_STATE_SAUPDATE_COMPL:
2116 ap->port_id = dbnode->u.sa_aen.port_id;
2117 memcpy(ap->event_data, &dbnode->u,
2118 sizeof(struct edif_sa_update_aen));
2119 dat_siz += sizeof(struct edif_sa_update_aen);
2122 /* unknown node type, rtn unknown ntype */
2123 ap->event_code = VND_CMD_AUTH_STATE_UNDEF;
2124 memcpy(ap->event_data, &dbnode->ntype, 4);
2129 ql_dbg(ql_dbg_edif, vha, 0x09102,
2130 "%s Doorbell consumed : type=%d %p\n",
2131 __func__, dbnode->ntype, dbnode);
2132 /* we're done with the db node, so free it up */
2133 qla_edb_node_free(vha, dbnode);
2139 ap->event_data_size = dat_siz;
2140 /* 8bytes = ap->event_code + ap->event_data_size */
2141 buf_size += dat_siz + 8;
2142 ap = (struct edif_app_dbell *)(buf + buf_size);
2147 static void qla_noop_sp_done(srb_t *sp, int res)
2153 * Called from work queue
2154 * build and send the sa_update iocb to delete an rx sa_index
2157 qla24xx_issue_sa_replace_iocb(scsi_qla_host_t *vha, struct qla_work_evt *e)
2160 fc_port_t *fcport = NULL;
2161 struct srb_iocb *iocb_cmd = NULL;
2162 int rval = QLA_SUCCESS;
2163 struct edif_sa_ctl *sa_ctl = e->u.sa_update.sa_ctl;
2164 uint16_t nport_handle = e->u.sa_update.nport_handle;
2166 ql_dbg(ql_dbg_edif, vha, 0x70e6,
2167 "%s: starting, sa_ctl: %p\n", __func__, sa_ctl);
2170 ql_dbg(ql_dbg_edif, vha, 0x70e6,
2171 "sa_ctl allocation failed\n");
2175 fcport = sa_ctl->fcport;
2177 /* Alloc SRB structure */
2178 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2180 ql_dbg(ql_dbg_edif, vha, 0x70e6,
2181 "SRB allocation failed\n");
2185 fcport->flags |= FCF_ASYNC_SENT;
2186 iocb_cmd = &sp->u.iocb_cmd;
2187 iocb_cmd->u.sa_update.sa_ctl = sa_ctl;
2189 ql_dbg(ql_dbg_edif, vha, 0x3073,
2190 "Enter: SA REPL portid=%06x, sa_ctl %p, index %x, nport_handle: 0x%x\n",
2191 fcport->d_id.b24, sa_ctl, sa_ctl->index, nport_handle);
2193 * if this is a sadb cleanup delete, mark it so the isr can
2194 * take the correct action
2196 if (sa_ctl->flags & EDIF_SA_CTL_FLG_CLEANUP_DEL) {
2197 /* mark this srb as a cleanup delete */
2198 sp->flags |= SRB_EDIF_CLEANUP_DELETE;
2199 ql_dbg(ql_dbg_edif, vha, 0x70e6,
2200 "%s: sp 0x%p flagged as cleanup delete\n", __func__, sp);
2203 sp->type = SRB_SA_REPLACE;
2204 sp->name = "SA_REPLACE";
2205 sp->fcport = fcport;
2206 sp->free = qla2x00_rel_sp;
2207 sp->done = qla_noop_sp_done;
2209 rval = qla2x00_start_sp(sp);
2211 if (rval != QLA_SUCCESS)
2212 rval = QLA_FUNCTION_FAILED;
2217 void qla24xx_sa_update_iocb(srb_t *sp, struct sa_update_28xx *sa_update_iocb)
2220 struct scsi_qla_host *vha = sp->vha;
2221 struct qla_sa_update_frame *sa_frame =
2222 &sp->u.iocb_cmd.u.sa_update.sa_frame;
2225 switch (sa_frame->flags & (SAU_FLG_INV | SAU_FLG_TX)) {
2227 ql_dbg(ql_dbg_edif, vha, 0x911d,
2228 "%s: EDIF SA UPDATE RX IOCB vha: 0x%p index: %d\n",
2229 __func__, vha, sa_frame->fast_sa_index);
2232 ql_dbg(ql_dbg_edif, vha, 0x911d,
2233 "%s: EDIF SA DELETE RX IOCB vha: 0x%p index: %d\n",
2234 __func__, vha, sa_frame->fast_sa_index);
2235 flags |= SA_FLAG_INVALIDATE;
2238 ql_dbg(ql_dbg_edif, vha, 0x911d,
2239 "%s: EDIF SA UPDATE TX IOCB vha: 0x%p index: %d\n",
2240 __func__, vha, sa_frame->fast_sa_index);
2241 flags |= SA_FLAG_TX;
2244 ql_dbg(ql_dbg_edif, vha, 0x911d,
2245 "%s: EDIF SA DELETE TX IOCB vha: 0x%p index: %d\n",
2246 __func__, vha, sa_frame->fast_sa_index);
2247 flags |= SA_FLAG_TX | SA_FLAG_INVALIDATE;
2251 sa_update_iocb->entry_type = SA_UPDATE_IOCB_TYPE;
2252 sa_update_iocb->entry_count = 1;
2253 sa_update_iocb->sys_define = 0;
2254 sa_update_iocb->entry_status = 0;
2255 sa_update_iocb->handle = sp->handle;
2256 sa_update_iocb->u.nport_handle = cpu_to_le16(sp->fcport->loop_id);
2257 sa_update_iocb->vp_index = sp->fcport->vha->vp_idx;
2258 sa_update_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
2259 sa_update_iocb->port_id[1] = sp->fcport->d_id.b.area;
2260 sa_update_iocb->port_id[2] = sp->fcport->d_id.b.domain;
2262 sa_update_iocb->flags = flags;
2263 sa_update_iocb->salt = cpu_to_le32(sa_frame->salt);
2264 sa_update_iocb->spi = cpu_to_le32(sa_frame->spi);
2265 sa_update_iocb->sa_index = cpu_to_le16(sa_frame->fast_sa_index);
2267 sa_update_iocb->sa_control |= SA_CNTL_ENC_FCSP;
2268 if (sp->fcport->edif.aes_gmac)
2269 sa_update_iocb->sa_control |= SA_CNTL_AES_GMAC;
2271 if (sa_frame->flags & SAU_FLG_KEY256) {
2272 sa_update_iocb->sa_control |= SA_CNTL_KEY256;
2273 for (itr = 0; itr < 32; itr++)
2274 sa_update_iocb->sa_key[itr] = sa_frame->sa_key[itr];
2276 sa_update_iocb->sa_control |= SA_CNTL_KEY128;
2277 for (itr = 0; itr < 16; itr++)
2278 sa_update_iocb->sa_key[itr] = sa_frame->sa_key[itr];
2281 ql_dbg(ql_dbg_edif, vha, 0x921d,
2282 "%s SAU Port ID = %02x%02x%02x, flags=%xh, index=%u, ctl=%xh, SPI 0x%x flags 0x%x hdl=%x gmac %d\n",
2283 __func__, sa_update_iocb->port_id[2], sa_update_iocb->port_id[1],
2284 sa_update_iocb->port_id[0], sa_update_iocb->flags, sa_update_iocb->sa_index,
2285 sa_update_iocb->sa_control, sa_update_iocb->spi, sa_frame->flags, sp->handle,
2286 sp->fcport->edif.aes_gmac);
2288 if (sa_frame->flags & SAU_FLG_TX)
2289 sp->fcport->edif.tx_sa_pending = 1;
2291 sp->fcport->edif.rx_sa_pending = 1;
2293 sp->fcport->vha->qla_stats.control_requests++;
2297 qla24xx_sa_replace_iocb(srb_t *sp, struct sa_update_28xx *sa_update_iocb)
2299 struct scsi_qla_host *vha = sp->vha;
2300 struct srb_iocb *srb_iocb = &sp->u.iocb_cmd;
2301 struct edif_sa_ctl *sa_ctl = srb_iocb->u.sa_update.sa_ctl;
2302 uint16_t nport_handle = sp->fcport->loop_id;
2304 sa_update_iocb->entry_type = SA_UPDATE_IOCB_TYPE;
2305 sa_update_iocb->entry_count = 1;
2306 sa_update_iocb->sys_define = 0;
2307 sa_update_iocb->entry_status = 0;
2308 sa_update_iocb->handle = sp->handle;
2310 sa_update_iocb->u.nport_handle = cpu_to_le16(nport_handle);
2312 sa_update_iocb->vp_index = sp->fcport->vha->vp_idx;
2313 sa_update_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
2314 sa_update_iocb->port_id[1] = sp->fcport->d_id.b.area;
2315 sa_update_iocb->port_id[2] = sp->fcport->d_id.b.domain;
2317 /* Invalidate the index. salt, spi, control & key are ignore */
2318 sa_update_iocb->flags = SA_FLAG_INVALIDATE;
2319 sa_update_iocb->salt = 0;
2320 sa_update_iocb->spi = 0;
2321 sa_update_iocb->sa_index = cpu_to_le16(sa_ctl->index);
2322 sa_update_iocb->sa_control = 0;
2324 ql_dbg(ql_dbg_edif, vha, 0x921d,
2325 "%s SAU DELETE RX Port ID = %02x:%02x:%02x, lid %d flags=%xh, index=%u, hdl=%x\n",
2326 __func__, sa_update_iocb->port_id[2], sa_update_iocb->port_id[1],
2327 sa_update_iocb->port_id[0], nport_handle, sa_update_iocb->flags,
2328 sa_update_iocb->sa_index, sp->handle);
2330 sp->fcport->vha->qla_stats.control_requests++;
2333 void qla24xx_auth_els(scsi_qla_host_t *vha, void **pkt, struct rsp_que **rsp)
2335 struct purex_entry_24xx *p = *pkt;
2339 struct purexevent *purex;
2340 struct scsi_qla_host *host = NULL;
2342 struct fc_port *fcport;
2343 struct qla_els_pt_arg a;
2346 memset(&a, 0, sizeof(a));
2348 a.els_opcode = ELS_AUTH_ELS;
2349 a.nport_handle = p->nport_handle;
2350 a.rx_xchg_address = p->rx_xchg_addr;
2351 a.did.b.domain = p->s_id[2];
2352 a.did.b.area = p->s_id[1];
2353 a.did.b.al_pa = p->s_id[0];
2354 a.tx_byte_count = a.tx_len = sizeof(struct fc_els_ls_rjt);
2355 a.tx_addr = vha->hw->elsrej.cdma;
2356 a.vp_idx = vha->vp_idx;
2357 a.control_flags = EPD_ELS_RJT;
2358 a.ox_id = le16_to_cpu(p->ox_id);
2360 sid = p->s_id[0] | (p->s_id[1] << 8) | (p->s_id[2] << 16);
2362 totlen = (le16_to_cpu(p->frame_size) & 0x0fff) - PURX_ELS_HEADER_SIZE;
2363 if (le16_to_cpu(p->status_flags) & 0x8000) {
2364 totlen = le16_to_cpu(p->trunc_frame_size);
2365 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2366 __qla_consume_iocb(vha, pkt, rsp);
2370 if (totlen > ELS_MAX_PAYLOAD) {
2371 ql_dbg(ql_dbg_edif, vha, 0x0910d,
2372 "%s WARNING: verbose ELS frame received (totlen=%x)\n",
2374 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2375 __qla_consume_iocb(vha, pkt, rsp);
2379 if (!vha->hw->flags.edif_enabled) {
2380 /* edif support not enabled */
2381 ql_dbg(ql_dbg_edif, vha, 0x910e, "%s edif not enabled\n",
2383 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2384 __qla_consume_iocb(vha, pkt, rsp);
2388 ptr = qla_enode_alloc(vha, N_PUREX);
2390 ql_dbg(ql_dbg_edif, vha, 0x09109,
2391 "WARNING: enode alloc failed for sid=%x\n",
2393 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2394 __qla_consume_iocb(vha, pkt, rsp);
2398 purex = &ptr->u.purexinfo;
2399 purex->pur_info.pur_sid = a.did;
2400 purex->pur_info.pur_bytes_rcvd = totlen;
2401 purex->pur_info.pur_rx_xchg_address = le32_to_cpu(p->rx_xchg_addr);
2402 purex->pur_info.pur_nphdl = le16_to_cpu(p->nport_handle);
2403 purex->pur_info.pur_did.b.domain = p->d_id[2];
2404 purex->pur_info.pur_did.b.area = p->d_id[1];
2405 purex->pur_info.pur_did.b.al_pa = p->d_id[0];
2406 purex->pur_info.vp_idx = p->vp_idx;
2408 a.sid = purex->pur_info.pur_did;
2410 rc = __qla_copy_purex_to_buffer(vha, pkt, rsp, purex->msgp,
2413 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2414 qla_enode_free(vha, ptr);
2417 beid.al_pa = purex->pur_info.pur_did.b.al_pa;
2418 beid.area = purex->pur_info.pur_did.b.area;
2419 beid.domain = purex->pur_info.pur_did.b.domain;
2420 host = qla_find_host_by_d_id(vha, beid);
2422 ql_log(ql_log_fatal, vha, 0x508b,
2423 "%s Drop ELS due to unable to find host %06x\n",
2424 __func__, purex->pur_info.pur_did.b24);
2426 qla_els_reject_iocb(vha, (*rsp)->qpair, &a);
2427 qla_enode_free(vha, ptr);
2431 fcport = qla2x00_find_fcport_by_pid(host, &purex->pur_info.pur_sid);
2433 if (DBELL_INACTIVE(vha) ||
2434 (fcport && EDIF_SESSION_DOWN(fcport))) {
2435 ql_dbg(ql_dbg_edif, host, 0x0910c, "%s e_dbell.db_flags =%x %06x\n",
2436 __func__, host->e_dbell.db_flags,
2437 fcport ? fcport->d_id.b24 : 0);
2439 qla_els_reject_iocb(host, (*rsp)->qpair, &a);
2440 qla_enode_free(host, ptr);
2444 /* add the local enode to the list */
2445 qla_enode_add(host, ptr);
2447 ql_dbg(ql_dbg_edif, host, 0x0910c,
2448 "%s COMPLETE purex->pur_info.pur_bytes_rcvd =%xh s:%06x -> d:%06x xchg=%xh\n",
2449 __func__, purex->pur_info.pur_bytes_rcvd, purex->pur_info.pur_sid.b24,
2450 purex->pur_info.pur_did.b24, purex->pur_info.pur_rx_xchg_address);
2452 qla_edb_eventcreate(host, VND_CMD_AUTH_STATE_ELS_RCVD, sid, 0, NULL);
2455 static uint16_t qla_edif_get_sa_index_from_freepool(fc_port_t *fcport, int dir)
2457 struct scsi_qla_host *vha = fcport->vha;
2458 struct qla_hw_data *ha = vha->hw;
2460 unsigned long flags = 0;
2463 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x3063,
2464 "%s: entry\n", __func__);
2467 sa_id_map = ha->edif_tx_sa_id_map;
2469 sa_id_map = ha->edif_rx_sa_id_map;
2471 spin_lock_irqsave(&ha->sadb_fp_lock, flags);
2472 sa_index = find_first_zero_bit(sa_id_map, EDIF_NUM_SA_INDEX);
2473 if (sa_index >= EDIF_NUM_SA_INDEX) {
2474 spin_unlock_irqrestore(&ha->sadb_fp_lock, flags);
2475 return INVALID_EDIF_SA_INDEX;
2477 set_bit(sa_index, sa_id_map);
2478 spin_unlock_irqrestore(&ha->sadb_fp_lock, flags);
2481 sa_index += EDIF_TX_SA_INDEX_BASE;
2483 ql_dbg(ql_dbg_edif, vha, 0x3063,
2484 "%s: index retrieved from free pool %d\n", __func__, sa_index);
2489 /* find an sadb entry for an nport_handle */
2490 static struct edif_sa_index_entry *
2491 qla_edif_sadb_find_sa_index_entry(uint16_t nport_handle,
2492 struct list_head *sa_list)
2494 struct edif_sa_index_entry *entry;
2495 struct edif_sa_index_entry *tentry;
2496 struct list_head *indx_list = sa_list;
2498 list_for_each_entry_safe(entry, tentry, indx_list, next) {
2499 if (entry->handle == nport_handle)
2505 /* remove an sa_index from the nport_handle and return it to the free pool */
2506 static int qla_edif_sadb_delete_sa_index(fc_port_t *fcport, uint16_t nport_handle,
2509 struct edif_sa_index_entry *entry;
2510 struct list_head *sa_list;
2511 int dir = (sa_index < EDIF_TX_SA_INDEX_BASE) ? 0 : 1;
2513 int free_slot_count = 0;
2514 scsi_qla_host_t *vha = fcport->vha;
2515 struct qla_hw_data *ha = vha->hw;
2516 unsigned long flags = 0;
2518 ql_dbg(ql_dbg_edif, vha, 0x3063,
2519 "%s: entry\n", __func__);
2522 sa_list = &ha->sadb_tx_index_list;
2524 sa_list = &ha->sadb_rx_index_list;
2526 entry = qla_edif_sadb_find_sa_index_entry(nport_handle, sa_list);
2528 ql_dbg(ql_dbg_edif, vha, 0x3063,
2529 "%s: no entry found for nport_handle 0x%x\n",
2530 __func__, nport_handle);
2534 spin_lock_irqsave(&ha->sadb_lock, flags);
2536 * each tx/rx direction has up to 2 sa indexes/slots. 1 slot for in flight traffic
2537 * the other is use at re-key time.
2539 for (slot = 0; slot < 2; slot++) {
2540 if (entry->sa_pair[slot].sa_index == sa_index) {
2541 entry->sa_pair[slot].sa_index = INVALID_EDIF_SA_INDEX;
2542 entry->sa_pair[slot].spi = 0;
2544 qla_edif_add_sa_index_to_freepool(fcport, dir, sa_index);
2545 } else if (entry->sa_pair[slot].sa_index == INVALID_EDIF_SA_INDEX) {
2550 if (free_slot_count == 2) {
2551 list_del(&entry->next);
2554 spin_unlock_irqrestore(&ha->sadb_lock, flags);
2556 ql_dbg(ql_dbg_edif, vha, 0x3063,
2557 "%s: sa_index %d removed, free_slot_count: %d\n",
2558 __func__, sa_index, free_slot_count);
2564 qla28xx_sa_update_iocb_entry(scsi_qla_host_t *v, struct req_que *req,
2565 struct sa_update_28xx *pkt)
2567 const char *func = "SA_UPDATE_RESPONSE_IOCB";
2569 struct edif_sa_ctl *sa_ctl;
2570 int old_sa_deleted = 1;
2571 uint16_t nport_handle;
2572 struct scsi_qla_host *vha;
2574 sp = qla2x00_get_sp_from_handle(v, func, req, pkt);
2577 ql_dbg(ql_dbg_edif, v, 0x3063,
2578 "%s: no sp found for pkt\n", __func__);
2581 /* use sp->vha due to npiv */
2584 switch (pkt->flags & (SA_FLAG_INVALIDATE | SA_FLAG_TX)) {
2586 ql_dbg(ql_dbg_edif, vha, 0x3063,
2587 "%s: EDIF SA UPDATE RX IOCB vha: 0x%p index: %d\n",
2588 __func__, vha, pkt->sa_index);
2591 ql_dbg(ql_dbg_edif, vha, 0x3063,
2592 "%s: EDIF SA DELETE RX IOCB vha: 0x%p index: %d\n",
2593 __func__, vha, pkt->sa_index);
2596 ql_dbg(ql_dbg_edif, vha, 0x3063,
2597 "%s: EDIF SA UPDATE TX IOCB vha: 0x%p index: %d\n",
2598 __func__, vha, pkt->sa_index);
2601 ql_dbg(ql_dbg_edif, vha, 0x3063,
2602 "%s: EDIF SA DELETE TX IOCB vha: 0x%p index: %d\n",
2603 __func__, vha, pkt->sa_index);
2608 * dig the nport handle out of the iocb, fcport->loop_id can not be trusted
2609 * to be correct during cleanup sa_update iocbs.
2611 nport_handle = sp->fcport->loop_id;
2613 ql_dbg(ql_dbg_edif, vha, 0x3063,
2614 "%s: %8phN comp status=%x old_sa_info=%x new_sa_info=%x lid %d, index=0x%x pkt_flags %xh hdl=%x\n",
2615 __func__, sp->fcport->port_name, pkt->u.comp_sts, pkt->old_sa_info, pkt->new_sa_info,
2616 nport_handle, pkt->sa_index, pkt->flags, sp->handle);
2618 /* if rx delete, remove the timer */
2619 if ((pkt->flags & (SA_FLAG_INVALIDATE | SA_FLAG_TX)) == SA_FLAG_INVALIDATE) {
2620 struct edif_list_entry *edif_entry;
2622 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
2624 edif_entry = qla_edif_list_find_sa_index(sp->fcport, nport_handle);
2626 ql_dbg(ql_dbg_edif, vha, 0x5033,
2627 "%s: removing edif_entry %p, new sa_index: 0x%x\n",
2628 __func__, edif_entry, pkt->sa_index);
2629 qla_edif_list_delete_sa_index(sp->fcport, edif_entry);
2630 del_timer(&edif_entry->timer);
2632 ql_dbg(ql_dbg_edif, vha, 0x5033,
2633 "%s: releasing edif_entry %p, new sa_index: 0x%x\n",
2634 __func__, edif_entry, pkt->sa_index);
2641 * if this is a delete for either tx or rx, make sure it succeeded.
2642 * The new_sa_info field should be 0xffff on success
2644 if (pkt->flags & SA_FLAG_INVALIDATE)
2645 old_sa_deleted = (le16_to_cpu(pkt->new_sa_info) == 0xffff) ? 1 : 0;
2647 /* Process update and delete the same way */
2649 /* If this is an sadb cleanup delete, bypass sending events to IPSEC */
2650 if (sp->flags & SRB_EDIF_CLEANUP_DELETE) {
2651 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
2652 ql_dbg(ql_dbg_edif, vha, 0x3063,
2653 "%s: nph 0x%x, sa_index %d removed from fw\n",
2654 __func__, sp->fcport->loop_id, pkt->sa_index);
2656 } else if ((pkt->entry_status == 0) && (pkt->u.comp_sts == 0) &&
2659 * Note: Wa are only keeping track of latest SA,
2660 * so we know when we can start enableing encryption per I/O.
2661 * If all SA's get deleted, let FW reject the IOCB.
2663 * TODO: edif: don't set enabled here I think
2664 * TODO: edif: prli complete is where it should be set
2666 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x3063,
2667 "SA(%x)updated for s_id %02x%02x%02x\n",
2669 pkt->port_id[2], pkt->port_id[1], pkt->port_id[0]);
2670 sp->fcport->edif.enable = 1;
2671 if (pkt->flags & SA_FLAG_TX) {
2672 sp->fcport->edif.tx_sa_set = 1;
2673 sp->fcport->edif.tx_sa_pending = 0;
2674 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
2675 QL_VND_SA_STAT_SUCCESS,
2676 QL_VND_TX_SA_KEY, sp->fcport);
2678 sp->fcport->edif.rx_sa_set = 1;
2679 sp->fcport->edif.rx_sa_pending = 0;
2680 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
2681 QL_VND_SA_STAT_SUCCESS,
2682 QL_VND_RX_SA_KEY, sp->fcport);
2685 ql_dbg(ql_dbg_edif, vha, 0x3063,
2686 "%s: %8phN SA update FAILED: sa_index: %d, new_sa_info %d, %02x%02x%02x\n",
2687 __func__, sp->fcport->port_name, pkt->sa_index, pkt->new_sa_info,
2688 pkt->port_id[2], pkt->port_id[1], pkt->port_id[0]);
2690 if (pkt->flags & SA_FLAG_TX)
2691 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
2692 (le16_to_cpu(pkt->u.comp_sts) << 16) | QL_VND_SA_STAT_FAILED,
2693 QL_VND_TX_SA_KEY, sp->fcport);
2695 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_SAUPDATE_COMPL,
2696 (le16_to_cpu(pkt->u.comp_sts) << 16) | QL_VND_SA_STAT_FAILED,
2697 QL_VND_RX_SA_KEY, sp->fcport);
2700 /* for delete, release sa_ctl, sa_index */
2701 if (pkt->flags & SA_FLAG_INVALIDATE) {
2702 /* release the sa_ctl */
2703 sa_ctl = qla_edif_find_sa_ctl_by_index(sp->fcport,
2704 le16_to_cpu(pkt->sa_index), (pkt->flags & SA_FLAG_TX));
2706 qla_edif_find_sa_ctl_by_index(sp->fcport, sa_ctl->index,
2707 (pkt->flags & SA_FLAG_TX)) != NULL) {
2708 ql_dbg(ql_dbg_edif + ql_dbg_verbose, vha, 0x3063,
2709 "%s: freeing sa_ctl for index %d\n",
2710 __func__, sa_ctl->index);
2711 qla_edif_free_sa_ctl(sp->fcport, sa_ctl, sa_ctl->index);
2713 ql_dbg(ql_dbg_edif, vha, 0x3063,
2714 "%s: sa_ctl NOT freed, sa_ctl: %p\n",
2717 ql_dbg(ql_dbg_edif, vha, 0x3063,
2718 "%s: freeing sa_index %d, nph: 0x%x\n",
2719 __func__, le16_to_cpu(pkt->sa_index), nport_handle);
2720 qla_edif_sadb_delete_sa_index(sp->fcport, nport_handle,
2721 le16_to_cpu(pkt->sa_index));
2723 * check for a failed sa_update and remove
2726 } else if (pkt->u.comp_sts) {
2727 ql_dbg(ql_dbg_edif, vha, 0x3063,
2728 "%s: freeing sa_index %d, nph: 0x%x\n",
2729 __func__, pkt->sa_index, nport_handle);
2730 qla_edif_sadb_delete_sa_index(sp->fcport, nport_handle,
2731 le16_to_cpu(pkt->sa_index));
2732 switch (le16_to_cpu(pkt->u.comp_sts)) {
2733 case CS_PORT_EDIF_UNAVAIL:
2734 case CS_PORT_EDIF_LOGOUT:
2735 qlt_schedule_sess_for_deletion(sp->fcport);
2746 * qla28xx_start_scsi_edif() - Send a SCSI type 6 command to the ISP
2747 * @sp: command to send to the ISP
2749 * Return: non-zero if a failure occurred, else zero.
2752 qla28xx_start_scsi_edif(srb_t *sp)
2755 unsigned long flags;
2756 struct scsi_cmnd *cmd;
2764 uint8_t additional_cdb_len;
2765 struct ct6_dsd *ctx;
2766 struct scsi_qla_host *vha = sp->vha;
2767 struct qla_hw_data *ha = vha->hw;
2768 struct cmd_type_6 *cmd_pkt;
2769 struct dsd64 *cur_dsd;
2770 uint8_t avail_dsds = 0;
2771 struct scatterlist *sg;
2772 struct req_que *req = sp->qpair->req;
2773 spinlock_t *lock = sp->qpair->qp_lock_ptr;
2775 /* Setup device pointers. */
2776 cmd = GET_CMD_SP(sp);
2778 /* So we know we haven't pci_map'ed anything yet */
2781 /* Send marker if required */
2782 if (vha->marker_needed != 0) {
2783 if (qla2x00_marker(vha, sp->qpair, 0, 0, MK_SYNC_ALL) !=
2785 ql_log(ql_log_warn, vha, 0x300c,
2786 "qla2x00_marker failed for cmd=%p.\n", cmd);
2787 return QLA_FUNCTION_FAILED;
2789 vha->marker_needed = 0;
2792 /* Acquire ring specific lock */
2793 spin_lock_irqsave(lock, flags);
2795 /* Check for room in outstanding command list. */
2796 handle = req->current_outstanding_cmd;
2797 for (index = 1; index < req->num_outstanding_cmds; index++) {
2799 if (handle == req->num_outstanding_cmds)
2801 if (!req->outstanding_cmds[handle])
2804 if (index == req->num_outstanding_cmds)
2807 /* Map the sg table so we have an accurate count of sg entries needed */
2808 if (scsi_sg_count(cmd)) {
2809 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
2810 scsi_sg_count(cmd), cmd->sc_data_direction);
2811 if (unlikely(!nseg))
2818 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
2819 if (req->cnt < (req_cnt + 2)) {
2820 cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr :
2821 rd_reg_dword(req->req_q_out);
2822 if (req->ring_index < cnt)
2823 req->cnt = cnt - req->ring_index;
2825 req->cnt = req->length -
2826 (req->ring_index - cnt);
2827 if (req->cnt < (req_cnt + 2))
2831 ctx = sp->u.scmd.ct6_ctx =
2832 mempool_alloc(ha->ctx_mempool, GFP_ATOMIC);
2834 ql_log(ql_log_fatal, vha, 0x3010,
2835 "Failed to allocate ctx for cmd=%p.\n", cmd);
2839 memset(ctx, 0, sizeof(struct ct6_dsd));
2840 ctx->fcp_cmnd = dma_pool_zalloc(ha->fcp_cmnd_dma_pool,
2841 GFP_ATOMIC, &ctx->fcp_cmnd_dma);
2842 if (!ctx->fcp_cmnd) {
2843 ql_log(ql_log_fatal, vha, 0x3011,
2844 "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd);
2848 /* Initialize the DSD list and dma handle */
2849 INIT_LIST_HEAD(&ctx->dsd_list);
2850 ctx->dsd_use_cnt = 0;
2852 if (cmd->cmd_len > 16) {
2853 additional_cdb_len = cmd->cmd_len - 16;
2854 if ((cmd->cmd_len % 4) != 0) {
2856 * SCSI command bigger than 16 bytes must be
2859 ql_log(ql_log_warn, vha, 0x3012,
2860 "scsi cmd len %d not multiple of 4 for cmd=%p.\n",
2862 goto queuing_error_fcp_cmnd;
2864 ctx->fcp_cmnd_len = 12 + cmd->cmd_len + 4;
2866 additional_cdb_len = 0;
2867 ctx->fcp_cmnd_len = 12 + 16 + 4;
2870 cmd_pkt = (struct cmd_type_6 *)req->ring_ptr;
2871 cmd_pkt->handle = make_handle(req->id, handle);
2874 * Zero out remaining portion of packet.
2875 * tagged queuing modifier -- default is TSK_SIMPLE (0).
2877 clr_ptr = (uint32_t *)cmd_pkt + 2;
2878 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
2879 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
2881 /* No data transfer */
2882 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
2883 cmd_pkt->byte_count = cpu_to_le32(0);
2887 /* Set transfer direction */
2888 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
2889 cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
2890 vha->qla_stats.output_bytes += scsi_bufflen(cmd);
2891 vha->qla_stats.output_requests++;
2892 sp->fcport->edif.tx_bytes += scsi_bufflen(cmd);
2893 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
2894 cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
2895 vha->qla_stats.input_bytes += scsi_bufflen(cmd);
2896 vha->qla_stats.input_requests++;
2897 sp->fcport->edif.rx_bytes += scsi_bufflen(cmd);
2900 cmd_pkt->control_flags |= cpu_to_le16(CF_EN_EDIF);
2901 cmd_pkt->control_flags &= ~(cpu_to_le16(CF_NEW_SA));
2903 /* One DSD is available in the Command Type 6 IOCB */
2905 cur_dsd = &cmd_pkt->fcp_dsd;
2907 /* Load data segments */
2908 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
2910 cont_a64_entry_t *cont_pkt;
2912 /* Allocate additional continuation packets? */
2913 if (avail_dsds == 0) {
2915 * Five DSDs are available in the Continuation
2918 cont_pkt = qla2x00_prep_cont_type1_iocb(vha, req);
2919 cur_dsd = cont_pkt->dsd;
2923 sle_dma = sg_dma_address(sg);
2924 put_unaligned_le64(sle_dma, &cur_dsd->address);
2925 cur_dsd->length = cpu_to_le32(sg_dma_len(sg));
2931 /* Set NPORT-ID and LUN number*/
2932 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
2933 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
2934 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
2935 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
2936 cmd_pkt->vp_index = sp->vha->vp_idx;
2938 cmd_pkt->entry_type = COMMAND_TYPE_6;
2940 /* Set total data segment count. */
2941 cmd_pkt->entry_count = (uint8_t)req_cnt;
2943 int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
2944 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
2946 /* build FCP_CMND IU */
2947 int_to_scsilun(cmd->device->lun, &ctx->fcp_cmnd->lun);
2948 ctx->fcp_cmnd->additional_cdb_len = additional_cdb_len;
2950 if (cmd->sc_data_direction == DMA_TO_DEVICE)
2951 ctx->fcp_cmnd->additional_cdb_len |= 1;
2952 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
2953 ctx->fcp_cmnd->additional_cdb_len |= 2;
2955 /* Populate the FCP_PRIO. */
2956 if (ha->flags.fcp_prio_enabled)
2957 ctx->fcp_cmnd->task_attribute |=
2958 sp->fcport->fcp_prio << 3;
2960 memcpy(ctx->fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
2962 fcp_dl = (__be32 *)(ctx->fcp_cmnd->cdb + 16 +
2963 additional_cdb_len);
2964 *fcp_dl = htonl((uint32_t)scsi_bufflen(cmd));
2966 cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(ctx->fcp_cmnd_len);
2967 put_unaligned_le64(ctx->fcp_cmnd_dma, &cmd_pkt->fcp_cmnd_dseg_address);
2969 sp->flags |= SRB_FCP_CMND_DMA_VALID;
2970 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
2971 /* Set total data segment count. */
2972 cmd_pkt->entry_count = (uint8_t)req_cnt;
2973 cmd_pkt->entry_status = 0;
2975 /* Build command packet. */
2976 req->current_outstanding_cmd = handle;
2977 req->outstanding_cmds[handle] = sp;
2978 sp->handle = handle;
2979 cmd->host_scribble = (unsigned char *)(unsigned long)handle;
2980 req->cnt -= req_cnt;
2982 /* Adjust ring index. */
2985 if (req->ring_index == req->length) {
2986 req->ring_index = 0;
2987 req->ring_ptr = req->ring;
2992 sp->qpair->cmd_cnt++;
2993 /* Set chip new ring index. */
2994 wrt_reg_dword(req->req_q_in, req->ring_index);
2996 spin_unlock_irqrestore(lock, flags);
3000 queuing_error_fcp_cmnd:
3001 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd, ctx->fcp_cmnd_dma);
3004 scsi_dma_unmap(cmd);
3006 if (sp->u.scmd.ct6_ctx) {
3007 mempool_free(sp->u.scmd.ct6_ctx, ha->ctx_mempool);
3008 sp->u.scmd.ct6_ctx = NULL;
3010 spin_unlock_irqrestore(lock, flags);
3012 return QLA_FUNCTION_FAILED;
3015 /**********************************************
3016 * edif update/delete sa_index list functions *
3017 **********************************************/
3019 /* clear the edif_indx_list for this port */
3020 void qla_edif_list_del(fc_port_t *fcport)
3022 struct edif_list_entry *indx_lst;
3023 struct edif_list_entry *tindx_lst;
3024 struct list_head *indx_list = &fcport->edif.edif_indx_list;
3025 unsigned long flags = 0;
3027 spin_lock_irqsave(&fcport->edif.indx_list_lock, flags);
3028 list_for_each_entry_safe(indx_lst, tindx_lst, indx_list, next) {
3029 list_del(&indx_lst->next);
3032 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
3039 /* allocate/retrieve an sa_index for a given spi */
3040 static uint16_t qla_edif_sadb_get_sa_index(fc_port_t *fcport,
3041 struct qla_sa_update_frame *sa_frame)
3043 struct edif_sa_index_entry *entry;
3044 struct list_head *sa_list;
3046 int dir = sa_frame->flags & SAU_FLG_TX;
3049 scsi_qla_host_t *vha = fcport->vha;
3050 struct qla_hw_data *ha = vha->hw;
3051 unsigned long flags = 0;
3052 uint16_t nport_handle = fcport->loop_id;
3054 ql_dbg(ql_dbg_edif, vha, 0x3063,
3055 "%s: entry fc_port: %p, nport_handle: 0x%x\n",
3056 __func__, fcport, nport_handle);
3059 sa_list = &ha->sadb_tx_index_list;
3061 sa_list = &ha->sadb_rx_index_list;
3063 entry = qla_edif_sadb_find_sa_index_entry(nport_handle, sa_list);
3065 if ((sa_frame->flags & (SAU_FLG_TX | SAU_FLG_INV)) == SAU_FLG_INV) {
3066 ql_dbg(ql_dbg_edif, vha, 0x3063,
3067 "%s: rx delete request with no entry\n", __func__);
3068 return RX_DELETE_NO_EDIF_SA_INDEX;
3071 /* if there is no entry for this nport, add one */
3072 entry = kzalloc((sizeof(struct edif_sa_index_entry)), GFP_ATOMIC);
3074 return INVALID_EDIF_SA_INDEX;
3076 sa_index = qla_edif_get_sa_index_from_freepool(fcport, dir);
3077 if (sa_index == INVALID_EDIF_SA_INDEX) {
3079 return INVALID_EDIF_SA_INDEX;
3082 INIT_LIST_HEAD(&entry->next);
3083 entry->handle = nport_handle;
3084 entry->fcport = fcport;
3085 entry->sa_pair[0].spi = sa_frame->spi;
3086 entry->sa_pair[0].sa_index = sa_index;
3087 entry->sa_pair[1].spi = 0;
3088 entry->sa_pair[1].sa_index = INVALID_EDIF_SA_INDEX;
3089 spin_lock_irqsave(&ha->sadb_lock, flags);
3090 list_add_tail(&entry->next, sa_list);
3091 spin_unlock_irqrestore(&ha->sadb_lock, flags);
3092 ql_dbg(ql_dbg_edif, vha, 0x3063,
3093 "%s: Created new sadb entry for nport_handle 0x%x, spi 0x%x, returning sa_index %d\n",
3094 __func__, nport_handle, sa_frame->spi, sa_index);
3099 spin_lock_irqsave(&ha->sadb_lock, flags);
3101 /* see if we already have an entry for this spi */
3102 for (slot = 0; slot < 2; slot++) {
3103 if (entry->sa_pair[slot].sa_index == INVALID_EDIF_SA_INDEX) {
3106 if (entry->sa_pair[slot].spi == sa_frame->spi) {
3107 spin_unlock_irqrestore(&ha->sadb_lock, flags);
3108 ql_dbg(ql_dbg_edif, vha, 0x3063,
3109 "%s: sadb slot %d entry for lid 0x%x, spi 0x%x found, sa_index %d\n",
3110 __func__, slot, entry->handle, sa_frame->spi,
3111 entry->sa_pair[slot].sa_index);
3112 return entry->sa_pair[slot].sa_index;
3116 spin_unlock_irqrestore(&ha->sadb_lock, flags);
3118 /* both slots are used */
3119 if (free_slot == -1) {
3120 ql_dbg(ql_dbg_edif, vha, 0x3063,
3121 "%s: WARNING: No free slots in sadb for nport_handle 0x%x, spi: 0x%x\n",
3122 __func__, entry->handle, sa_frame->spi);
3123 ql_dbg(ql_dbg_edif, vha, 0x3063,
3124 "%s: Slot 0 spi: 0x%x sa_index: %d, Slot 1 spi: 0x%x sa_index: %d\n",
3125 __func__, entry->sa_pair[0].spi, entry->sa_pair[0].sa_index,
3126 entry->sa_pair[1].spi, entry->sa_pair[1].sa_index);
3128 return INVALID_EDIF_SA_INDEX;
3131 /* there is at least one free slot, use it */
3132 sa_index = qla_edif_get_sa_index_from_freepool(fcport, dir);
3133 if (sa_index == INVALID_EDIF_SA_INDEX) {
3134 ql_dbg(ql_dbg_edif, fcport->vha, 0x3063,
3135 "%s: empty freepool!!\n", __func__);
3136 return INVALID_EDIF_SA_INDEX;
3139 spin_lock_irqsave(&ha->sadb_lock, flags);
3140 entry->sa_pair[free_slot].spi = sa_frame->spi;
3141 entry->sa_pair[free_slot].sa_index = sa_index;
3142 spin_unlock_irqrestore(&ha->sadb_lock, flags);
3143 ql_dbg(ql_dbg_edif, fcport->vha, 0x3063,
3144 "%s: sadb slot %d entry for nport_handle 0x%x, spi 0x%x added, returning sa_index %d\n",
3145 __func__, free_slot, entry->handle, sa_frame->spi, sa_index);
3150 /* release any sadb entries -- only done at teardown */
3151 void qla_edif_sadb_release(struct qla_hw_data *ha)
3153 struct edif_sa_index_entry *entry, *tmp;
3155 list_for_each_entry_safe(entry, tmp, &ha->sadb_rx_index_list, next) {
3156 list_del(&entry->next);
3160 list_for_each_entry_safe(entry, tmp, &ha->sadb_tx_index_list, next) {
3161 list_del(&entry->next);
3166 /**************************
3167 * sadb freepool functions
3168 **************************/
3170 /* build the rx and tx sa_index free pools -- only done at fcport init */
3171 int qla_edif_sadb_build_free_pool(struct qla_hw_data *ha)
3173 ha->edif_tx_sa_id_map =
3174 kcalloc(BITS_TO_LONGS(EDIF_NUM_SA_INDEX), sizeof(long), GFP_KERNEL);
3176 if (!ha->edif_tx_sa_id_map) {
3177 ql_log_pci(ql_log_fatal, ha->pdev, 0x0009,
3178 "Unable to allocate memory for sadb tx.\n");
3182 ha->edif_rx_sa_id_map =
3183 kcalloc(BITS_TO_LONGS(EDIF_NUM_SA_INDEX), sizeof(long), GFP_KERNEL);
3184 if (!ha->edif_rx_sa_id_map) {
3185 kfree(ha->edif_tx_sa_id_map);
3186 ha->edif_tx_sa_id_map = NULL;
3187 ql_log_pci(ql_log_fatal, ha->pdev, 0x0009,
3188 "Unable to allocate memory for sadb rx.\n");
3194 /* release the free pool - only done during fcport teardown */
3195 void qla_edif_sadb_release_free_pool(struct qla_hw_data *ha)
3197 kfree(ha->edif_tx_sa_id_map);
3198 ha->edif_tx_sa_id_map = NULL;
3199 kfree(ha->edif_rx_sa_id_map);
3200 ha->edif_rx_sa_id_map = NULL;
3203 static void __chk_edif_rx_sa_delete_pending(scsi_qla_host_t *vha,
3204 fc_port_t *fcport, uint32_t handle, uint16_t sa_index)
3206 struct edif_list_entry *edif_entry;
3207 struct edif_sa_ctl *sa_ctl;
3208 uint16_t delete_sa_index = INVALID_EDIF_SA_INDEX;
3209 unsigned long flags = 0;
3210 uint16_t nport_handle = fcport->loop_id;
3211 uint16_t cached_nport_handle;
3213 spin_lock_irqsave(&fcport->edif.indx_list_lock, flags);
3214 edif_entry = qla_edif_list_find_sa_index(fcport, nport_handle);
3216 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
3217 return; /* no pending delete for this handle */
3221 * check for no pending delete for this index or iocb does not
3224 if (edif_entry->delete_sa_index == INVALID_EDIF_SA_INDEX ||
3225 edif_entry->update_sa_index != sa_index) {
3226 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
3231 * wait until we have seen at least EDIF_DELAY_COUNT transfers before
3232 * queueing RX delete
3234 if (edif_entry->count++ < EDIF_RX_DELETE_FILTER_COUNT) {
3235 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
3239 ql_dbg(ql_dbg_edif, vha, 0x5033,
3240 "%s: invalidating delete_sa_index, update_sa_index: 0x%x sa_index: 0x%x, delete_sa_index: 0x%x\n",
3241 __func__, edif_entry->update_sa_index, sa_index, edif_entry->delete_sa_index);
3243 delete_sa_index = edif_entry->delete_sa_index;
3244 edif_entry->delete_sa_index = INVALID_EDIF_SA_INDEX;
3245 cached_nport_handle = edif_entry->handle;
3246 spin_unlock_irqrestore(&fcport->edif.indx_list_lock, flags);
3248 /* sanity check on the nport handle */
3249 if (nport_handle != cached_nport_handle) {
3250 ql_dbg(ql_dbg_edif, vha, 0x3063,
3251 "%s: POST SA DELETE nport_handle mismatch: lid: 0x%x, edif_entry nph: 0x%x\n",
3252 __func__, nport_handle, cached_nport_handle);
3255 /* find the sa_ctl for the delete and schedule the delete */
3256 sa_ctl = qla_edif_find_sa_ctl_by_index(fcport, delete_sa_index, 0);
3258 ql_dbg(ql_dbg_edif, vha, 0x3063,
3259 "%s: POST SA DELETE sa_ctl: %p, index recvd %d\n",
3260 __func__, sa_ctl, sa_index);
3261 ql_dbg(ql_dbg_edif, vha, 0x3063,
3262 "delete index %d, update index: %d, nport handle: 0x%x, handle: 0x%x\n",
3264 edif_entry->update_sa_index, nport_handle, handle);
3266 sa_ctl->flags = EDIF_SA_CTL_FLG_DEL;
3267 set_bit(EDIF_SA_CTL_REPL, &sa_ctl->state);
3268 qla_post_sa_replace_work(fcport->vha, fcport,
3269 nport_handle, sa_ctl);
3271 ql_dbg(ql_dbg_edif, vha, 0x3063,
3272 "%s: POST SA DELETE sa_ctl not found for delete_sa_index: %d\n",
3273 __func__, delete_sa_index);
3277 void qla_chk_edif_rx_sa_delete_pending(scsi_qla_host_t *vha,
3278 srb_t *sp, struct sts_entry_24xx *sts24)
3280 fc_port_t *fcport = sp->fcport;
3281 /* sa_index used by this iocb */
3282 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
3285 handle = (uint32_t)LSW(sts24->handle);
3287 /* find out if this status iosb is for a scsi read */
3288 if (cmd->sc_data_direction != DMA_FROM_DEVICE)
3291 return __chk_edif_rx_sa_delete_pending(vha, fcport, handle,
3292 le16_to_cpu(sts24->edif_sa_index));
3295 void qlt_chk_edif_rx_sa_delete_pending(scsi_qla_host_t *vha, fc_port_t *fcport,
3296 struct ctio7_from_24xx *pkt)
3298 __chk_edif_rx_sa_delete_pending(vha, fcport,
3299 pkt->handle, le16_to_cpu(pkt->edif_sa_index));
3302 static void qla_parse_auth_els_ctl(struct srb *sp)
3304 struct qla_els_pt_arg *a = &sp->u.bsg_cmd.u.els_arg;
3305 struct bsg_job *bsg_job = sp->u.bsg_cmd.bsg_job;
3306 struct fc_bsg_request *request = bsg_job->request;
3307 struct qla_bsg_auth_els_request *p =
3308 (struct qla_bsg_auth_els_request *)bsg_job->request;
3310 a->tx_len = a->tx_byte_count = sp->remap.req.len;
3311 a->tx_addr = sp->remap.req.dma;
3312 a->rx_len = a->rx_byte_count = sp->remap.rsp.len;
3313 a->rx_addr = sp->remap.rsp.dma;
3315 if (p->e.sub_cmd == SEND_ELS_REPLY) {
3316 a->control_flags = p->e.extra_control_flags << 13;
3317 a->rx_xchg_address = cpu_to_le32(p->e.extra_rx_xchg_address);
3318 if (p->e.extra_control_flags == BSG_CTL_FLAG_LS_ACC)
3319 a->els_opcode = ELS_LS_ACC;
3320 else if (p->e.extra_control_flags == BSG_CTL_FLAG_LS_RJT)
3321 a->els_opcode = ELS_LS_RJT;
3323 a->did = sp->fcport->d_id;
3324 a->els_opcode = request->rqst_data.h_els.command_code;
3325 a->nport_handle = cpu_to_le16(sp->fcport->loop_id);
3326 a->vp_idx = sp->vha->vp_idx;
3329 int qla_edif_process_els(scsi_qla_host_t *vha, struct bsg_job *bsg_job)
3331 struct fc_bsg_request *bsg_request = bsg_job->request;
3332 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
3333 fc_port_t *fcport = NULL;
3334 struct qla_hw_data *ha = vha->hw;
3336 int rval = (DID_ERROR << 16);
3338 struct qla_bsg_auth_els_request *p =
3339 (struct qla_bsg_auth_els_request *)bsg_job->request;
3341 d_id.b.al_pa = bsg_request->rqst_data.h_els.port_id[2];
3342 d_id.b.area = bsg_request->rqst_data.h_els.port_id[1];
3343 d_id.b.domain = bsg_request->rqst_data.h_els.port_id[0];
3345 /* find matching d_id in fcport list */
3346 fcport = qla2x00_find_fcport_by_pid(vha, &d_id);
3348 ql_dbg(ql_dbg_edif, vha, 0x911a,
3349 "%s fcport not find online portid=%06x.\n",
3350 __func__, d_id.b24);
3351 SET_DID_STATUS(bsg_reply->result, DID_ERROR);
3355 if (qla_bsg_check(vha, bsg_job, fcport))
3358 if (fcport->loop_id == FC_NO_LOOP_ID) {
3359 ql_dbg(ql_dbg_edif, vha, 0x910d,
3360 "%s ELS code %x, no loop id.\n", __func__,
3361 bsg_request->rqst_data.r_els.els_code);
3362 SET_DID_STATUS(bsg_reply->result, DID_BAD_TARGET);
3366 if (!vha->flags.online) {
3367 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
3368 SET_DID_STATUS(bsg_reply->result, DID_BAD_TARGET);
3373 /* pass through is supported only for ISP 4Gb or higher */
3374 if (!IS_FWI2_CAPABLE(ha)) {
3375 ql_dbg(ql_dbg_user, vha, 0x7001,
3376 "ELS passthru not supported for ISP23xx based adapters.\n");
3377 SET_DID_STATUS(bsg_reply->result, DID_BAD_TARGET);
3382 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3384 ql_dbg(ql_dbg_user, vha, 0x7004,
3385 "Failed get sp pid=%06x\n", fcport->d_id.b24);
3387 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
3391 sp->remap.req.len = bsg_job->request_payload.payload_len;
3392 sp->remap.req.buf = dma_pool_alloc(ha->purex_dma_pool,
3393 GFP_KERNEL, &sp->remap.req.dma);
3394 if (!sp->remap.req.buf) {
3395 ql_dbg(ql_dbg_user, vha, 0x7005,
3396 "Failed allocate request dma len=%x\n",
3397 bsg_job->request_payload.payload_len);
3399 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
3403 sp->remap.rsp.len = bsg_job->reply_payload.payload_len;
3404 sp->remap.rsp.buf = dma_pool_alloc(ha->purex_dma_pool,
3405 GFP_KERNEL, &sp->remap.rsp.dma);
3406 if (!sp->remap.rsp.buf) {
3407 ql_dbg(ql_dbg_user, vha, 0x7006,
3408 "Failed allocate response dma len=%x\n",
3409 bsg_job->reply_payload.payload_len);
3411 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
3412 goto done_free_remap_req;
3414 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
3415 bsg_job->request_payload.sg_cnt, sp->remap.req.buf,
3417 sp->remap.remapped = true;
3419 sp->type = SRB_ELS_CMD_HST_NOLOGIN;
3420 sp->name = "SPCN_BSG_HST_NOLOGIN";
3421 sp->u.bsg_cmd.bsg_job = bsg_job;
3422 qla_parse_auth_els_ctl(sp);
3424 sp->free = qla2x00_bsg_sp_free;
3425 sp->done = qla2x00_bsg_job_done;
3427 rval = qla2x00_start_sp(sp);
3429 ql_dbg(ql_dbg_edif, vha, 0x700a,
3430 "%s %s %8phN xchg %x ctlflag %x hdl %x reqlen %xh bsg ptr %p\n",
3431 __func__, sc_to_str(p->e.sub_cmd), fcport->port_name,
3432 p->e.extra_rx_xchg_address, p->e.extra_control_flags,
3433 sp->handle, sp->remap.req.len, bsg_job);
3435 if (rval != QLA_SUCCESS) {
3436 ql_log(ql_log_warn, vha, 0x700e,
3437 "qla2x00_start_sp failed = %d\n", rval);
3438 SET_DID_STATUS(bsg_reply->result, DID_IMM_RETRY);
3440 goto done_free_remap_rsp;
3444 done_free_remap_rsp:
3445 dma_pool_free(ha->purex_dma_pool, sp->remap.rsp.buf,
3447 done_free_remap_req:
3448 dma_pool_free(ha->purex_dma_pool, sp->remap.req.buf,
3457 void qla_edif_sess_down(struct scsi_qla_host *vha, struct fc_port *sess)
3459 if (sess->edif.app_sess_online && DBELL_ACTIVE(vha)) {
3460 ql_dbg(ql_dbg_disc, vha, 0xf09c,
3461 "%s: sess %8phN send port_offline event\n",
3462 __func__, sess->port_name);
3463 sess->edif.app_sess_online = 0;
3464 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_SESSION_SHUTDOWN,
3465 sess->d_id.b24, 0, sess);
3466 qla2x00_post_aen_work(vha, FCH_EVT_PORT_OFFLINE, sess->d_id.b24);
3470 void qla_edif_clear_appdata(struct scsi_qla_host *vha, struct fc_port *fcport)
3472 if (!(fcport->flags & FCF_FCSP_DEVICE))
3475 qla_edb_clear(vha, fcport->d_id);
3476 qla_enode_clear(vha, fcport->d_id);