xref: /titanic_44/usr/src/uts/common/io/1394/s1394_fcp.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * s1394_fcp.c
31*7c478bd9Sstevel@tonic-gate  *    1394 Services Layer FCP Support Routines
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <sys/conf.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/tnf_probe.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <sys/1394/t1394.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/1394/h1394.h>
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate static int s1394_fcp_register_common(s1394_target_t *target,
47*7c478bd9Sstevel@tonic-gate     t1394_fcp_evts_t *evts, s1394_fa_type_t type, s1394_fa_descr_t *descr);
48*7c478bd9Sstevel@tonic-gate static int s1394_fcp_unregister_common(s1394_target_t *target,
49*7c478bd9Sstevel@tonic-gate     s1394_fa_type_t type);
50*7c478bd9Sstevel@tonic-gate static void s1394_fcp_resp_recv_write_request(cmd1394_cmd_t *req);
51*7c478bd9Sstevel@tonic-gate static void s1394_fcp_cmd_recv_write_request(cmd1394_cmd_t *req);
52*7c478bd9Sstevel@tonic-gate static void s1394_fcp_recv_write_request(cmd1394_cmd_t *req,
53*7c478bd9Sstevel@tonic-gate     s1394_fa_type_t type);
54*7c478bd9Sstevel@tonic-gate static void s1394_fcp_recv_write_unclaimed(s1394_hal_t *hal,
55*7c478bd9Sstevel@tonic-gate     cmd1394_cmd_t *req);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate  * number of retries to notify registered targets in case target list
60*7c478bd9Sstevel@tonic-gate  * changes while the list rwlock is dropped for the time of callback
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate uint_t s1394_fcp_notify_retry_cnt = 3;
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate s1394_fa_descr_t s1394_fcp_ctl_descr = {
65*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_RESP_ADDR,
66*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_RESP_SIZE,
67*7c478bd9Sstevel@tonic-gate 	T1394_ADDR_WRENBL,
68*7c478bd9Sstevel@tonic-gate 	{ NULL, s1394_fcp_resp_recv_write_request, NULL },
69*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_CMD_ADDR
70*7c478bd9Sstevel@tonic-gate };
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate s1394_fa_descr_t s1394_fcp_tgt_descr = {
73*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_CMD_ADDR,
74*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_CMD_SIZE,
75*7c478bd9Sstevel@tonic-gate 	T1394_ADDR_WRENBL,
76*7c478bd9Sstevel@tonic-gate 	{ NULL, s1394_fcp_cmd_recv_write_request, NULL },
77*7c478bd9Sstevel@tonic-gate 	IEC61883_FCP_RESP_ADDR
78*7c478bd9Sstevel@tonic-gate };
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate int
s1394_fcp_hal_init(s1394_hal_t * hal)82*7c478bd9Sstevel@tonic-gate s1394_fcp_hal_init(s1394_hal_t *hal)
83*7c478bd9Sstevel@tonic-gate {
84*7c478bd9Sstevel@tonic-gate 	int	ret = DDI_SUCCESS;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fcp_hal_init_enter, S1394_TNF_SL_FCP_STACK, "");
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	if ((ddi_prop_exists(DDI_DEV_T_ANY, hal->halinfo.dip, DDI_PROP_DONTPASS,
89*7c478bd9Sstevel@tonic-gate 	    "h1394-fcp-claim-on-demand")) == 0) {
90*7c478bd9Sstevel@tonic-gate 		/* if not on-demand, claim addresses now */
91*7c478bd9Sstevel@tonic-gate 		ret = s1394_fa_claim_addr(hal, S1394_FA_TYPE_FCP_CTL,
92*7c478bd9Sstevel@tonic-gate 					&s1394_fcp_ctl_descr);
93*7c478bd9Sstevel@tonic-gate 		if (ret == DDI_SUCCESS) {
94*7c478bd9Sstevel@tonic-gate 			ret = s1394_fa_claim_addr(hal, S1394_FA_TYPE_FCP_TGT,
95*7c478bd9Sstevel@tonic-gate 						&s1394_fcp_tgt_descr);
96*7c478bd9Sstevel@tonic-gate 			if (ret != DDI_SUCCESS) {
97*7c478bd9Sstevel@tonic-gate 				s1394_fa_free_addr(hal, S1394_FA_TYPE_FCP_CTL);
98*7c478bd9Sstevel@tonic-gate 			}
99*7c478bd9Sstevel@tonic-gate 		}
100*7c478bd9Sstevel@tonic-gate 	}
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fcp_hal_init_exit, S1394_TNF_SL_FCP_STACK, "");
103*7c478bd9Sstevel@tonic-gate 	return (ret);
104*7c478bd9Sstevel@tonic-gate }
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate int
s1394_fcp_register_ctl(s1394_target_t * target,t1394_fcp_evts_t * evts)107*7c478bd9Sstevel@tonic-gate s1394_fcp_register_ctl(s1394_target_t *target, t1394_fcp_evts_t *evts)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate 	return (s1394_fcp_register_common(target, evts, S1394_FA_TYPE_FCP_CTL,
110*7c478bd9Sstevel@tonic-gate 			&s1394_fcp_ctl_descr));
111*7c478bd9Sstevel@tonic-gate }
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate int
s1394_fcp_register_tgt(s1394_target_t * target,t1394_fcp_evts_t * evts)114*7c478bd9Sstevel@tonic-gate s1394_fcp_register_tgt(s1394_target_t *target, t1394_fcp_evts_t *evts)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate 	return (s1394_fcp_register_common(target, evts, S1394_FA_TYPE_FCP_TGT,
117*7c478bd9Sstevel@tonic-gate 			&s1394_fcp_tgt_descr));
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate int
s1394_fcp_unregister_ctl(s1394_target_t * target)121*7c478bd9Sstevel@tonic-gate s1394_fcp_unregister_ctl(s1394_target_t *target)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	return (s1394_fcp_unregister_common(target, S1394_FA_TYPE_FCP_CTL));
124*7c478bd9Sstevel@tonic-gate }
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate int
s1394_fcp_unregister_tgt(s1394_target_t * target)127*7c478bd9Sstevel@tonic-gate s1394_fcp_unregister_tgt(s1394_target_t *target)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate 	return (s1394_fcp_unregister_common(target, S1394_FA_TYPE_FCP_TGT));
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate static int
s1394_fcp_register_common(s1394_target_t * target,t1394_fcp_evts_t * evts,s1394_fa_type_t type,s1394_fa_descr_t * descr)134*7c478bd9Sstevel@tonic-gate s1394_fcp_register_common(s1394_target_t *target, t1394_fcp_evts_t *evts,
135*7c478bd9Sstevel@tonic-gate     s1394_fa_type_t type, s1394_fa_descr_t *descr)
136*7c478bd9Sstevel@tonic-gate {
137*7c478bd9Sstevel@tonic-gate 	s1394_hal_t	*hal = target->on_hal;
138*7c478bd9Sstevel@tonic-gate 	s1394_fcp_target_t *fcp;
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	rw_enter(&hal->target_list_rwlock, RW_WRITER);
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	if (s1394_fa_list_is_empty(hal, type)) {
143*7c478bd9Sstevel@tonic-gate 		if (s1394_fa_claim_addr(hal, type, descr) != DDI_SUCCESS) {
144*7c478bd9Sstevel@tonic-gate 			rw_exit(&hal->target_list_rwlock);
145*7c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
146*7c478bd9Sstevel@tonic-gate 		}
147*7c478bd9Sstevel@tonic-gate 	}
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 	/* Add on the target list */
150*7c478bd9Sstevel@tonic-gate 	s1394_fa_list_add(hal, target, type);
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	fcp = &target->target_fa[type].fat_u.fcp;
153*7c478bd9Sstevel@tonic-gate 	fcp->fc_evts = *evts;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 	rw_exit(&hal->target_list_rwlock);
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate static int
s1394_fcp_unregister_common(s1394_target_t * target,s1394_fa_type_t type)161*7c478bd9Sstevel@tonic-gate s1394_fcp_unregister_common(s1394_target_t *target, s1394_fa_type_t type)
162*7c478bd9Sstevel@tonic-gate {
163*7c478bd9Sstevel@tonic-gate 	s1394_hal_t	*hal = target->on_hal;
164*7c478bd9Sstevel@tonic-gate 	int		result;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	rw_enter(&hal->target_list_rwlock, RW_WRITER);
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	result = s1394_fa_list_remove(hal, target, type);
169*7c478bd9Sstevel@tonic-gate 	if (result == DDI_SUCCESS) {
170*7c478bd9Sstevel@tonic-gate 		if (s1394_fa_list_is_empty(hal, type)) {
171*7c478bd9Sstevel@tonic-gate 			s1394_fa_free_addr(hal, type);
172*7c478bd9Sstevel@tonic-gate 		}
173*7c478bd9Sstevel@tonic-gate 	} else {
174*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_0(s1394_fcp_unregister_common_error_list,
175*7c478bd9Sstevel@tonic-gate 		    S1394_TNF_SL_FCP_ERROR, "");
176*7c478bd9Sstevel@tonic-gate 	}
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	rw_exit(&hal->target_list_rwlock);
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	return (result);
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate /*
184*7c478bd9Sstevel@tonic-gate  * s1394_fcp_write_check_cmd()
185*7c478bd9Sstevel@tonic-gate  *    Check if an FCP command is formed correctly;
186*7c478bd9Sstevel@tonic-gate  *    set cmd_result and return DDI_FAILURE if not.
187*7c478bd9Sstevel@tonic-gate  */
188*7c478bd9Sstevel@tonic-gate int
s1394_fcp_write_check_cmd(cmd1394_cmd_t * cmd)189*7c478bd9Sstevel@tonic-gate s1394_fcp_write_check_cmd(cmd1394_cmd_t *cmd)
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	int	len;
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate 	/* 4-byte writes must be quadlet writes */
194*7c478bd9Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_WR_BLOCK) {
195*7c478bd9Sstevel@tonic-gate 		len = cmd->cmd_u.b.blk_length;
196*7c478bd9Sstevel@tonic-gate 		if (len == 4) {
197*7c478bd9Sstevel@tonic-gate 			cmd->cmd_result = CMD1394_ETYPE_ERROR;
198*7c478bd9Sstevel@tonic-gate 			TNF_PROBE_0(t1394_write_error_type,
199*7c478bd9Sstevel@tonic-gate 			    S1394_TNF_SL_FCP_ERROR, "");
200*7c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
201*7c478bd9Sstevel@tonic-gate 		}
202*7c478bd9Sstevel@tonic-gate 	} else {
203*7c478bd9Sstevel@tonic-gate 		len = 4;
204*7c478bd9Sstevel@tonic-gate 	}
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 	/*
207*7c478bd9Sstevel@tonic-gate 	 * request must be within FCP range. we avoid extra checks by
208*7c478bd9Sstevel@tonic-gate 	 * using the fact that command and response are of the same size
209*7c478bd9Sstevel@tonic-gate 	 */
210*7c478bd9Sstevel@tonic-gate 	if ((cmd->cmd_addr & IEEE1394_ADDR_OFFSET_MASK) + len >
211*7c478bd9Sstevel@tonic-gate 	    IEC61883_FCP_CMD_SIZE) {
212*7c478bd9Sstevel@tonic-gate 		cmd->cmd_result = CMD1394_EADDRESS_ERROR;
213*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_0(t1394_write_error_addr, S1394_TNF_SL_FCP_ERROR, "");
214*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
215*7c478bd9Sstevel@tonic-gate 	}
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 	/* some options don't make sense for FCP commands */
218*7c478bd9Sstevel@tonic-gate 	if (cmd->cmd_options & CMD1394_OVERRIDE_ADDR) {
219*7c478bd9Sstevel@tonic-gate 		cmd->cmd_result = CMD1394_EINVALID_COMMAND;
220*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_0(t1394_write_error_opt, S1394_TNF_SL_FCP_ERROR, "");
221*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
222*7c478bd9Sstevel@tonic-gate 	}
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate static void
s1394_fcp_resp_recv_write_request(cmd1394_cmd_t * req)228*7c478bd9Sstevel@tonic-gate s1394_fcp_resp_recv_write_request(cmd1394_cmd_t *req)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate 	s1394_fcp_recv_write_request(req, S1394_FA_TYPE_FCP_CTL);
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate static void
s1394_fcp_cmd_recv_write_request(cmd1394_cmd_t * req)234*7c478bd9Sstevel@tonic-gate s1394_fcp_cmd_recv_write_request(cmd1394_cmd_t *req)
235*7c478bd9Sstevel@tonic-gate {
236*7c478bd9Sstevel@tonic-gate 	s1394_fcp_recv_write_request(req, S1394_FA_TYPE_FCP_TGT);
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate /*
240*7c478bd9Sstevel@tonic-gate  * s1394_fcp_recv_write_request()
241*7c478bd9Sstevel@tonic-gate  *    Common write request handler
242*7c478bd9Sstevel@tonic-gate  */
243*7c478bd9Sstevel@tonic-gate static void
s1394_fcp_recv_write_request(cmd1394_cmd_t * req,s1394_fa_type_t type)244*7c478bd9Sstevel@tonic-gate s1394_fcp_recv_write_request(cmd1394_cmd_t *req, s1394_fa_type_t type)
245*7c478bd9Sstevel@tonic-gate {
246*7c478bd9Sstevel@tonic-gate 	s1394_hal_t	*hal = (s1394_hal_t *)req->cmd_callback_arg;
247*7c478bd9Sstevel@tonic-gate 	s1394_target_t	*target;
248*7c478bd9Sstevel@tonic-gate 	s1394_fa_target_t *fat;
249*7c478bd9Sstevel@tonic-gate 	uint_t		saved_gen;
250*7c478bd9Sstevel@tonic-gate 	int		num_retries = 0;
251*7c478bd9Sstevel@tonic-gate 	int		(*cb)(cmd1394_cmd_t *req);
252*7c478bd9Sstevel@tonic-gate 	boolean_t	restored = B_FALSE;
253*7c478bd9Sstevel@tonic-gate 	int		ret = T1394_REQ_UNCLAIMED;
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fcp_recv_write_request_enter,
256*7c478bd9Sstevel@tonic-gate 	    S1394_TNF_SL_FCP_STACK, "");
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	rw_enter(&hal->target_list_rwlock, RW_READER);
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate start:
261*7c478bd9Sstevel@tonic-gate 	target = hal->hal_fa[type].fal_head;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	if (target) {
264*7c478bd9Sstevel@tonic-gate 		s1394_fa_restore_cmd(hal, req);
265*7c478bd9Sstevel@tonic-gate 		restored = B_TRUE;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 		/* Find a target that claims the request */
268*7c478bd9Sstevel@tonic-gate 		do {
269*7c478bd9Sstevel@tonic-gate 			fat = &target->target_fa[type];
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 			cb = fat->fat_u.fcp.fc_evts.fcp_write_request;
272*7c478bd9Sstevel@tonic-gate 			if (cb == NULL) {
273*7c478bd9Sstevel@tonic-gate 				continue;
274*7c478bd9Sstevel@tonic-gate 			}
275*7c478bd9Sstevel@tonic-gate 			req->cmd_callback_arg = fat->fat_u.fcp.fc_evts.fcp_arg;
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 			saved_gen = s1394_fa_list_gen(hal, type);
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 			rw_exit(&hal->target_list_rwlock);
280*7c478bd9Sstevel@tonic-gate 			ret = cb(req);
281*7c478bd9Sstevel@tonic-gate 			rw_enter(&hal->target_list_rwlock, RW_READER);
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 			if (ret == T1394_REQ_CLAIMED) {
284*7c478bd9Sstevel@tonic-gate 				break;
285*7c478bd9Sstevel@tonic-gate 			}
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate 			/*
288*7c478bd9Sstevel@tonic-gate 			 * List could change while we dropped the lock. In such
289*7c478bd9Sstevel@tonic-gate 			 * case, start all over again, because missing a write
290*7c478bd9Sstevel@tonic-gate 			 * request can have more serious consequences for a
291*7c478bd9Sstevel@tonic-gate 			 * target than receiving same request more than once
292*7c478bd9Sstevel@tonic-gate 			 */
293*7c478bd9Sstevel@tonic-gate 			if (saved_gen != s1394_fa_list_gen(hal, type)) {
294*7c478bd9Sstevel@tonic-gate 				TNF_PROBE_2(s1394_fcp_recv_write_request_error,
295*7c478bd9Sstevel@tonic-gate 				    S1394_TNF_SL_FCP_ERROR, "",
296*7c478bd9Sstevel@tonic-gate 				    tnf_string, msg, "list gen changed",
297*7c478bd9Sstevel@tonic-gate 				    tnf_opaque, num_retries, num_retries);
298*7c478bd9Sstevel@tonic-gate 				num_retries++;
299*7c478bd9Sstevel@tonic-gate 				if (num_retries <= s1394_fcp_notify_retry_cnt) {
300*7c478bd9Sstevel@tonic-gate 					goto start;
301*7c478bd9Sstevel@tonic-gate 				} else {
302*7c478bd9Sstevel@tonic-gate 					break;
303*7c478bd9Sstevel@tonic-gate 				}
304*7c478bd9Sstevel@tonic-gate 			}
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 			target = fat->fat_next;
307*7c478bd9Sstevel@tonic-gate 		} while (target != NULL);
308*7c478bd9Sstevel@tonic-gate 	}
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 	rw_exit(&hal->target_list_rwlock);
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 	if (ret != T1394_REQ_CLAIMED) {
313*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_0(s1394_fcp_recv_write_request_error_unclaimed,
314*7c478bd9Sstevel@tonic-gate 		    S1394_TNF_SL_FCP_ERROR, "");
315*7c478bd9Sstevel@tonic-gate 		if (restored) {
316*7c478bd9Sstevel@tonic-gate 			s1394_fa_convert_cmd(hal, req);
317*7c478bd9Sstevel@tonic-gate 		}
318*7c478bd9Sstevel@tonic-gate 		s1394_fcp_recv_write_unclaimed(hal, req);
319*7c478bd9Sstevel@tonic-gate 	}
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fcp_recv_write_request_exit,
322*7c478bd9Sstevel@tonic-gate 	    S1394_TNF_SL_FCP_STACK, "");
323*7c478bd9Sstevel@tonic-gate }
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate /*
326*7c478bd9Sstevel@tonic-gate  * none of the targets claimed the request - send an appropriate response
327*7c478bd9Sstevel@tonic-gate  */
328*7c478bd9Sstevel@tonic-gate static void
s1394_fcp_recv_write_unclaimed(s1394_hal_t * hal,cmd1394_cmd_t * req)329*7c478bd9Sstevel@tonic-gate s1394_fcp_recv_write_unclaimed(s1394_hal_t *hal, cmd1394_cmd_t *req)
330*7c478bd9Sstevel@tonic-gate {
331*7c478bd9Sstevel@tonic-gate 	req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
332*7c478bd9Sstevel@tonic-gate 	(void) s1394_send_response(hal, req);
333*7c478bd9Sstevel@tonic-gate }
334