Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * bnx2fc_els.c: QLogic Linux FCoE offload driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * This file contains helper routines that handle ELS requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * and responses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2008-2013 Broadcom Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2014-2016 QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (c) 2016-2017 Cavium Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "bnx2fc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static void bnx2fc_logo_resp(struct fc_seq *seq, struct fc_frame *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 			     void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static void bnx2fc_flogi_resp(struct fc_seq *seq, struct fc_frame *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 			      void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 			void *data, u32 data_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 			void (*cb_func)(struct bnx2fc_els_cb_arg *cb_arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void bnx2fc_rrq_compl(struct bnx2fc_els_cb_arg *cb_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct bnx2fc_cmd *orig_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct bnx2fc_cmd *rrq_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	BUG_ON(!cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	rrq_req = cb_arg->io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	orig_io_req = cb_arg->aborted_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	BUG_ON(!orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	BNX2FC_ELS_DBG("rrq_compl: orig xid = 0x%x, rrq_xid = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		   orig_io_req->xid, rrq_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &rrq_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		 * els req is timed out. cleanup the IO with FW and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		 * drop the completion. Remove from active_cmd_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		BNX2FC_ELS_DBG("rrq xid - 0x%x timed out, clean it up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			   rrq_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (rrq_req->on_active_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			list_del_init(&rrq_req->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			rrq_req->on_active_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			rc = bnx2fc_initiate_cleanup(rrq_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			BUG_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) int bnx2fc_send_rrq(struct bnx2fc_cmd *aborted_io_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct fc_els_rrq rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct bnx2fc_rport *tgt = aborted_io_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct fc_lport *lport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct bnx2fc_els_cb_arg *cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32 sid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u32 r_a_tov = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned long start = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	sid = tgt->sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	BNX2FC_ELS_DBG("Sending RRQ orig_xid = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		   aborted_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	memset(&rrq, 0, sizeof(rrq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for RRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		goto rrq_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	cb_arg->aborted_io_req = aborted_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	rrq.rrq_cmd = ELS_RRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	hton24(rrq.rrq_s_id, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	rrq.rrq_ox_id = htons(aborted_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	rrq.rrq_rx_id = htons(aborted_io_req->task->rxwr_txrd.var_ctx.rx_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) retry_rrq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	rc = bnx2fc_initiate_els(tgt, ELS_RRQ, &rrq, sizeof(rrq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				 bnx2fc_rrq_compl, cb_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				 r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (rc == -ENOMEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (time_after(jiffies, start + (10 * HZ))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			BNX2FC_ELS_DBG("rrq Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			goto rrq_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto retry_rrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) rrq_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		BNX2FC_ELS_DBG("RRQ failed - release orig io req 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			aborted_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		kref_put(&aborted_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void bnx2fc_l2_els_compl(struct bnx2fc_els_cb_arg *cb_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct bnx2fc_cmd *els_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct bnx2fc_rport *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct bnx2fc_mp_req *mp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	void *resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u32 resp_len, hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u16 l2_oxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int frame_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	l2_oxid = cb_arg->l2_oxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	BNX2FC_ELS_DBG("ELS COMPL - l2_oxid = 0x%x\n", l2_oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	els_req = cb_arg->io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &els_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		 * els req is timed out. cleanup the IO with FW and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		 * drop the completion. libfc will handle the els timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (els_req->on_active_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			list_del_init(&els_req->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			els_req->on_active_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			rc = bnx2fc_initiate_cleanup(els_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			BUG_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		goto free_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	tgt = els_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	mp_req = &(els_req->mp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	fc_hdr = &(mp_req->resp_fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	resp_len = mp_req->resp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	resp_buf = mp_req->resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	buf = kzalloc(PAGE_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		printk(KERN_ERR PFX "Unable to alloc mp buf\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		goto free_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	hdr_len = sizeof(*fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (hdr_len + resp_len > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		printk(KERN_ERR PFX "l2_els_compl: resp len is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				    "beyond page size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		goto free_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	memcpy(buf, fc_hdr, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	memcpy(buf + hdr_len, resp_buf, resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	frame_len = hdr_len + resp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	bnx2fc_process_l2_frame_compl(tgt, buf, frame_len, l2_oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) free_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) free_arg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int bnx2fc_send_adisc(struct bnx2fc_rport *tgt, struct fc_frame *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct fc_els_adisc *adisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct bnx2fc_els_cb_arg *cb_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct fc_lport *lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	u32 r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for ADISC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	BNX2FC_ELS_DBG("send ADISC: l2_oxid = 0x%x\n", cb_arg->l2_oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	adisc = fc_frame_payload_get(fp, sizeof(*adisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* adisc is initialized by libfc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	rc = bnx2fc_initiate_els(tgt, ELS_ADISC, adisc, sizeof(*adisc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				 bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int bnx2fc_send_logo(struct bnx2fc_rport *tgt, struct fc_frame *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct fc_els_logo *logo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct bnx2fc_els_cb_arg *cb_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct fc_lport *lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	u32 r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for LOGO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	BNX2FC_ELS_DBG("Send LOGO: l2_oxid = 0x%x\n", cb_arg->l2_oxid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	logo = fc_frame_payload_get(fp, sizeof(*logo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* logo is initialized by libfc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	rc = bnx2fc_initiate_els(tgt, ELS_LOGO, logo, sizeof(*logo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				 bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int bnx2fc_send_rls(struct bnx2fc_rport *tgt, struct fc_frame *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct fc_els_rls *rls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct bnx2fc_els_cb_arg *cb_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct fc_lport *lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	u32 r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for LOGO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	rls = fc_frame_payload_get(fp, sizeof(*rls));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* rls is initialized by libfc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	rc = bnx2fc_initiate_els(tgt, ELS_RLS, rls, sizeof(*rls),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				  bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct bnx2fc_mp_req *mp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct fc_frame_header *fc_hdr, *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct bnx2fc_cmd *srr_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	struct bnx2fc_cmd *orig_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct fc_frame *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	void *resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	u32 resp_len, hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	orig_io_req = cb_arg->aborted_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	srr_req = cb_arg->io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &srr_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		/* SRR timedout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		BNX2FC_IO_DBG(srr_req, "srr timed out, abort "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		       "orig_io - 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		rc = bnx2fc_initiate_abts(srr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			BNX2FC_IO_DBG(srr_req, "srr_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				"failed. issue cleanup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			bnx2fc_initiate_cleanup(srr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		    test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			BNX2FC_IO_DBG(srr_req, "srr_compl:xid 0x%x flags = %lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				      orig_io_req->xid, orig_io_req->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			goto srr_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		orig_io_req->srr_retry++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		if (orig_io_req->srr_retry <= SRR_RETRY_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			struct bnx2fc_rport *tgt = orig_io_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			rc = bnx2fc_send_srr(orig_io_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 					     orig_io_req->srr_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 					     orig_io_req->srr_rctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				goto srr_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		rc = bnx2fc_initiate_abts(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			BNX2FC_IO_DBG(srr_req, "srr_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 				"failed xid = 0x%x. issue cleanup\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		goto srr_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	    test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		BNX2FC_IO_DBG(srr_req, "srr_compl:xid - 0x%x flags = %lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			      orig_io_req->xid, orig_io_req->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		goto srr_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	mp_req = &(srr_req->mp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	fc_hdr = &(mp_req->resp_fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	resp_len = mp_req->resp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	resp_buf = mp_req->resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	hdr_len = sizeof(*fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	buf = kzalloc(PAGE_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		printk(KERN_ERR PFX "srr buf: mem alloc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto srr_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	memcpy(buf, fc_hdr, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	memcpy(buf + hdr_len, resp_buf, resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	fp = fc_frame_alloc(NULL, resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (!fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		printk(KERN_ERR PFX "fc_frame_alloc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto free_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	fh = (struct fc_frame_header *) fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* Copy FC Frame header and payload into the frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	memcpy(fh, buf, hdr_len + resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	opcode = fc_frame_payload_op(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	switch (opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	case ELS_LS_ACC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		BNX2FC_IO_DBG(srr_req, "SRR success\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	case ELS_LS_RJT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		BNX2FC_IO_DBG(srr_req, "SRR rejected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		rc = bnx2fc_initiate_abts(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			BNX2FC_IO_DBG(srr_req, "srr_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				"failed xid = 0x%x. issue cleanup\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 				orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		BNX2FC_IO_DBG(srr_req, "srr compl - invalid opcode = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	fc_frame_free(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) free_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) srr_compl_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static void bnx2fc_rec_compl(struct bnx2fc_els_cb_arg *cb_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	struct bnx2fc_cmd *orig_io_req, *new_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct bnx2fc_cmd *rec_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct bnx2fc_mp_req *mp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct fc_frame_header *fc_hdr, *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct fc_els_ls_rjt *rjt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct fc_els_rec_acc *acc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct bnx2fc_rport *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct fcoe_err_report_entry *err_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct scsi_cmnd *sc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	enum fc_rctl r_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	void *resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct fc_frame *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	u32 e_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	u32 resp_len, hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	bool send_seq_clnp = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	bool abort_io = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	BNX2FC_MISC_DBG("Entered rec_compl callback\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	rec_req = cb_arg->io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	orig_io_req = cb_arg->aborted_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	BNX2FC_IO_DBG(rec_req, "rec_compl: orig xid = 0x%x", orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	tgt = orig_io_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	/* Handle REC timeout case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &rec_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		BNX2FC_IO_DBG(rec_req, "timed out, abort "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		       "orig_io - 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		/* els req is timed out. send abts for els */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		rc = bnx2fc_initiate_abts(rec_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			BNX2FC_IO_DBG(rec_req, "rec_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 				"failed. issue cleanup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			bnx2fc_initiate_cleanup(rec_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		orig_io_req->rec_retry++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		/* REC timedout. send ABTS to the orig IO req */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (orig_io_req->rec_retry <= REC_RETRY_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			rc = bnx2fc_send_rec(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				goto rec_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		rc = bnx2fc_initiate_abts(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			BNX2FC_IO_DBG(rec_req, "rec_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				"failed xid = 0x%x. issue cleanup\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		goto rec_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		BNX2FC_IO_DBG(rec_req, "completed"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		       "orig_io - 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		goto rec_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		BNX2FC_IO_DBG(rec_req, "abts in prog "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		       "orig_io - 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		goto rec_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	mp_req = &(rec_req->mp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	fc_hdr = &(mp_req->resp_fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	resp_len = mp_req->resp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	acc = resp_buf = mp_req->resp_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	hdr_len = sizeof(*fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	buf = kzalloc(PAGE_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		printk(KERN_ERR PFX "rec buf: mem alloc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		goto rec_compl_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	memcpy(buf, fc_hdr, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	memcpy(buf + hdr_len, resp_buf, resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	fp = fc_frame_alloc(NULL, resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (!fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		printk(KERN_ERR PFX "fc_frame_alloc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		goto free_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	fh = (struct fc_frame_header *) fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	/* Copy FC Frame header and payload into the frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	memcpy(fh, buf, hdr_len + resp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	opcode = fc_frame_payload_op(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (opcode == ELS_LS_RJT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		BNX2FC_IO_DBG(rec_req, "opcode is RJT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		rjt = fc_frame_payload_get(fp, sizeof(*rjt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		if ((rjt->er_reason == ELS_RJT_LOGIC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		    rjt->er_reason == ELS_RJT_UNAB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		    rjt->er_explan == ELS_EXPL_OXID_RXID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			BNX2FC_IO_DBG(rec_req, "handle CMD LOST case\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			new_io_req = bnx2fc_cmd_alloc(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			if (!new_io_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 				goto abort_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			new_io_req->sc_cmd = orig_io_req->sc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			/* cleanup orig_io_req that is with the FW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			set_bit(BNX2FC_FLAG_CMD_LOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 				&orig_io_req->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			/* Post a new IO req with the same sc_cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			BNX2FC_IO_DBG(rec_req, "Post IO request again\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			rc = bnx2fc_post_io_req(tgt, new_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 				goto free_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			BNX2FC_IO_DBG(rec_req, "REC: io post err\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) abort_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		rc = bnx2fc_initiate_abts(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			BNX2FC_IO_DBG(rec_req, "rec_compl: initiate_abts "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 				"failed. issue cleanup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	} else if (opcode == ELS_LS_ACC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		/* REVISIT: Check if the exchange is already aborted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		offset = ntohl(acc->reca_fc4value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		e_stat = ntohl(acc->reca_e_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		if (e_stat & ESB_ST_SEQ_INIT)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			BNX2FC_IO_DBG(rec_req, "target has the seq init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			goto free_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		BNX2FC_IO_DBG(rec_req, "e_stat = 0x%x, offset = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 			e_stat, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		/* Seq initiative is with us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		err_entry = (struct fcoe_err_report_entry *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			     &orig_io_req->err_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		sc_cmd = orig_io_req->sc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			/* SCSI WRITE command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			if (offset == orig_io_req->data_xfer_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 				BNX2FC_IO_DBG(rec_req, "WRITE - resp lost\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 				/* FCP_RSP lost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 				r_ctl = FC_RCTL_DD_CMD_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 				offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 				/* start transmitting from offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				BNX2FC_IO_DBG(rec_req, "XFER_RDY/DATA lost\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 				send_seq_clnp = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 				r_ctl = FC_RCTL_DD_DATA_DESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 				if (bnx2fc_initiate_seq_cleanup(orig_io_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 								offset, r_ctl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 					abort_io = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				/* XFER_RDY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			/* SCSI READ command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			if (err_entry->data.rx_buf_off ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 					orig_io_req->data_xfer_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 				/* FCP_RSP lost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 				BNX2FC_IO_DBG(rec_req, "READ - resp lost\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 				r_ctl = FC_RCTL_DD_CMD_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 				offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 				/* request retransmission from this offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 				send_seq_clnp = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 				offset = err_entry->data.rx_buf_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 				BNX2FC_IO_DBG(rec_req, "RD DATA lost\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 				/* FCP_DATA lost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 				r_ctl = FC_RCTL_DD_SOL_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 				if (bnx2fc_initiate_seq_cleanup(orig_io_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 								offset, r_ctl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 					abort_io = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		if (abort_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 			rc = bnx2fc_initiate_abts(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			if (rc != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 				BNX2FC_IO_DBG(rec_req, "rec_compl:initiate_abts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 					      " failed. issue cleanup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 				bnx2fc_initiate_cleanup(orig_io_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		} else if (!send_seq_clnp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			BNX2FC_IO_DBG(rec_req, "Send SRR - FCP_RSP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 			rc = bnx2fc_send_srr(orig_io_req, offset, r_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 			spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 				BNX2FC_IO_DBG(rec_req, "Unable to send SRR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 					" IO will abort\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) free_frame:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	fc_frame_free(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) free_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) rec_compl_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) int bnx2fc_send_rec(struct bnx2fc_cmd *orig_io_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct fc_els_rec rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	struct bnx2fc_rport *tgt = orig_io_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	struct fc_lport *lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	struct bnx2fc_els_cb_arg *cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	u32 sid = tgt->sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	u32 r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	BNX2FC_IO_DBG(orig_io_req, "Sending REC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	memset(&rec, 0, sizeof(rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for REC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		goto rec_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	kref_get(&orig_io_req->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	cb_arg->aborted_io_req = orig_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	rec.rec_cmd = ELS_REC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	hton24(rec.rec_s_id, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	rec.rec_ox_id = htons(orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	rec.rec_rx_id = htons(orig_io_req->task->rxwr_txrd.var_ctx.rx_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	rc = bnx2fc_initiate_els(tgt, ELS_REC, &rec, sizeof(rec),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				 bnx2fc_rec_compl, cb_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 				 r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		BNX2FC_IO_DBG(orig_io_req, "REC failed - release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) rec_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) int bnx2fc_send_srr(struct bnx2fc_cmd *orig_io_req, u32 offset, u8 r_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	struct fcp_srr srr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	struct bnx2fc_rport *tgt = orig_io_req->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	struct fc_lport *lport = tgt->rdata->local_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	struct bnx2fc_els_cb_arg *cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	u32 r_a_tov = lport->r_a_tov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	BNX2FC_IO_DBG(orig_io_req, "Sending SRR\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	memset(&srr, 0, sizeof(srr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (!cb_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		printk(KERN_ERR PFX "Unable to allocate cb_arg for SRR\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		goto srr_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	kref_get(&orig_io_req->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	cb_arg->aborted_io_req = orig_io_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	srr.srr_op = ELS_SRR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	srr.srr_ox_id = htons(orig_io_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	srr.srr_rx_id = htons(orig_io_req->task->rxwr_txrd.var_ctx.rx_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	srr.srr_rel_off = htonl(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	srr.srr_r_ctl = r_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	orig_io_req->srr_offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	orig_io_req->srr_rctl = r_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	rc = bnx2fc_initiate_els(tgt, ELS_SRR, &srr, sizeof(srr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 				 bnx2fc_srr_compl, cb_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 				 r_a_tov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		BNX2FC_IO_DBG(orig_io_req, "SRR failed - release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		kfree(cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		set_bit(BNX2FC_FLAG_SRR_SENT, &orig_io_req->req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) srr_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			void *data, u32 data_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 			void (*cb_func)(struct bnx2fc_els_cb_arg *cb_arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 			struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	struct fcoe_port *port = tgt->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	struct bnx2fc_interface *interface = port->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	struct fc_rport *rport = tgt->rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	struct fc_lport *lport = port->lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	struct bnx2fc_cmd *els_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct bnx2fc_mp_req *mp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	struct fcoe_task_ctx_entry *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	struct fcoe_task_ctx_entry *task_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	int task_idx, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	u32 did, sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	u16 xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	rc = fc_remote_port_chkready(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		printk(KERN_ERR PFX "els 0x%x: rport not ready\n", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		printk(KERN_ERR PFX "els 0x%x: link is not ready\n", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	if (!(test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		printk(KERN_ERR PFX "els 0x%x: tgt not ready\n", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	els_req = bnx2fc_elstm_alloc(tgt, BNX2FC_ELS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	if (!els_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	els_req->sc_cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	els_req->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	els_req->tgt = tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	els_req->cb_func = cb_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	cb_arg->io_req = els_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	els_req->cb_arg = cb_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	els_req->data_xfer_len = data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	mp_req = (struct bnx2fc_mp_req *)&(els_req->mp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	rc = bnx2fc_init_mp_req(els_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	if (rc == FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		printk(KERN_ERR PFX "ELS MP request init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 		spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		kref_put(&els_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		/* rc SUCCESS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	/* Set the data_xfer_len to the size of ELS payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	mp_req->req_len = data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	els_req->data_xfer_len = mp_req->req_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	/* Fill ELS Payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		memcpy(mp_req->req_buf, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 		printk(KERN_ERR PFX "Invalid ELS op 0x%x\n", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		els_req->cb_func = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		els_req->cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 		spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		kref_put(&els_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		goto els_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	/* Fill FC header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	fc_hdr = &(mp_req->req_fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	did = tgt->rport->port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	sid = tgt->sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	if (op == ELS_SRR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		__fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS4_REQ, did, sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 				   FC_TYPE_FCP, FC_FC_FIRST_SEQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 				   FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		__fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 				   FC_TYPE_ELS, FC_FC_FIRST_SEQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 				   FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	/* Obtain exchange id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	xid = els_req->xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	task_idx = xid/BNX2FC_TASKS_PER_PAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	index = xid % BNX2FC_TASKS_PER_PAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	/* Initialize task context for this IO request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	task_page = (struct fcoe_task_ctx_entry *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 			interface->hba->task_ctx[task_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	task = &(task_page[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	bnx2fc_init_mp_task(els_req, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	spin_lock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 		printk(KERN_ERR PFX "initiate_els.. session not ready\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		els_req->cb_func = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		els_req->cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		kref_put(&els_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 		spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	if (timer_msec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		bnx2fc_cmd_timer_set(els_req, timer_msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	bnx2fc_add_2_sq(tgt, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	els_req->on_active_queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	list_add_tail(&els_req->link, &tgt->els_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	/* Ring doorbell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	bnx2fc_ring_doorbell(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	spin_unlock_bh(&tgt->tgt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) els_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) void bnx2fc_process_els_compl(struct bnx2fc_cmd *els_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 			      struct fcoe_task_ctx_entry *task, u8 num_rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	struct bnx2fc_mp_req *mp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	struct fc_frame_header *fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	u64 *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	u64 *temp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	BNX2FC_ELS_DBG("Entered process_els_compl xid = 0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 			"cmd_type = %d\n", els_req->xid, els_req->cmd_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	if (test_and_set_bit(BNX2FC_FLAG_ELS_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 			     &els_req->req_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		BNX2FC_ELS_DBG("Timer context finished processing this "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 			   "els - 0x%x\n", els_req->xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 		/* This IO doesn't receive cleanup completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		kref_put(&els_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	/* Cancel the timeout_work, as we received the response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	if (cancel_delayed_work(&els_req->timeout_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		kref_put(&els_req->refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 			 bnx2fc_cmd_release); /* drop timer hold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	if (els_req->on_active_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		list_del_init(&els_req->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 		els_req->on_active_queue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	mp_req = &(els_req->mp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	fc_hdr = &(mp_req->resp_fc_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	hdr = (u64 *)fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	temp_hdr = (u64 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		&task->rxwr_only.union_ctx.comp_info.mp_rsp.fc_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	hdr[0] = cpu_to_be64(temp_hdr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	hdr[1] = cpu_to_be64(temp_hdr[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	hdr[2] = cpu_to_be64(temp_hdr[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	mp_req->resp_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		task->rxwr_only.union_ctx.comp_info.mp_rsp.mp_payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	/* Parse ELS response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	if ((els_req->cb_func) && (els_req->cb_arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 		els_req->cb_func(els_req->cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 		els_req->cb_arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	kref_put(&els_req->refcount, bnx2fc_cmd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) #define		BNX2FC_FCOE_MAC_METHOD_GRANGED_MAC	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) #define		BNX2FC_FCOE_MAC_METHOD_FCF_MAP		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) #define		BNX2FC_FCOE_MAC_METHOD_FCOE_SET_MAC	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) static void bnx2fc_flogi_resp(struct fc_seq *seq, struct fc_frame *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 			      void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	struct fcoe_ctlr *fip = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	struct fc_exch *exch = fc_seq_exch(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	struct fc_lport *lport = exch->lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	u8 *granted_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	u8 fcoe_mac[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	u8 fc_map[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	int method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 	if (IS_ERR(fp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	granted_mac = fr_cb(fp)->granted_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	 * We set the source MAC for FCoE traffic based on the Granted MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	 * address from the switch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	 * If granted_mac is non-zero, we use that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	 * If the granted_mac is zeroed out, create the FCoE MAC based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	 * the sel_fcf->fc_map and the d_id fo the FLOGI frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	 * If sel_fcf->fc_map is 0, then we use the default FCF-MAC plus the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	 * d_id of the FLOGI frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	if (!is_zero_ether_addr(granted_mac)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 		ether_addr_copy(fcoe_mac, granted_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 		method = BNX2FC_FCOE_MAC_METHOD_GRANGED_MAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	} else if (fip->sel_fcf && fip->sel_fcf->fc_map != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 		hton24(fc_map, fip->sel_fcf->fc_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 		fcoe_mac[0] = fc_map[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 		fcoe_mac[1] = fc_map[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 		fcoe_mac[2] = fc_map[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 		fcoe_mac[3] = fh->fh_d_id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 		fcoe_mac[4] = fh->fh_d_id[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 		fcoe_mac[5] = fh->fh_d_id[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 		method = BNX2FC_FCOE_MAC_METHOD_FCF_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 		fc_fcoe_set_mac(fcoe_mac, fh->fh_d_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 		method = BNX2FC_FCOE_MAC_METHOD_FCOE_SET_MAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	BNX2FC_HBA_DBG(lport, "fcoe_mac=%pM method=%d\n", fcoe_mac, method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	fip->update_mac(lport, fcoe_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	fc_lport_flogi_resp(seq, fp, lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static void bnx2fc_logo_resp(struct fc_seq *seq, struct fc_frame *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 			     void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	struct fcoe_ctlr *fip = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	struct fc_exch *exch = fc_seq_exch(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	struct fc_lport *lport = exch->lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 	static u8 zero_mac[ETH_ALEN] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 	if (!IS_ERR(fp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 		fip->update_mac(lport, zero_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	fc_lport_logo_resp(seq, fp, lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct fc_seq *bnx2fc_elsct_send(struct fc_lport *lport, u32 did,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 				      struct fc_frame *fp, unsigned int op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 				      void (*resp)(struct fc_seq *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 						   struct fc_frame *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 						   void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 				      void *arg, u32 timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 	struct fcoe_port *port = lport_priv(lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	struct bnx2fc_interface *interface = port->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 	struct fcoe_ctlr *fip = bnx2fc_to_ctlr(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) 	struct fc_frame_header *fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) 	switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 	case ELS_FLOGI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) 	case ELS_FDISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) 		return fc_elsct_send(lport, did, fp, op, bnx2fc_flogi_resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 				     fip, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) 	case ELS_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 		/* only hook onto fabric logouts, not port logouts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) 		if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 		return fc_elsct_send(lport, did, fp, op, bnx2fc_logo_resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) 				     fip, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) 	return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }