diff options
Diffstat (limited to 'drivers/scsi/libfc/fc_fcp.c')
-rw-r--r-- | drivers/scsi/libfc/fc_fcp.c | 1044 |
1 files changed, 552 insertions, 492 deletions
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c index 59a4408b27b5..c4b58d042f6f 100644 --- a/drivers/scsi/libfc/fc_fcp.c +++ b/drivers/scsi/libfc/fc_fcp.c | |||
@@ -39,15 +39,9 @@ | |||
39 | #include <scsi/libfc.h> | 39 | #include <scsi/libfc.h> |
40 | #include <scsi/fc_encode.h> | 40 | #include <scsi/fc_encode.h> |
41 | 41 | ||
42 | MODULE_AUTHOR("Open-FCoE.org"); | 42 | #include "fc_libfc.h" |
43 | MODULE_DESCRIPTION("libfc"); | ||
44 | MODULE_LICENSE("GPL v2"); | ||
45 | 43 | ||
46 | unsigned int fc_debug_logging; | 44 | struct kmem_cache *scsi_pkt_cachep; |
47 | module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR); | ||
48 | MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); | ||
49 | |||
50 | static struct kmem_cache *scsi_pkt_cachep; | ||
51 | 45 | ||
52 | /* SRB state definitions */ | 46 | /* SRB state definitions */ |
53 | #define FC_SRB_FREE 0 /* cmd is free */ | 47 | #define FC_SRB_FREE 0 /* cmd is free */ |
@@ -58,7 +52,6 @@ static struct kmem_cache *scsi_pkt_cachep; | |||
58 | #define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */ | 52 | #define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */ |
59 | #define FC_SRB_COMPL (1 << 5) /* fc_io_compl has been run */ | 53 | #define FC_SRB_COMPL (1 << 5) /* fc_io_compl has been run */ |
60 | #define FC_SRB_FCP_PROCESSING_TMO (1 << 6) /* timer function processing */ | 54 | #define FC_SRB_FCP_PROCESSING_TMO (1 << 6) /* timer function processing */ |
61 | #define FC_SRB_NOMEM (1 << 7) /* dropped to out of mem */ | ||
62 | 55 | ||
63 | #define FC_SRB_READ (1 << 1) | 56 | #define FC_SRB_READ (1 << 1) |
64 | #define FC_SRB_WRITE (1 << 0) | 57 | #define FC_SRB_WRITE (1 << 0) |
@@ -73,10 +66,20 @@ static struct kmem_cache *scsi_pkt_cachep; | |||
73 | #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status) | 66 | #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status) |
74 | #define CMD_RESID_LEN(Cmnd) ((Cmnd)->SCp.buffers_residual) | 67 | #define CMD_RESID_LEN(Cmnd) ((Cmnd)->SCp.buffers_residual) |
75 | 68 | ||
69 | /** | ||
70 | * struct fc_fcp_internal - FCP layer internal data | ||
71 | * @scsi_pkt_pool: Memory pool to draw FCP packets from | ||
72 | * @scsi_pkt_queue: Current FCP packets | ||
73 | * @last_can_queue_ramp_down_time: ramp down time | ||
74 | * @last_can_queue_ramp_up_time: ramp up time | ||
75 | * @max_can_queue: max can_queue size | ||
76 | */ | ||
76 | struct fc_fcp_internal { | 77 | struct fc_fcp_internal { |
77 | mempool_t *scsi_pkt_pool; | 78 | mempool_t *scsi_pkt_pool; |
78 | struct list_head scsi_pkt_queue; | 79 | struct list_head scsi_pkt_queue; |
79 | u8 throttled; | 80 | unsigned long last_can_queue_ramp_down_time; |
81 | unsigned long last_can_queue_ramp_up_time; | ||
82 | int max_can_queue; | ||
80 | }; | 83 | }; |
81 | 84 | ||
82 | #define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv) | 85 | #define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv) |
@@ -90,9 +93,9 @@ static void fc_fcp_recv(struct fc_seq *, struct fc_frame *, void *); | |||
90 | static void fc_fcp_resp(struct fc_fcp_pkt *, struct fc_frame *); | 93 | static void fc_fcp_resp(struct fc_fcp_pkt *, struct fc_frame *); |
91 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *); | 94 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *); |
92 | static void fc_tm_done(struct fc_seq *, struct fc_frame *, void *); | 95 | static void fc_tm_done(struct fc_seq *, struct fc_frame *, void *); |
93 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp); | 96 | static void fc_fcp_error(struct fc_fcp_pkt *, struct fc_frame *); |
94 | static void fc_timeout_error(struct fc_fcp_pkt *); | 97 | static void fc_timeout_error(struct fc_fcp_pkt *); |
95 | static void fc_fcp_timeout(unsigned long data); | 98 | static void fc_fcp_timeout(unsigned long); |
96 | static void fc_fcp_rec(struct fc_fcp_pkt *); | 99 | static void fc_fcp_rec(struct fc_fcp_pkt *); |
97 | static void fc_fcp_rec_error(struct fc_fcp_pkt *, struct fc_frame *); | 100 | static void fc_fcp_rec_error(struct fc_fcp_pkt *, struct fc_frame *); |
98 | static void fc_fcp_rec_resp(struct fc_seq *, struct fc_frame *, void *); | 101 | static void fc_fcp_rec_resp(struct fc_seq *, struct fc_frame *, void *); |
@@ -124,6 +127,7 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *); | |||
124 | #define FC_SCSI_TM_TOV (10 * HZ) | 127 | #define FC_SCSI_TM_TOV (10 * HZ) |
125 | #define FC_SCSI_REC_TOV (2 * HZ) | 128 | #define FC_SCSI_REC_TOV (2 * HZ) |
126 | #define FC_HOST_RESET_TIMEOUT (30 * HZ) | 129 | #define FC_HOST_RESET_TIMEOUT (30 * HZ) |
130 | #define FC_CAN_QUEUE_PERIOD (60 * HZ) | ||
127 | 131 | ||
128 | #define FC_MAX_ERROR_CNT 5 | 132 | #define FC_MAX_ERROR_CNT 5 |
129 | #define FC_MAX_RECOV_RETRY 3 | 133 | #define FC_MAX_RECOV_RETRY 3 |
@@ -131,23 +135,22 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *); | |||
131 | #define FC_FCP_DFLT_QUEUE_DEPTH 32 | 135 | #define FC_FCP_DFLT_QUEUE_DEPTH 32 |
132 | 136 | ||
133 | /** | 137 | /** |
134 | * fc_fcp_pkt_alloc - allocation routine for scsi_pkt packet | 138 | * fc_fcp_pkt_alloc() - Allocate a fcp_pkt |
135 | * @lp: fc lport struct | 139 | * @lport: The local port that the FCP packet is for |
136 | * @gfp: gfp flags for allocation | 140 | * @gfp: GFP flags for allocation |
137 | * | 141 | * |
138 | * This is used by upper layer scsi driver. | 142 | * Return value: fcp_pkt structure or null on allocation failure. |
139 | * Return Value : scsi_pkt structure or null on allocation failure. | 143 | * Context: Can be called from process context, no lock is required. |
140 | * Context : call from process context. no locking required. | ||
141 | */ | 144 | */ |
142 | static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lp, gfp_t gfp) | 145 | static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lport, gfp_t gfp) |
143 | { | 146 | { |
144 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 147 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
145 | struct fc_fcp_pkt *fsp; | 148 | struct fc_fcp_pkt *fsp; |
146 | 149 | ||
147 | fsp = mempool_alloc(si->scsi_pkt_pool, gfp); | 150 | fsp = mempool_alloc(si->scsi_pkt_pool, gfp); |
148 | if (fsp) { | 151 | if (fsp) { |
149 | memset(fsp, 0, sizeof(*fsp)); | 152 | memset(fsp, 0, sizeof(*fsp)); |
150 | fsp->lp = lp; | 153 | fsp->lp = lport; |
151 | atomic_set(&fsp->ref_cnt, 1); | 154 | atomic_set(&fsp->ref_cnt, 1); |
152 | init_timer(&fsp->timer); | 155 | init_timer(&fsp->timer); |
153 | INIT_LIST_HEAD(&fsp->list); | 156 | INIT_LIST_HEAD(&fsp->list); |
@@ -157,12 +160,11 @@ static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lp, gfp_t gfp) | |||
157 | } | 160 | } |
158 | 161 | ||
159 | /** | 162 | /** |
160 | * fc_fcp_pkt_release() - release hold on scsi_pkt packet | 163 | * fc_fcp_pkt_release() - Release hold on a fcp_pkt |
161 | * @fsp: fcp packet struct | 164 | * @fsp: The FCP packet to be released |
162 | * | 165 | * |
163 | * This is used by upper layer scsi driver. | 166 | * Context: Can be called from process or interrupt context, |
164 | * Context : call from process and interrupt context. | 167 | * no lock is required. |
165 | * no locking required | ||
166 | */ | 168 | */ |
167 | static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) | 169 | static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) |
168 | { | 170 | { |
@@ -173,20 +175,25 @@ static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) | |||
173 | } | 175 | } |
174 | } | 176 | } |
175 | 177 | ||
178 | /** | ||
179 | * fc_fcp_pkt_hold() - Hold a fcp_pkt | ||
180 | * @fsp: The FCP packet to be held | ||
181 | */ | ||
176 | static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) | 182 | static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) |
177 | { | 183 | { |
178 | atomic_inc(&fsp->ref_cnt); | 184 | atomic_inc(&fsp->ref_cnt); |
179 | } | 185 | } |
180 | 186 | ||
181 | /** | 187 | /** |
182 | * fc_fcp_pkt_destory() - release hold on scsi_pkt packet | 188 | * fc_fcp_pkt_destory() - Release hold on a fcp_pkt |
183 | * @seq: exchange sequence | 189 | * @seq: The sequence that the FCP packet is on (required by destructor API) |
184 | * @fsp: fcp packet struct | 190 | * @fsp: The FCP packet to be released |
191 | * | ||
192 | * This routine is called by a destructor callback in the exch_seq_send() | ||
193 | * routine of the libfc Transport Template. The 'struct fc_seq' is a required | ||
194 | * argument even though it is not used by this routine. | ||
185 | * | 195 | * |
186 | * Release hold on scsi_pkt packet set to keep scsi_pkt | 196 | * Context: No locking required. |
187 | * till EM layer exch resource is not freed. | ||
188 | * Context : called from from EM layer. | ||
189 | * no locking required | ||
190 | */ | 197 | */ |
191 | static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) | 198 | static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) |
192 | { | 199 | { |
@@ -194,10 +201,10 @@ static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) | |||
194 | } | 201 | } |
195 | 202 | ||
196 | /** | 203 | /** |
197 | * fc_fcp_lock_pkt() - lock a packet and get a ref to it. | 204 | * fc_fcp_lock_pkt() - Lock a fcp_pkt and increase its reference count |
198 | * @fsp: fcp packet | 205 | * @fsp: The FCP packet to be locked and incremented |
199 | * | 206 | * |
200 | * We should only return error if we return a command to scsi-ml before | 207 | * We should only return error if we return a command to SCSI-ml before |
201 | * getting a response. This can happen in cases where we send a abort, but | 208 | * getting a response. This can happen in cases where we send a abort, but |
202 | * do not wait for the response and the abort and command can be passing | 209 | * do not wait for the response and the abort and command can be passing |
203 | * each other on the wire/network-layer. | 210 | * each other on the wire/network-layer. |
@@ -222,18 +229,33 @@ static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp) | |||
222 | return 0; | 229 | return 0; |
223 | } | 230 | } |
224 | 231 | ||
232 | /** | ||
233 | * fc_fcp_unlock_pkt() - Release a fcp_pkt's lock and decrement its | ||
234 | * reference count | ||
235 | * @fsp: The FCP packet to be unlocked and decremented | ||
236 | */ | ||
225 | static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) | 237 | static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) |
226 | { | 238 | { |
227 | spin_unlock_bh(&fsp->scsi_pkt_lock); | 239 | spin_unlock_bh(&fsp->scsi_pkt_lock); |
228 | fc_fcp_pkt_release(fsp); | 240 | fc_fcp_pkt_release(fsp); |
229 | } | 241 | } |
230 | 242 | ||
243 | /** | ||
244 | * fc_fcp_timer_set() - Start a timer for a fcp_pkt | ||
245 | * @fsp: The FCP packet to start a timer for | ||
246 | * @delay: The timeout period for the timer | ||
247 | */ | ||
231 | static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) | 248 | static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) |
232 | { | 249 | { |
233 | if (!(fsp->state & FC_SRB_COMPL)) | 250 | if (!(fsp->state & FC_SRB_COMPL)) |
234 | mod_timer(&fsp->timer, jiffies + delay); | 251 | mod_timer(&fsp->timer, jiffies + delay); |
235 | } | 252 | } |
236 | 253 | ||
254 | /** | ||
255 | * fc_fcp_send_abort() - Send an abort for exchanges associated with a | ||
256 | * fcp_pkt | ||
257 | * @fsp: The FCP packet to abort exchanges on | ||
258 | */ | ||
237 | static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) | 259 | static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) |
238 | { | 260 | { |
239 | if (!fsp->seq_ptr) | 261 | if (!fsp->seq_ptr) |
@@ -243,9 +265,14 @@ static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) | |||
243 | return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0); | 265 | return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0); |
244 | } | 266 | } |
245 | 267 | ||
246 | /* | 268 | /** |
247 | * Retry command. | 269 | * fc_fcp_retry_cmd() - Retry a fcp_pkt |
248 | * An abort isn't needed. | 270 | * @fsp: The FCP packet to be retried |
271 | * | ||
272 | * Sets the status code to be FC_ERROR and then calls | ||
273 | * fc_fcp_complete_locked() which in turn calls fc_io_compl(). | ||
274 | * fc_io_compl() will notify the SCSI-ml that the I/O is done. | ||
275 | * The SCSI-ml will retry the command. | ||
249 | */ | 276 | */ |
250 | static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) | 277 | static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) |
251 | { | 278 | { |
@@ -260,64 +287,146 @@ static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) | |||
260 | fc_fcp_complete_locked(fsp); | 287 | fc_fcp_complete_locked(fsp); |
261 | } | 288 | } |
262 | 289 | ||
263 | /* | 290 | /** |
264 | * fc_fcp_ddp_setup - calls to LLD's ddp_setup to set up DDP | 291 | * fc_fcp_ddp_setup() - Calls a LLD's ddp_setup routine to set up DDP context |
265 | * transfer for a read I/O indicated by the fc_fcp_pkt. | 292 | * @fsp: The FCP packet that will manage the DDP frames |
266 | * @fsp: ptr to the fc_fcp_pkt | 293 | * @xid: The XID that will be used for the DDP exchange |
267 | * | ||
268 | * This is called in exch_seq_send() when we have a newly allocated | ||
269 | * exchange with a valid exchange id to setup ddp. | ||
270 | * | ||
271 | * returns: none | ||
272 | */ | 294 | */ |
273 | void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) | 295 | void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) |
274 | { | 296 | { |
275 | struct fc_lport *lp; | 297 | struct fc_lport *lport; |
276 | 298 | ||
277 | if (!fsp) | 299 | if (!fsp) |
278 | return; | 300 | return; |
279 | 301 | ||
280 | lp = fsp->lp; | 302 | lport = fsp->lp; |
281 | if ((fsp->req_flags & FC_SRB_READ) && | 303 | if ((fsp->req_flags & FC_SRB_READ) && |
282 | (lp->lro_enabled) && (lp->tt.ddp_setup)) { | 304 | (lport->lro_enabled) && (lport->tt.ddp_setup)) { |
283 | if (lp->tt.ddp_setup(lp, xid, scsi_sglist(fsp->cmd), | 305 | if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd), |
284 | scsi_sg_count(fsp->cmd))) | 306 | scsi_sg_count(fsp->cmd))) |
285 | fsp->xfer_ddp = xid; | 307 | fsp->xfer_ddp = xid; |
286 | } | 308 | } |
287 | } | 309 | } |
288 | EXPORT_SYMBOL(fc_fcp_ddp_setup); | ||
289 | 310 | ||
290 | /* | 311 | /** |
291 | * fc_fcp_ddp_done - calls to LLD's ddp_done to release any | 312 | * fc_fcp_ddp_done() - Calls a LLD's ddp_done routine to release any |
292 | * DDP related resources for this I/O if it is initialized | 313 | * DDP related resources for a fcp_pkt |
293 | * as a ddp transfer | 314 | * @fsp: The FCP packet that DDP had been used on |
294 | * @fsp: ptr to the fc_fcp_pkt | ||
295 | * | ||
296 | * returns: none | ||
297 | */ | 315 | */ |
298 | static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) | 316 | static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) |
299 | { | 317 | { |
300 | struct fc_lport *lp; | 318 | struct fc_lport *lport; |
301 | 319 | ||
302 | if (!fsp) | 320 | if (!fsp) |
303 | return; | 321 | return; |
304 | 322 | ||
305 | lp = fsp->lp; | 323 | if (fsp->xfer_ddp == FC_XID_UNKNOWN) |
306 | if (fsp->xfer_ddp && lp->tt.ddp_done) { | 324 | return; |
307 | fsp->xfer_len = lp->tt.ddp_done(lp, fsp->xfer_ddp); | 325 | |
308 | fsp->xfer_ddp = 0; | 326 | lport = fsp->lp; |
327 | if (lport->tt.ddp_done) { | ||
328 | fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp); | ||
329 | fsp->xfer_ddp = FC_XID_UNKNOWN; | ||
309 | } | 330 | } |
310 | } | 331 | } |
311 | 332 | ||
333 | /** | ||
334 | * fc_fcp_can_queue_ramp_up() - increases can_queue | ||
335 | * @lport: lport to ramp up can_queue | ||
336 | * | ||
337 | * Locking notes: Called with Scsi_Host lock held | ||
338 | */ | ||
339 | static void fc_fcp_can_queue_ramp_up(struct fc_lport *lport) | ||
340 | { | ||
341 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); | ||
342 | int can_queue; | ||
343 | |||
344 | if (si->last_can_queue_ramp_up_time && | ||
345 | (time_before(jiffies, si->last_can_queue_ramp_up_time + | ||
346 | FC_CAN_QUEUE_PERIOD))) | ||
347 | return; | ||
348 | |||
349 | if (time_before(jiffies, si->last_can_queue_ramp_down_time + | ||
350 | FC_CAN_QUEUE_PERIOD)) | ||
351 | return; | ||
352 | |||
353 | si->last_can_queue_ramp_up_time = jiffies; | ||
354 | |||
355 | can_queue = lport->host->can_queue << 1; | ||
356 | if (can_queue >= si->max_can_queue) { | ||
357 | can_queue = si->max_can_queue; | ||
358 | si->last_can_queue_ramp_down_time = 0; | ||
359 | } | ||
360 | lport->host->can_queue = can_queue; | ||
361 | shost_printk(KERN_ERR, lport->host, "libfc: increased " | ||
362 | "can_queue to %d.\n", can_queue); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * fc_fcp_can_queue_ramp_down() - reduces can_queue | ||
367 | * @lport: lport to reduce can_queue | ||
368 | * | ||
369 | * If we are getting memory allocation failures, then we may | ||
370 | * be trying to execute too many commands. We let the running | ||
371 | * commands complete or timeout, then try again with a reduced | ||
372 | * can_queue. Eventually we will hit the point where we run | ||
373 | * on all reserved structs. | ||
374 | * | ||
375 | * Locking notes: Called with Scsi_Host lock held | ||
376 | */ | ||
377 | static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport) | ||
378 | { | ||
379 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); | ||
380 | int can_queue; | ||
381 | |||
382 | if (si->last_can_queue_ramp_down_time && | ||
383 | (time_before(jiffies, si->last_can_queue_ramp_down_time + | ||
384 | FC_CAN_QUEUE_PERIOD))) | ||
385 | return; | ||
386 | |||
387 | si->last_can_queue_ramp_down_time = jiffies; | ||
388 | |||
389 | can_queue = lport->host->can_queue; | ||
390 | can_queue >>= 1; | ||
391 | if (!can_queue) | ||
392 | can_queue = 1; | ||
393 | lport->host->can_queue = can_queue; | ||
394 | shost_printk(KERN_ERR, lport->host, "libfc: Could not allocate frame.\n" | ||
395 | "Reducing can_queue to %d.\n", can_queue); | ||
396 | } | ||
312 | 397 | ||
313 | /* | 398 | /* |
314 | * Receive SCSI data from target. | 399 | * fc_fcp_frame_alloc() - Allocates fc_frame structure and buffer. |
315 | * Called after receiving solicited data. | 400 | * @lport: fc lport struct |
401 | * @len: payload length | ||
402 | * | ||
403 | * Allocates fc_frame structure and buffer but if fails to allocate | ||
404 | * then reduce can_queue. | ||
405 | */ | ||
406 | static inline struct fc_frame *fc_fcp_frame_alloc(struct fc_lport *lport, | ||
407 | size_t len) | ||
408 | { | ||
409 | struct fc_frame *fp; | ||
410 | unsigned long flags; | ||
411 | |||
412 | fp = fc_frame_alloc(lport, len); | ||
413 | if (!fp) { | ||
414 | spin_lock_irqsave(lport->host->host_lock, flags); | ||
415 | fc_fcp_can_queue_ramp_down(lport); | ||
416 | spin_unlock_irqrestore(lport->host->host_lock, flags); | ||
417 | } | ||
418 | return fp; | ||
419 | } | ||
420 | |||
421 | /** | ||
422 | * fc_fcp_recv_data() - Handler for receiving SCSI-FCP data from a target | ||
423 | * @fsp: The FCP packet the data is on | ||
424 | * @fp: The data frame | ||
316 | */ | 425 | */ |
317 | static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 426 | static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
318 | { | 427 | { |
319 | struct scsi_cmnd *sc = fsp->cmd; | 428 | struct scsi_cmnd *sc = fsp->cmd; |
320 | struct fc_lport *lp = fsp->lp; | 429 | struct fc_lport *lport = fsp->lp; |
321 | struct fcoe_dev_stats *stats; | 430 | struct fcoe_dev_stats *stats; |
322 | struct fc_frame_header *fh; | 431 | struct fc_frame_header *fh; |
323 | size_t start_offset; | 432 | size_t start_offset; |
@@ -327,7 +436,7 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
327 | size_t len; | 436 | size_t len; |
328 | void *buf; | 437 | void *buf; |
329 | struct scatterlist *sg; | 438 | struct scatterlist *sg; |
330 | size_t remaining; | 439 | u32 nents; |
331 | 440 | ||
332 | fh = fc_frame_header_get(fp); | 441 | fh = fc_frame_header_get(fp); |
333 | offset = ntohl(fh->fh_parm_offset); | 442 | offset = ntohl(fh->fh_parm_offset); |
@@ -351,65 +460,29 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
351 | if (offset != fsp->xfer_len) | 460 | if (offset != fsp->xfer_len) |
352 | fsp->state |= FC_SRB_DISCONTIG; | 461 | fsp->state |= FC_SRB_DISCONTIG; |
353 | 462 | ||
354 | crc = 0; | ||
355 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) | ||
356 | crc = crc32(~0, (u8 *) fh, sizeof(*fh)); | ||
357 | |||
358 | sg = scsi_sglist(sc); | 463 | sg = scsi_sglist(sc); |
359 | remaining = len; | 464 | nents = scsi_sg_count(sc); |
360 | |||
361 | while (remaining > 0 && sg) { | ||
362 | size_t off; | ||
363 | void *page_addr; | ||
364 | size_t sg_bytes; | ||
365 | 465 | ||
366 | if (offset >= sg->length) { | 466 | if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED)) { |
367 | offset -= sg->length; | 467 | copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents, |
368 | sg = sg_next(sg); | 468 | &offset, KM_SOFTIRQ0, NULL); |
369 | continue; | 469 | } else { |
370 | } | 470 | crc = crc32(~0, (u8 *) fh, sizeof(*fh)); |
371 | sg_bytes = min(remaining, sg->length - offset); | 471 | copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents, |
372 | 472 | &offset, KM_SOFTIRQ0, &crc); | |
373 | /* | ||
374 | * The scatterlist item may be bigger than PAGE_SIZE, | ||
375 | * but we are limited to mapping PAGE_SIZE at a time. | ||
376 | */ | ||
377 | off = offset + sg->offset; | ||
378 | sg_bytes = min(sg_bytes, (size_t) | ||
379 | (PAGE_SIZE - (off & ~PAGE_MASK))); | ||
380 | page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT), | ||
381 | KM_SOFTIRQ0); | ||
382 | if (!page_addr) | ||
383 | break; /* XXX panic? */ | ||
384 | |||
385 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) | ||
386 | crc = crc32(crc, buf, sg_bytes); | ||
387 | memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, | ||
388 | sg_bytes); | ||
389 | |||
390 | kunmap_atomic(page_addr, KM_SOFTIRQ0); | ||
391 | buf += sg_bytes; | ||
392 | offset += sg_bytes; | ||
393 | remaining -= sg_bytes; | ||
394 | copy_len += sg_bytes; | ||
395 | } | ||
396 | |||
397 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) { | ||
398 | buf = fc_frame_payload_get(fp, 0); | 473 | buf = fc_frame_payload_get(fp, 0); |
399 | if (len % 4) { | 474 | if (len % 4) |
400 | crc = crc32(crc, buf + len, 4 - (len % 4)); | 475 | crc = crc32(crc, buf + len, 4 - (len % 4)); |
401 | len += 4 - (len % 4); | ||
402 | } | ||
403 | 476 | ||
404 | if (~crc != le32_to_cpu(fr_crc(fp))) { | 477 | if (~crc != le32_to_cpu(fr_crc(fp))) { |
405 | crc_err: | 478 | crc_err: |
406 | stats = fc_lport_get_stats(lp); | 479 | stats = fc_lport_get_stats(lport); |
407 | stats->ErrorFrames++; | 480 | stats->ErrorFrames++; |
408 | /* FIXME - per cpu count, not total count! */ | 481 | /* FIXME - per cpu count, not total count! */ |
409 | if (stats->InvalidCRCCount++ < 5) | 482 | if (stats->InvalidCRCCount++ < 5) |
410 | printk(KERN_WARNING "libfc: CRC error on data " | 483 | printk(KERN_WARNING "libfc: CRC error on data " |
411 | "frame for port (%6x)\n", | 484 | "frame for port (%6x)\n", |
412 | fc_host_port_id(lp->host)); | 485 | fc_host_port_id(lport->host)); |
413 | /* | 486 | /* |
414 | * Assume the frame is total garbage. | 487 | * Assume the frame is total garbage. |
415 | * We may have copied it over the good part | 488 | * We may have copied it over the good part |
@@ -437,18 +510,17 @@ crc_err: | |||
437 | } | 510 | } |
438 | 511 | ||
439 | /** | 512 | /** |
440 | * fc_fcp_send_data() - Send SCSI data to target. | 513 | * fc_fcp_send_data() - Send SCSI data to a target |
441 | * @fsp: ptr to fc_fcp_pkt | 514 | * @fsp: The FCP packet the data is on |
442 | * @sp: ptr to this sequence | 515 | * @sp: The sequence the data is to be sent on |
443 | * @offset: starting offset for this data request | 516 | * @offset: The starting offset for this data request |
444 | * @seq_blen: the burst length for this data request | 517 | * @seq_blen: The burst length for this data request |
445 | * | 518 | * |
446 | * Called after receiving a Transfer Ready data descriptor. | 519 | * Called after receiving a Transfer Ready data descriptor. |
447 | * if LLD is capable of seq offload then send down seq_blen | 520 | * If the LLD is capable of sequence offload then send down the |
448 | * size of data in single frame, otherwise send multiple FC | 521 | * seq_blen ammount of data in single frame, otherwise send |
449 | * frames of max FC frame payload supported by target port. | 522 | * multiple frames of the maximum frame payload supported by |
450 | * | 523 | * the target port. |
451 | * Returns : 0 for success. | ||
452 | */ | 524 | */ |
453 | static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | 525 | static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, |
454 | size_t offset, size_t seq_blen) | 526 | size_t offset, size_t seq_blen) |
@@ -457,16 +529,18 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
457 | struct scsi_cmnd *sc; | 529 | struct scsi_cmnd *sc; |
458 | struct scatterlist *sg; | 530 | struct scatterlist *sg; |
459 | struct fc_frame *fp = NULL; | 531 | struct fc_frame *fp = NULL; |
460 | struct fc_lport *lp = fsp->lp; | 532 | struct fc_lport *lport = fsp->lp; |
533 | struct page *page; | ||
461 | size_t remaining; | 534 | size_t remaining; |
462 | size_t t_blen; | 535 | size_t t_blen; |
463 | size_t tlen; | 536 | size_t tlen; |
464 | size_t sg_bytes; | 537 | size_t sg_bytes; |
465 | size_t frame_offset, fh_parm_offset; | 538 | size_t frame_offset, fh_parm_offset; |
539 | size_t off; | ||
466 | int error; | 540 | int error; |
467 | void *data = NULL; | 541 | void *data = NULL; |
468 | void *page_addr; | 542 | void *page_addr; |
469 | int using_sg = lp->sg_supp; | 543 | int using_sg = lport->sg_supp; |
470 | u32 f_ctl; | 544 | u32 f_ctl; |
471 | 545 | ||
472 | WARN_ON(seq_blen <= 0); | 546 | WARN_ON(seq_blen <= 0); |
@@ -488,10 +562,10 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
488 | * to max FC frame payload previously set in fsp->max_payload. | 562 | * to max FC frame payload previously set in fsp->max_payload. |
489 | */ | 563 | */ |
490 | t_blen = fsp->max_payload; | 564 | t_blen = fsp->max_payload; |
491 | if (lp->seq_offload) { | 565 | if (lport->seq_offload) { |
492 | t_blen = min(seq_blen, (size_t)lp->lso_max); | 566 | t_blen = min(seq_blen, (size_t)lport->lso_max); |
493 | FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", | 567 | FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", |
494 | fsp, seq_blen, lp->lso_max, t_blen); | 568 | fsp, seq_blen, lport->lso_max, t_blen); |
495 | } | 569 | } |
496 | 570 | ||
497 | WARN_ON(t_blen < FC_MIN_MAX_PAYLOAD); | 571 | WARN_ON(t_blen < FC_MIN_MAX_PAYLOAD); |
@@ -503,7 +577,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
503 | remaining = seq_blen; | 577 | remaining = seq_blen; |
504 | fh_parm_offset = frame_offset = offset; | 578 | fh_parm_offset = frame_offset = offset; |
505 | tlen = 0; | 579 | tlen = 0; |
506 | seq = lp->tt.seq_start_next(seq); | 580 | seq = lport->tt.seq_start_next(seq); |
507 | f_ctl = FC_FC_REL_OFF; | 581 | f_ctl = FC_FC_REL_OFF; |
508 | WARN_ON(!seq); | 582 | WARN_ON(!seq); |
509 | 583 | ||
@@ -525,43 +599,34 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
525 | */ | 599 | */ |
526 | if (tlen % 4) | 600 | if (tlen % 4) |
527 | using_sg = 0; | 601 | using_sg = 0; |
528 | if (using_sg) { | 602 | fp = fc_frame_alloc(lport, using_sg ? 0 : tlen); |
529 | fp = _fc_frame_alloc(lp, 0); | 603 | if (!fp) |
530 | if (!fp) | 604 | return -ENOMEM; |
531 | return -ENOMEM; | ||
532 | } else { | ||
533 | fp = fc_frame_alloc(lp, tlen); | ||
534 | if (!fp) | ||
535 | return -ENOMEM; | ||
536 | 605 | ||
537 | data = (void *)(fr_hdr(fp)) + | 606 | data = fc_frame_header_get(fp) + 1; |
538 | sizeof(struct fc_frame_header); | ||
539 | } | ||
540 | fh_parm_offset = frame_offset; | 607 | fh_parm_offset = frame_offset; |
541 | fr_max_payload(fp) = fsp->max_payload; | 608 | fr_max_payload(fp) = fsp->max_payload; |
542 | } | 609 | } |
610 | |||
611 | off = offset + sg->offset; | ||
543 | sg_bytes = min(tlen, sg->length - offset); | 612 | sg_bytes = min(tlen, sg->length - offset); |
613 | sg_bytes = min(sg_bytes, | ||
614 | (size_t) (PAGE_SIZE - (off & ~PAGE_MASK))); | ||
615 | page = sg_page(sg) + (off >> PAGE_SHIFT); | ||
544 | if (using_sg) { | 616 | if (using_sg) { |
545 | get_page(sg_page(sg)); | 617 | get_page(page); |
546 | skb_fill_page_desc(fp_skb(fp), | 618 | skb_fill_page_desc(fp_skb(fp), |
547 | skb_shinfo(fp_skb(fp))->nr_frags, | 619 | skb_shinfo(fp_skb(fp))->nr_frags, |
548 | sg_page(sg), sg->offset + offset, | 620 | page, off & ~PAGE_MASK, sg_bytes); |
549 | sg_bytes); | ||
550 | fp_skb(fp)->data_len += sg_bytes; | 621 | fp_skb(fp)->data_len += sg_bytes; |
551 | fr_len(fp) += sg_bytes; | 622 | fr_len(fp) += sg_bytes; |
552 | fp_skb(fp)->truesize += PAGE_SIZE; | 623 | fp_skb(fp)->truesize += PAGE_SIZE; |
553 | } else { | 624 | } else { |
554 | size_t off = offset + sg->offset; | ||
555 | |||
556 | /* | 625 | /* |
557 | * The scatterlist item may be bigger than PAGE_SIZE, | 626 | * The scatterlist item may be bigger than PAGE_SIZE, |
558 | * but we must not cross pages inside the kmap. | 627 | * but we must not cross pages inside the kmap. |
559 | */ | 628 | */ |
560 | sg_bytes = min(sg_bytes, (size_t) (PAGE_SIZE - | 629 | page_addr = kmap_atomic(page, KM_SOFTIRQ0); |
561 | (off & ~PAGE_MASK))); | ||
562 | page_addr = kmap_atomic(sg_page(sg) + | ||
563 | (off >> PAGE_SHIFT), | ||
564 | KM_SOFTIRQ0); | ||
565 | memcpy(data, (char *)page_addr + (off & ~PAGE_MASK), | 630 | memcpy(data, (char *)page_addr + (off & ~PAGE_MASK), |
566 | sg_bytes); | 631 | sg_bytes); |
567 | kunmap_atomic(page_addr, KM_SOFTIRQ0); | 632 | kunmap_atomic(page_addr, KM_SOFTIRQ0); |
@@ -572,7 +637,8 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
572 | tlen -= sg_bytes; | 637 | tlen -= sg_bytes; |
573 | remaining -= sg_bytes; | 638 | remaining -= sg_bytes; |
574 | 639 | ||
575 | if (tlen) | 640 | if ((skb_shinfo(fp_skb(fp))->nr_frags < FC_FRAME_SG_LEN) && |
641 | (tlen)) | ||
576 | continue; | 642 | continue; |
577 | 643 | ||
578 | /* | 644 | /* |
@@ -589,7 +655,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
589 | /* | 655 | /* |
590 | * send fragment using for a sequence. | 656 | * send fragment using for a sequence. |
591 | */ | 657 | */ |
592 | error = lp->tt.seq_send(lp, seq, fp); | 658 | error = lport->tt.seq_send(lport, seq, fp); |
593 | if (error) { | 659 | if (error) { |
594 | WARN_ON(1); /* send error should be rare */ | 660 | WARN_ON(1); /* send error should be rare */ |
595 | fc_fcp_retry_cmd(fsp); | 661 | fc_fcp_retry_cmd(fsp); |
@@ -601,6 +667,11 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
601 | return 0; | 667 | return 0; |
602 | } | 668 | } |
603 | 669 | ||
670 | /** | ||
671 | * fc_fcp_abts_resp() - Send an ABTS response | ||
672 | * @fsp: The FCP packet that is being aborted | ||
673 | * @fp: The response frame | ||
674 | */ | ||
604 | static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 675 | static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
605 | { | 676 | { |
606 | int ba_done = 1; | 677 | int ba_done = 1; |
@@ -637,46 +708,13 @@ static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
637 | } | 708 | } |
638 | 709 | ||
639 | /** | 710 | /** |
640 | * fc_fcp_reduce_can_queue() - drop can_queue | 711 | * fc_fcp_recv() - Reveive an FCP frame |
641 | * @lp: lport to drop queueing for | ||
642 | * | ||
643 | * If we are getting memory allocation failures, then we may | ||
644 | * be trying to execute too many commands. We let the running | ||
645 | * commands complete or timeout, then try again with a reduced | ||
646 | * can_queue. Eventually we will hit the point where we run | ||
647 | * on all reserved structs. | ||
648 | */ | ||
649 | static void fc_fcp_reduce_can_queue(struct fc_lport *lp) | ||
650 | { | ||
651 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | ||
652 | unsigned long flags; | ||
653 | int can_queue; | ||
654 | |||
655 | spin_lock_irqsave(lp->host->host_lock, flags); | ||
656 | if (si->throttled) | ||
657 | goto done; | ||
658 | si->throttled = 1; | ||
659 | |||
660 | can_queue = lp->host->can_queue; | ||
661 | can_queue >>= 1; | ||
662 | if (!can_queue) | ||
663 | can_queue = 1; | ||
664 | lp->host->can_queue = can_queue; | ||
665 | shost_printk(KERN_ERR, lp->host, "libfc: Could not allocate frame.\n" | ||
666 | "Reducing can_queue to %d.\n", can_queue); | ||
667 | done: | ||
668 | spin_unlock_irqrestore(lp->host->host_lock, flags); | ||
669 | } | ||
670 | |||
671 | /** | ||
672 | * fc_fcp_recv() - Reveive FCP frames | ||
673 | * @seq: The sequence the frame is on | 712 | * @seq: The sequence the frame is on |
674 | * @fp: The FC frame | 713 | * @fp: The received frame |
675 | * @arg: The related FCP packet | 714 | * @arg: The related FCP packet |
676 | * | 715 | * |
677 | * Return : None | 716 | * Context: Called from Soft IRQ context. Can not be called |
678 | * Context : called from Soft IRQ context | 717 | * holding the FCP packet list lock. |
679 | * can not called holding list lock | ||
680 | */ | 718 | */ |
681 | static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 719 | static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
682 | { | 720 | { |
@@ -687,8 +725,10 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
687 | u8 r_ctl; | 725 | u8 r_ctl; |
688 | int rc = 0; | 726 | int rc = 0; |
689 | 727 | ||
690 | if (IS_ERR(fp)) | 728 | if (IS_ERR(fp)) { |
691 | goto errout; | 729 | fc_fcp_error(fsp, fp); |
730 | return; | ||
731 | } | ||
692 | 732 | ||
693 | fh = fc_frame_header_get(fp); | 733 | fh = fc_frame_header_get(fp); |
694 | r_ctl = fh->fh_r_ctl; | 734 | r_ctl = fh->fh_r_ctl; |
@@ -721,8 +761,6 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
721 | (size_t) ntohl(dd->ft_burst_len)); | 761 | (size_t) ntohl(dd->ft_burst_len)); |
722 | if (!rc) | 762 | if (!rc) |
723 | seq->rec_data = fsp->xfer_len; | 763 | seq->rec_data = fsp->xfer_len; |
724 | else if (rc == -ENOMEM) | ||
725 | fsp->state |= FC_SRB_NOMEM; | ||
726 | } else if (r_ctl == FC_RCTL_DD_SOL_DATA) { | 764 | } else if (r_ctl == FC_RCTL_DD_SOL_DATA) { |
727 | /* | 765 | /* |
728 | * received a DATA frame | 766 | * received a DATA frame |
@@ -742,13 +780,13 @@ unlock: | |||
742 | fc_fcp_unlock_pkt(fsp); | 780 | fc_fcp_unlock_pkt(fsp); |
743 | out: | 781 | out: |
744 | fc_frame_free(fp); | 782 | fc_frame_free(fp); |
745 | errout: | ||
746 | if (IS_ERR(fp)) | ||
747 | fc_fcp_error(fsp, fp); | ||
748 | else if (rc == -ENOMEM) | ||
749 | fc_fcp_reduce_can_queue(lport); | ||
750 | } | 783 | } |
751 | 784 | ||
785 | /** | ||
786 | * fc_fcp_resp() - Handler for FCP responses | ||
787 | * @fsp: The FCP packet the response is for | ||
788 | * @fp: The response frame | ||
789 | */ | ||
752 | static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 790 | static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
753 | { | 791 | { |
754 | struct fc_frame_header *fh; | 792 | struct fc_frame_header *fh; |
@@ -862,15 +900,16 @@ err: | |||
862 | } | 900 | } |
863 | 901 | ||
864 | /** | 902 | /** |
865 | * fc_fcp_complete_locked() - complete processing of a fcp packet | 903 | * fc_fcp_complete_locked() - Complete processing of a fcp_pkt with the |
866 | * @fsp: fcp packet | 904 | * fcp_pkt lock held |
905 | * @fsp: The FCP packet to be completed | ||
867 | * | 906 | * |
868 | * This function may sleep if a timer is pending. The packet lock must be | 907 | * This function may sleep if a timer is pending. The packet lock must be |
869 | * held, and the host lock must not be held. | 908 | * held, and the host lock must not be held. |
870 | */ | 909 | */ |
871 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | 910 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) |
872 | { | 911 | { |
873 | struct fc_lport *lp = fsp->lp; | 912 | struct fc_lport *lport = fsp->lp; |
874 | struct fc_seq *seq; | 913 | struct fc_seq *seq; |
875 | struct fc_exch *ep; | 914 | struct fc_exch *ep; |
876 | u32 f_ctl; | 915 | u32 f_ctl; |
@@ -901,8 +940,8 @@ static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | |||
901 | struct fc_frame *conf_frame; | 940 | struct fc_frame *conf_frame; |
902 | struct fc_seq *csp; | 941 | struct fc_seq *csp; |
903 | 942 | ||
904 | csp = lp->tt.seq_start_next(seq); | 943 | csp = lport->tt.seq_start_next(seq); |
905 | conf_frame = fc_frame_alloc(fsp->lp, 0); | 944 | conf_frame = fc_fcp_frame_alloc(fsp->lp, 0); |
906 | if (conf_frame) { | 945 | if (conf_frame) { |
907 | f_ctl = FC_FC_SEQ_INIT; | 946 | f_ctl = FC_FC_SEQ_INIT; |
908 | f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ; | 947 | f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
@@ -910,43 +949,48 @@ static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | |||
910 | fc_fill_fc_hdr(conf_frame, FC_RCTL_DD_SOL_CTL, | 949 | fc_fill_fc_hdr(conf_frame, FC_RCTL_DD_SOL_CTL, |
911 | ep->did, ep->sid, | 950 | ep->did, ep->sid, |
912 | FC_TYPE_FCP, f_ctl, 0); | 951 | FC_TYPE_FCP, f_ctl, 0); |
913 | lp->tt.seq_send(lp, csp, conf_frame); | 952 | lport->tt.seq_send(lport, csp, conf_frame); |
914 | } | 953 | } |
915 | } | 954 | } |
916 | lp->tt.exch_done(seq); | 955 | lport->tt.exch_done(seq); |
917 | } | 956 | } |
918 | fc_io_compl(fsp); | 957 | fc_io_compl(fsp); |
919 | } | 958 | } |
920 | 959 | ||
960 | /** | ||
961 | * fc_fcp_cleanup_cmd() - Cancel the active exchange on a fcp_pkt | ||
962 | * @fsp: The FCP packet whose exchanges should be canceled | ||
963 | * @error: The reason for the cancellation | ||
964 | */ | ||
921 | static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) | 965 | static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) |
922 | { | 966 | { |
923 | struct fc_lport *lp = fsp->lp; | 967 | struct fc_lport *lport = fsp->lp; |
924 | 968 | ||
925 | if (fsp->seq_ptr) { | 969 | if (fsp->seq_ptr) { |
926 | lp->tt.exch_done(fsp->seq_ptr); | 970 | lport->tt.exch_done(fsp->seq_ptr); |
927 | fsp->seq_ptr = NULL; | 971 | fsp->seq_ptr = NULL; |
928 | } | 972 | } |
929 | fsp->status_code = error; | 973 | fsp->status_code = error; |
930 | } | 974 | } |
931 | 975 | ||
932 | /** | 976 | /** |
933 | * fc_fcp_cleanup_each_cmd() - Cleanup active commads | 977 | * fc_fcp_cleanup_each_cmd() - Cancel all exchanges on a local port |
934 | * @lp: logical port | 978 | * @lport: The local port whose exchanges should be canceled |
935 | * @id: target id | 979 | * @id: The target's ID |
936 | * @lun: lun | 980 | * @lun: The LUN |
937 | * @error: fsp status code | 981 | * @error: The reason for cancellation |
938 | * | 982 | * |
939 | * If lun or id is -1, they are ignored. | 983 | * If lun or id is -1, they are ignored. |
940 | */ | 984 | */ |
941 | static void fc_fcp_cleanup_each_cmd(struct fc_lport *lp, unsigned int id, | 985 | static void fc_fcp_cleanup_each_cmd(struct fc_lport *lport, unsigned int id, |
942 | unsigned int lun, int error) | 986 | unsigned int lun, int error) |
943 | { | 987 | { |
944 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 988 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
945 | struct fc_fcp_pkt *fsp; | 989 | struct fc_fcp_pkt *fsp; |
946 | struct scsi_cmnd *sc_cmd; | 990 | struct scsi_cmnd *sc_cmd; |
947 | unsigned long flags; | 991 | unsigned long flags; |
948 | 992 | ||
949 | spin_lock_irqsave(lp->host->host_lock, flags); | 993 | spin_lock_irqsave(lport->host->host_lock, flags); |
950 | restart: | 994 | restart: |
951 | list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { | 995 | list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { |
952 | sc_cmd = fsp->cmd; | 996 | sc_cmd = fsp->cmd; |
@@ -957,7 +1001,7 @@ restart: | |||
957 | continue; | 1001 | continue; |
958 | 1002 | ||
959 | fc_fcp_pkt_hold(fsp); | 1003 | fc_fcp_pkt_hold(fsp); |
960 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1004 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
961 | 1005 | ||
962 | if (!fc_fcp_lock_pkt(fsp)) { | 1006 | if (!fc_fcp_lock_pkt(fsp)) { |
963 | fc_fcp_cleanup_cmd(fsp, error); | 1007 | fc_fcp_cleanup_cmd(fsp, error); |
@@ -966,35 +1010,36 @@ restart: | |||
966 | } | 1010 | } |
967 | 1011 | ||
968 | fc_fcp_pkt_release(fsp); | 1012 | fc_fcp_pkt_release(fsp); |
969 | spin_lock_irqsave(lp->host->host_lock, flags); | 1013 | spin_lock_irqsave(lport->host->host_lock, flags); |
970 | /* | 1014 | /* |
971 | * while we dropped the lock multiple pkts could | 1015 | * while we dropped the lock multiple pkts could |
972 | * have been released, so we have to start over. | 1016 | * have been released, so we have to start over. |
973 | */ | 1017 | */ |
974 | goto restart; | 1018 | goto restart; |
975 | } | 1019 | } |
976 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1020 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
977 | } | 1021 | } |
978 | 1022 | ||
979 | static void fc_fcp_abort_io(struct fc_lport *lp) | 1023 | /** |
1024 | * fc_fcp_abort_io() - Abort all FCP-SCSI exchanges on a local port | ||
1025 | * @lport: The local port whose exchanges are to be aborted | ||
1026 | */ | ||
1027 | static void fc_fcp_abort_io(struct fc_lport *lport) | ||
980 | { | 1028 | { |
981 | fc_fcp_cleanup_each_cmd(lp, -1, -1, FC_HRD_ERROR); | 1029 | fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_HRD_ERROR); |
982 | } | 1030 | } |
983 | 1031 | ||
984 | /** | 1032 | /** |
985 | * fc_fcp_pkt_send() - send a fcp packet to the lower level. | 1033 | * fc_fcp_pkt_send() - Send a fcp_pkt |
986 | * @lp: fc lport | 1034 | * @lport: The local port to send the FCP packet on |
987 | * @fsp: fc packet. | 1035 | * @fsp: The FCP packet to send |
988 | * | 1036 | * |
989 | * This is called by upper layer protocol. | 1037 | * Return: Zero for success and -1 for failure |
990 | * Return : zero for success and -1 for failure | 1038 | * Locks: Called with the host lock and irqs disabled. |
991 | * Context : called from queuecommand which can be called from process | ||
992 | * or scsi soft irq. | ||
993 | * Locks : called with the host lock and irqs disabled. | ||
994 | */ | 1039 | */ |
995 | static int fc_fcp_pkt_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | 1040 | static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp) |
996 | { | 1041 | { |
997 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 1042 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
998 | int rc; | 1043 | int rc; |
999 | 1044 | ||
1000 | fsp->cmd->SCp.ptr = (char *)fsp; | 1045 | fsp->cmd->SCp.ptr = (char *)fsp; |
@@ -1006,16 +1051,22 @@ static int fc_fcp_pkt_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | |||
1006 | memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); | 1051 | memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); |
1007 | list_add_tail(&fsp->list, &si->scsi_pkt_queue); | 1052 | list_add_tail(&fsp->list, &si->scsi_pkt_queue); |
1008 | 1053 | ||
1009 | spin_unlock_irq(lp->host->host_lock); | 1054 | spin_unlock_irq(lport->host->host_lock); |
1010 | rc = lp->tt.fcp_cmd_send(lp, fsp, fc_fcp_recv); | 1055 | rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv); |
1011 | spin_lock_irq(lp->host->host_lock); | 1056 | spin_lock_irq(lport->host->host_lock); |
1012 | if (rc) | 1057 | if (rc) |
1013 | list_del(&fsp->list); | 1058 | list_del(&fsp->list); |
1014 | 1059 | ||
1015 | return rc; | 1060 | return rc; |
1016 | } | 1061 | } |
1017 | 1062 | ||
1018 | static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | 1063 | /** |
1064 | * fc_fcp_cmd_send() - Send a FCP command | ||
1065 | * @lport: The local port to send the command on | ||
1066 | * @fsp: The FCP packet the command is on | ||
1067 | * @resp: The handler for the response | ||
1068 | */ | ||
1069 | static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp, | ||
1019 | void (*resp)(struct fc_seq *, | 1070 | void (*resp)(struct fc_seq *, |
1020 | struct fc_frame *fp, | 1071 | struct fc_frame *fp, |
1021 | void *arg)) | 1072 | void *arg)) |
@@ -1023,14 +1074,14 @@ static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1023 | struct fc_frame *fp; | 1074 | struct fc_frame *fp; |
1024 | struct fc_seq *seq; | 1075 | struct fc_seq *seq; |
1025 | struct fc_rport *rport; | 1076 | struct fc_rport *rport; |
1026 | struct fc_rport_libfc_priv *rp; | 1077 | struct fc_rport_libfc_priv *rpriv; |
1027 | const size_t len = sizeof(fsp->cdb_cmd); | 1078 | const size_t len = sizeof(fsp->cdb_cmd); |
1028 | int rc = 0; | 1079 | int rc = 0; |
1029 | 1080 | ||
1030 | if (fc_fcp_lock_pkt(fsp)) | 1081 | if (fc_fcp_lock_pkt(fsp)) |
1031 | return 0; | 1082 | return 0; |
1032 | 1083 | ||
1033 | fp = fc_frame_alloc(lp, sizeof(fsp->cdb_cmd)); | 1084 | fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd)); |
1034 | if (!fp) { | 1085 | if (!fp) { |
1035 | rc = -1; | 1086 | rc = -1; |
1036 | goto unlock; | 1087 | goto unlock; |
@@ -1040,15 +1091,15 @@ static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1040 | fr_fsp(fp) = fsp; | 1091 | fr_fsp(fp) = fsp; |
1041 | rport = fsp->rport; | 1092 | rport = fsp->rport; |
1042 | fsp->max_payload = rport->maxframe_size; | 1093 | fsp->max_payload = rport->maxframe_size; |
1043 | rp = rport->dd_data; | 1094 | rpriv = rport->dd_data; |
1044 | 1095 | ||
1045 | fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id, | 1096 | fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id, |
1046 | fc_host_port_id(rp->local_port->host), FC_TYPE_FCP, | 1097 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_FCP, |
1047 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1098 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1048 | 1099 | ||
1049 | seq = lp->tt.exch_seq_send(lp, fp, resp, fc_fcp_pkt_destroy, fsp, 0); | 1100 | seq = lport->tt.exch_seq_send(lport, fp, resp, fc_fcp_pkt_destroy, |
1101 | fsp, 0); | ||
1050 | if (!seq) { | 1102 | if (!seq) { |
1051 | fc_frame_free(fp); | ||
1052 | rc = -1; | 1103 | rc = -1; |
1053 | goto unlock; | 1104 | goto unlock; |
1054 | } | 1105 | } |
@@ -1065,8 +1116,10 @@ unlock: | |||
1065 | return rc; | 1116 | return rc; |
1066 | } | 1117 | } |
1067 | 1118 | ||
1068 | /* | 1119 | /** |
1069 | * transport error handler | 1120 | * fc_fcp_error() - Handler for FCP layer errors |
1121 | * @fsp: The FCP packet the error is on | ||
1122 | * @fp: The frame that has errored | ||
1070 | */ | 1123 | */ |
1071 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1124 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1072 | { | 1125 | { |
@@ -1091,11 +1144,13 @@ unlock: | |||
1091 | fc_fcp_unlock_pkt(fsp); | 1144 | fc_fcp_unlock_pkt(fsp); |
1092 | } | 1145 | } |
1093 | 1146 | ||
1094 | /* | 1147 | /** |
1095 | * Scsi abort handler- calls to send an abort | 1148 | * fc_fcp_pkt_abort() - Abort a fcp_pkt |
1096 | * and then wait for abort completion | 1149 | * @fsp: The FCP packet to abort on |
1150 | * | ||
1151 | * Called to send an abort and then wait for abort completion | ||
1097 | */ | 1152 | */ |
1098 | static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | 1153 | static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp) |
1099 | { | 1154 | { |
1100 | int rc = FAILED; | 1155 | int rc = FAILED; |
1101 | 1156 | ||
@@ -1122,14 +1177,15 @@ static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | |||
1122 | return rc; | 1177 | return rc; |
1123 | } | 1178 | } |
1124 | 1179 | ||
1125 | /* | 1180 | /** |
1126 | * Retry LUN reset after resource allocation failed. | 1181 | * fc_lun_reset_send() - Send LUN reset command |
1182 | * @data: The FCP packet that identifies the LUN to be reset | ||
1127 | */ | 1183 | */ |
1128 | static void fc_lun_reset_send(unsigned long data) | 1184 | static void fc_lun_reset_send(unsigned long data) |
1129 | { | 1185 | { |
1130 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; | 1186 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; |
1131 | struct fc_lport *lp = fsp->lp; | 1187 | struct fc_lport *lport = fsp->lp; |
1132 | if (lp->tt.fcp_cmd_send(lp, fsp, fc_tm_done)) { | 1188 | if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) { |
1133 | if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) | 1189 | if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) |
1134 | return; | 1190 | return; |
1135 | if (fc_fcp_lock_pkt(fsp)) | 1191 | if (fc_fcp_lock_pkt(fsp)) |
@@ -1140,11 +1196,15 @@ static void fc_lun_reset_send(unsigned long data) | |||
1140 | } | 1196 | } |
1141 | } | 1197 | } |
1142 | 1198 | ||
1143 | /* | 1199 | /** |
1144 | * Scsi device reset handler- send a LUN RESET to the device | 1200 | * fc_lun_reset() - Send a LUN RESET command to a device |
1145 | * and wait for reset reply | 1201 | * and wait for the reply |
1202 | * @lport: The local port to sent the comand on | ||
1203 | * @fsp: The FCP packet that identifies the LUN to be reset | ||
1204 | * @id: The SCSI command ID | ||
1205 | * @lun: The LUN ID to be reset | ||
1146 | */ | 1206 | */ |
1147 | static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | 1207 | static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp, |
1148 | unsigned int id, unsigned int lun) | 1208 | unsigned int id, unsigned int lun) |
1149 | { | 1209 | { |
1150 | int rc; | 1210 | int rc; |
@@ -1172,14 +1232,14 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1172 | 1232 | ||
1173 | spin_lock_bh(&fsp->scsi_pkt_lock); | 1233 | spin_lock_bh(&fsp->scsi_pkt_lock); |
1174 | if (fsp->seq_ptr) { | 1234 | if (fsp->seq_ptr) { |
1175 | lp->tt.exch_done(fsp->seq_ptr); | 1235 | lport->tt.exch_done(fsp->seq_ptr); |
1176 | fsp->seq_ptr = NULL; | 1236 | fsp->seq_ptr = NULL; |
1177 | } | 1237 | } |
1178 | fsp->wait_for_comp = 0; | 1238 | fsp->wait_for_comp = 0; |
1179 | spin_unlock_bh(&fsp->scsi_pkt_lock); | 1239 | spin_unlock_bh(&fsp->scsi_pkt_lock); |
1180 | 1240 | ||
1181 | if (!rc) { | 1241 | if (!rc) { |
1182 | FC_SCSI_DBG(lp, "lun reset failed\n"); | 1242 | FC_SCSI_DBG(lport, "lun reset failed\n"); |
1183 | return FAILED; | 1243 | return FAILED; |
1184 | } | 1244 | } |
1185 | 1245 | ||
@@ -1187,13 +1247,16 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1187 | if (fsp->cdb_status != FCP_TMF_CMPL) | 1247 | if (fsp->cdb_status != FCP_TMF_CMPL) |
1188 | return FAILED; | 1248 | return FAILED; |
1189 | 1249 | ||
1190 | FC_SCSI_DBG(lp, "lun reset to lun %u completed\n", lun); | 1250 | FC_SCSI_DBG(lport, "lun reset to lun %u completed\n", lun); |
1191 | fc_fcp_cleanup_each_cmd(lp, id, lun, FC_CMD_ABORTED); | 1251 | fc_fcp_cleanup_each_cmd(lport, id, lun, FC_CMD_ABORTED); |
1192 | return SUCCESS; | 1252 | return SUCCESS; |
1193 | } | 1253 | } |
1194 | 1254 | ||
1195 | /* | 1255 | /** |
1196 | * Task Managment response handler | 1256 | * fc_tm_done() - Task Managment response handler |
1257 | * @seq: The sequence that the response is on | ||
1258 | * @fp: The response frame | ||
1259 | * @arg: The FCP packet the response is for | ||
1197 | */ | 1260 | */ |
1198 | static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1261 | static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1199 | { | 1262 | { |
@@ -1230,34 +1293,31 @@ static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1230 | fc_fcp_unlock_pkt(fsp); | 1293 | fc_fcp_unlock_pkt(fsp); |
1231 | } | 1294 | } |
1232 | 1295 | ||
1233 | static void fc_fcp_cleanup(struct fc_lport *lp) | 1296 | /** |
1297 | * fc_fcp_cleanup() - Cleanup all FCP exchanges on a local port | ||
1298 | * @lport: The local port to be cleaned up | ||
1299 | */ | ||
1300 | static void fc_fcp_cleanup(struct fc_lport *lport) | ||
1234 | { | 1301 | { |
1235 | fc_fcp_cleanup_each_cmd(lp, -1, -1, FC_ERROR); | 1302 | fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_ERROR); |
1236 | } | 1303 | } |
1237 | 1304 | ||
1238 | /* | 1305 | /** |
1239 | * fc_fcp_timeout: called by OS timer function. | 1306 | * fc_fcp_timeout() - Handler for fcp_pkt timeouts |
1240 | * | 1307 | * @data: The FCP packet that has timed out |
1241 | * The timer has been inactivated and must be reactivated if desired | ||
1242 | * using fc_fcp_timer_set(). | ||
1243 | * | ||
1244 | * Algorithm: | ||
1245 | * | ||
1246 | * If REC is supported, just issue it, and return. The REC exchange will | ||
1247 | * complete or time out, and recovery can continue at that point. | ||
1248 | * | ||
1249 | * Otherwise, if the response has been received without all the data, | ||
1250 | * it has been ER_TIMEOUT since the response was received. | ||
1251 | * | 1308 | * |
1252 | * If the response has not been received, | 1309 | * If REC is supported then just issue it and return. The REC exchange will |
1253 | * we see if data was received recently. If it has been, we continue waiting, | 1310 | * complete or time out and recovery can continue at that point. Otherwise, |
1254 | * otherwise, we abort the command. | 1311 | * if the response has been received without all the data it has been |
1312 | * ER_TIMEOUT since the response was received. If the response has not been | ||
1313 | * received we see if data was received recently. If it has been then we | ||
1314 | * continue waiting, otherwise, we abort the command. | ||
1255 | */ | 1315 | */ |
1256 | static void fc_fcp_timeout(unsigned long data) | 1316 | static void fc_fcp_timeout(unsigned long data) |
1257 | { | 1317 | { |
1258 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; | 1318 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; |
1259 | struct fc_rport *rport = fsp->rport; | 1319 | struct fc_rport *rport = fsp->rport; |
1260 | struct fc_rport_libfc_priv *rp = rport->dd_data; | 1320 | struct fc_rport_libfc_priv *rpriv = rport->dd_data; |
1261 | 1321 | ||
1262 | if (fc_fcp_lock_pkt(fsp)) | 1322 | if (fc_fcp_lock_pkt(fsp)) |
1263 | return; | 1323 | return; |
@@ -1267,7 +1327,7 @@ static void fc_fcp_timeout(unsigned long data) | |||
1267 | 1327 | ||
1268 | fsp->state |= FC_SRB_FCP_PROCESSING_TMO; | 1328 | fsp->state |= FC_SRB_FCP_PROCESSING_TMO; |
1269 | 1329 | ||
1270 | if (rp->flags & FC_RP_FLAGS_REC_SUPPORTED) | 1330 | if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED) |
1271 | fc_fcp_rec(fsp); | 1331 | fc_fcp_rec(fsp); |
1272 | else if (time_after_eq(fsp->last_pkt_time + (FC_SCSI_ER_TIMEOUT / 2), | 1332 | else if (time_after_eq(fsp->last_pkt_time + (FC_SCSI_ER_TIMEOUT / 2), |
1273 | jiffies)) | 1333 | jiffies)) |
@@ -1281,39 +1341,40 @@ unlock: | |||
1281 | fc_fcp_unlock_pkt(fsp); | 1341 | fc_fcp_unlock_pkt(fsp); |
1282 | } | 1342 | } |
1283 | 1343 | ||
1284 | /* | 1344 | /** |
1285 | * Send a REC ELS request | 1345 | * fc_fcp_rec() - Send a REC ELS request |
1346 | * @fsp: The FCP packet to send the REC request on | ||
1286 | */ | 1347 | */ |
1287 | static void fc_fcp_rec(struct fc_fcp_pkt *fsp) | 1348 | static void fc_fcp_rec(struct fc_fcp_pkt *fsp) |
1288 | { | 1349 | { |
1289 | struct fc_lport *lp; | 1350 | struct fc_lport *lport; |
1290 | struct fc_frame *fp; | 1351 | struct fc_frame *fp; |
1291 | struct fc_rport *rport; | 1352 | struct fc_rport *rport; |
1292 | struct fc_rport_libfc_priv *rp; | 1353 | struct fc_rport_libfc_priv *rpriv; |
1293 | 1354 | ||
1294 | lp = fsp->lp; | 1355 | lport = fsp->lp; |
1295 | rport = fsp->rport; | 1356 | rport = fsp->rport; |
1296 | rp = rport->dd_data; | 1357 | rpriv = rport->dd_data; |
1297 | if (!fsp->seq_ptr || rp->rp_state != RPORT_ST_READY) { | 1358 | if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) { |
1298 | fsp->status_code = FC_HRD_ERROR; | 1359 | fsp->status_code = FC_HRD_ERROR; |
1299 | fsp->io_status = 0; | 1360 | fsp->io_status = 0; |
1300 | fc_fcp_complete_locked(fsp); | 1361 | fc_fcp_complete_locked(fsp); |
1301 | return; | 1362 | return; |
1302 | } | 1363 | } |
1303 | fp = fc_frame_alloc(lp, sizeof(struct fc_els_rec)); | 1364 | fp = fc_fcp_frame_alloc(lport, sizeof(struct fc_els_rec)); |
1304 | if (!fp) | 1365 | if (!fp) |
1305 | goto retry; | 1366 | goto retry; |
1306 | 1367 | ||
1307 | fr_seq(fp) = fsp->seq_ptr; | 1368 | fr_seq(fp) = fsp->seq_ptr; |
1308 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id, | 1369 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id, |
1309 | fc_host_port_id(rp->local_port->host), FC_TYPE_ELS, | 1370 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_ELS, |
1310 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1371 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1311 | if (lp->tt.elsct_send(lp, rport->port_id, fp, ELS_REC, fc_fcp_rec_resp, | 1372 | if (lport->tt.elsct_send(lport, rport->port_id, fp, ELS_REC, |
1312 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV))) { | 1373 | fc_fcp_rec_resp, fsp, |
1374 | jiffies_to_msecs(FC_SCSI_REC_TOV))) { | ||
1313 | fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ | 1375 | fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ |
1314 | return; | 1376 | return; |
1315 | } | 1377 | } |
1316 | fc_frame_free(fp); | ||
1317 | retry: | 1378 | retry: |
1318 | if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) | 1379 | if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) |
1319 | fc_fcp_timer_set(fsp, FC_SCSI_REC_TOV); | 1380 | fc_fcp_timer_set(fsp, FC_SCSI_REC_TOV); |
@@ -1321,12 +1382,16 @@ retry: | |||
1321 | fc_timeout_error(fsp); | 1382 | fc_timeout_error(fsp); |
1322 | } | 1383 | } |
1323 | 1384 | ||
1324 | /* | 1385 | /** |
1325 | * Receive handler for REC ELS frame | 1386 | * fc_fcp_rec_resp() - Handler for REC ELS responses |
1326 | * if it is a reject then let the scsi layer to handle | 1387 | * @seq: The sequence the response is on |
1327 | * the timeout. if it is a LS_ACC then if the io was not completed | 1388 | * @fp: The response frame |
1328 | * then set the timeout and return otherwise complete the exchange | 1389 | * @arg: The FCP packet the response is on |
1329 | * and tell the scsi layer to restart the I/O. | 1390 | * |
1391 | * If the response is a reject then the scsi layer will handle | ||
1392 | * the timeout. If the response is a LS_ACC then if the I/O was not completed | ||
1393 | * set the timeout and return. If the I/O was completed then complete the | ||
1394 | * exchange and tell the SCSI layer. | ||
1330 | */ | 1395 | */ |
1331 | static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1396 | static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1332 | { | 1397 | { |
@@ -1338,7 +1403,7 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1338 | u32 offset; | 1403 | u32 offset; |
1339 | enum dma_data_direction data_dir; | 1404 | enum dma_data_direction data_dir; |
1340 | enum fc_rctl r_ctl; | 1405 | enum fc_rctl r_ctl; |
1341 | struct fc_rport_libfc_priv *rp; | 1406 | struct fc_rport_libfc_priv *rpriv; |
1342 | 1407 | ||
1343 | if (IS_ERR(fp)) { | 1408 | if (IS_ERR(fp)) { |
1344 | fc_fcp_rec_error(fsp, fp); | 1409 | fc_fcp_rec_error(fsp, fp); |
@@ -1361,13 +1426,13 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1361 | /* fall through */ | 1426 | /* fall through */ |
1362 | case ELS_RJT_UNSUP: | 1427 | case ELS_RJT_UNSUP: |
1363 | FC_FCP_DBG(fsp, "device does not support REC\n"); | 1428 | FC_FCP_DBG(fsp, "device does not support REC\n"); |
1364 | rp = fsp->rport->dd_data; | 1429 | rpriv = fsp->rport->dd_data; |
1365 | /* | 1430 | /* |
1366 | * if we do not spport RECs or got some bogus | 1431 | * if we do not spport RECs or got some bogus |
1367 | * reason then resetup timer so we check for | 1432 | * reason then resetup timer so we check for |
1368 | * making progress. | 1433 | * making progress. |
1369 | */ | 1434 | */ |
1370 | rp->flags &= ~FC_RP_FLAGS_REC_SUPPORTED; | 1435 | rpriv->flags &= ~FC_RP_FLAGS_REC_SUPPORTED; |
1371 | fc_fcp_timer_set(fsp, FC_SCSI_ER_TIMEOUT); | 1436 | fc_fcp_timer_set(fsp, FC_SCSI_ER_TIMEOUT); |
1372 | break; | 1437 | break; |
1373 | case ELS_RJT_LOGIC: | 1438 | case ELS_RJT_LOGIC: |
@@ -1464,8 +1529,10 @@ out: | |||
1464 | fc_frame_free(fp); | 1529 | fc_frame_free(fp); |
1465 | } | 1530 | } |
1466 | 1531 | ||
1467 | /* | 1532 | /** |
1468 | * Handle error response or timeout for REC exchange. | 1533 | * fc_fcp_rec_error() - Handler for REC errors |
1534 | * @fsp: The FCP packet the error is on | ||
1535 | * @fp: The REC frame | ||
1469 | */ | 1536 | */ |
1470 | static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1537 | static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1471 | { | 1538 | { |
@@ -1504,10 +1571,9 @@ out: | |||
1504 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ | 1571 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ |
1505 | } | 1572 | } |
1506 | 1573 | ||
1507 | /* | 1574 | /** |
1508 | * Time out error routine: | 1575 | * fc_timeout_error() - Handler for fcp_pkt timeouts |
1509 | * abort's the I/O close the exchange and | 1576 | * @fsp: The FCP packt that has timed out |
1510 | * send completion notification to scsi layer | ||
1511 | */ | 1577 | */ |
1512 | static void fc_timeout_error(struct fc_fcp_pkt *fsp) | 1578 | static void fc_timeout_error(struct fc_fcp_pkt *fsp) |
1513 | { | 1579 | { |
@@ -1521,16 +1587,18 @@ static void fc_timeout_error(struct fc_fcp_pkt *fsp) | |||
1521 | fc_fcp_send_abort(fsp); | 1587 | fc_fcp_send_abort(fsp); |
1522 | } | 1588 | } |
1523 | 1589 | ||
1524 | /* | 1590 | /** |
1525 | * Sequence retransmission request. | 1591 | * fc_fcp_srr() - Send a SRR request (Sequence Retransmission Request) |
1592 | * @fsp: The FCP packet the SRR is to be sent on | ||
1593 | * @r_ctl: The R_CTL field for the SRR request | ||
1526 | * This is called after receiving status but insufficient data, or | 1594 | * This is called after receiving status but insufficient data, or |
1527 | * when expecting status but the request has timed out. | 1595 | * when expecting status but the request has timed out. |
1528 | */ | 1596 | */ |
1529 | static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | 1597 | static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) |
1530 | { | 1598 | { |
1531 | struct fc_lport *lp = fsp->lp; | 1599 | struct fc_lport *lport = fsp->lp; |
1532 | struct fc_rport *rport; | 1600 | struct fc_rport *rport; |
1533 | struct fc_rport_libfc_priv *rp; | 1601 | struct fc_rport_libfc_priv *rpriv; |
1534 | struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); | 1602 | struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); |
1535 | struct fc_seq *seq; | 1603 | struct fc_seq *seq; |
1536 | struct fcp_srr *srr; | 1604 | struct fcp_srr *srr; |
@@ -1538,12 +1606,13 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | |||
1538 | u8 cdb_op; | 1606 | u8 cdb_op; |
1539 | 1607 | ||
1540 | rport = fsp->rport; | 1608 | rport = fsp->rport; |
1541 | rp = rport->dd_data; | 1609 | rpriv = rport->dd_data; |
1542 | cdb_op = fsp->cdb_cmd.fc_cdb[0]; | 1610 | cdb_op = fsp->cdb_cmd.fc_cdb[0]; |
1543 | 1611 | ||
1544 | if (!(rp->flags & FC_RP_FLAGS_RETRY) || rp->rp_state != RPORT_ST_READY) | 1612 | if (!(rpriv->flags & FC_RP_FLAGS_RETRY) || |
1613 | rpriv->rp_state != RPORT_ST_READY) | ||
1545 | goto retry; /* shouldn't happen */ | 1614 | goto retry; /* shouldn't happen */ |
1546 | fp = fc_frame_alloc(lp, sizeof(*srr)); | 1615 | fp = fc_fcp_frame_alloc(lport, sizeof(*srr)); |
1547 | if (!fp) | 1616 | if (!fp) |
1548 | goto retry; | 1617 | goto retry; |
1549 | 1618 | ||
@@ -1556,15 +1625,14 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | |||
1556 | srr->srr_rel_off = htonl(offset); | 1625 | srr->srr_rel_off = htonl(offset); |
1557 | 1626 | ||
1558 | fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id, | 1627 | fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id, |
1559 | fc_host_port_id(rp->local_port->host), FC_TYPE_FCP, | 1628 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_FCP, |
1560 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1629 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1561 | 1630 | ||
1562 | seq = lp->tt.exch_seq_send(lp, fp, fc_fcp_srr_resp, NULL, | 1631 | seq = lport->tt.exch_seq_send(lport, fp, fc_fcp_srr_resp, NULL, |
1563 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV)); | 1632 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV)); |
1564 | if (!seq) { | 1633 | if (!seq) |
1565 | fc_frame_free(fp); | ||
1566 | goto retry; | 1634 | goto retry; |
1567 | } | 1635 | |
1568 | fsp->recov_seq = seq; | 1636 | fsp->recov_seq = seq; |
1569 | fsp->xfer_len = offset; | 1637 | fsp->xfer_len = offset; |
1570 | fsp->xfer_contig_end = offset; | 1638 | fsp->xfer_contig_end = offset; |
@@ -1575,8 +1643,11 @@ retry: | |||
1575 | fc_fcp_retry_cmd(fsp); | 1643 | fc_fcp_retry_cmd(fsp); |
1576 | } | 1644 | } |
1577 | 1645 | ||
1578 | /* | 1646 | /** |
1579 | * Handle response from SRR. | 1647 | * fc_fcp_srr_resp() - Handler for SRR response |
1648 | * @seq: The sequence the SRR is on | ||
1649 | * @fp: The SRR frame | ||
1650 | * @arg: The FCP packet the SRR is on | ||
1580 | */ | 1651 | */ |
1581 | static void fc_fcp_srr_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1652 | static void fc_fcp_srr_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1582 | { | 1653 | { |
@@ -1622,6 +1693,11 @@ out: | |||
1622 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ | 1693 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ |
1623 | } | 1694 | } |
1624 | 1695 | ||
1696 | /** | ||
1697 | * fc_fcp_srr_error() - Handler for SRR errors | ||
1698 | * @fsp: The FCP packet that the SRR error is on | ||
1699 | * @fp: The SRR frame | ||
1700 | */ | ||
1625 | static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1701 | static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1626 | { | 1702 | { |
1627 | if (fc_fcp_lock_pkt(fsp)) | 1703 | if (fc_fcp_lock_pkt(fsp)) |
@@ -1646,31 +1722,36 @@ out: | |||
1646 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ | 1722 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ |
1647 | } | 1723 | } |
1648 | 1724 | ||
1649 | static inline int fc_fcp_lport_queue_ready(struct fc_lport *lp) | 1725 | /** |
1726 | * fc_fcp_lport_queue_ready() - Determine if the lport and it's queue is ready | ||
1727 | * @lport: The local port to be checked | ||
1728 | */ | ||
1729 | static inline int fc_fcp_lport_queue_ready(struct fc_lport *lport) | ||
1650 | { | 1730 | { |
1651 | /* lock ? */ | 1731 | /* lock ? */ |
1652 | return (lp->state == LPORT_ST_READY) && lp->link_up && !lp->qfull; | 1732 | return (lport->state == LPORT_ST_READY) && |
1733 | lport->link_up && !lport->qfull; | ||
1653 | } | 1734 | } |
1654 | 1735 | ||
1655 | /** | 1736 | /** |
1656 | * fc_queuecommand - The queuecommand function of the scsi template | 1737 | * fc_queuecommand() - The queuecommand function of the SCSI template |
1657 | * @cmd: struct scsi_cmnd to be executed | 1738 | * @cmd: The scsi_cmnd to be executed |
1658 | * @done: Callback function to be called when cmd is completed | 1739 | * @done: The callback function to be called when the scsi_cmnd is complete |
1659 | * | 1740 | * |
1660 | * this is the i/o strategy routine, called by the scsi layer | 1741 | * This is the i/o strategy routine, called by the SCSI layer. This routine |
1661 | * this routine is called with holding the host_lock. | 1742 | * is called with the host_lock held. |
1662 | */ | 1743 | */ |
1663 | int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | 1744 | int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) |
1664 | { | 1745 | { |
1665 | struct fc_lport *lp; | 1746 | struct fc_lport *lport; |
1666 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); | 1747 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); |
1667 | struct fc_fcp_pkt *fsp; | 1748 | struct fc_fcp_pkt *fsp; |
1668 | struct fc_rport_libfc_priv *rp; | 1749 | struct fc_rport_libfc_priv *rpriv; |
1669 | int rval; | 1750 | int rval; |
1670 | int rc = 0; | 1751 | int rc = 0; |
1671 | struct fcoe_dev_stats *stats; | 1752 | struct fcoe_dev_stats *stats; |
1672 | 1753 | ||
1673 | lp = shost_priv(sc_cmd->device->host); | 1754 | lport = shost_priv(sc_cmd->device->host); |
1674 | 1755 | ||
1675 | rval = fc_remote_port_chkready(rport); | 1756 | rval = fc_remote_port_chkready(rport); |
1676 | if (rval) { | 1757 | if (rval) { |
@@ -1689,14 +1770,16 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1689 | goto out; | 1770 | goto out; |
1690 | } | 1771 | } |
1691 | 1772 | ||
1692 | rp = rport->dd_data; | 1773 | rpriv = rport->dd_data; |
1693 | 1774 | ||
1694 | if (!fc_fcp_lport_queue_ready(lp)) { | 1775 | if (!fc_fcp_lport_queue_ready(lport)) { |
1776 | if (lport->qfull) | ||
1777 | fc_fcp_can_queue_ramp_down(lport); | ||
1695 | rc = SCSI_MLQUEUE_HOST_BUSY; | 1778 | rc = SCSI_MLQUEUE_HOST_BUSY; |
1696 | goto out; | 1779 | goto out; |
1697 | } | 1780 | } |
1698 | 1781 | ||
1699 | fsp = fc_fcp_pkt_alloc(lp, GFP_ATOMIC); | 1782 | fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC); |
1700 | if (fsp == NULL) { | 1783 | if (fsp == NULL) { |
1701 | rc = SCSI_MLQUEUE_HOST_BUSY; | 1784 | rc = SCSI_MLQUEUE_HOST_BUSY; |
1702 | goto out; | 1785 | goto out; |
@@ -1706,8 +1789,9 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1706 | * build the libfc request pkt | 1789 | * build the libfc request pkt |
1707 | */ | 1790 | */ |
1708 | fsp->cmd = sc_cmd; /* save the cmd */ | 1791 | fsp->cmd = sc_cmd; /* save the cmd */ |
1709 | fsp->lp = lp; /* save the softc ptr */ | 1792 | fsp->lp = lport; /* save the softc ptr */ |
1710 | fsp->rport = rport; /* set the remote port ptr */ | 1793 | fsp->rport = rport; /* set the remote port ptr */ |
1794 | fsp->xfer_ddp = FC_XID_UNKNOWN; | ||
1711 | sc_cmd->scsi_done = done; | 1795 | sc_cmd->scsi_done = done; |
1712 | 1796 | ||
1713 | /* | 1797 | /* |
@@ -1719,7 +1803,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1719 | /* | 1803 | /* |
1720 | * setup the data direction | 1804 | * setup the data direction |
1721 | */ | 1805 | */ |
1722 | stats = fc_lport_get_stats(lp); | 1806 | stats = fc_lport_get_stats(lport); |
1723 | if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { | 1807 | if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { |
1724 | fsp->req_flags = FC_SRB_READ; | 1808 | fsp->req_flags = FC_SRB_READ; |
1725 | stats->InputRequests++; | 1809 | stats->InputRequests++; |
@@ -1733,7 +1817,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1733 | stats->ControlRequests++; | 1817 | stats->ControlRequests++; |
1734 | } | 1818 | } |
1735 | 1819 | ||
1736 | fsp->tgt_flags = rp->flags; | 1820 | fsp->tgt_flags = rpriv->flags; |
1737 | 1821 | ||
1738 | init_timer(&fsp->timer); | 1822 | init_timer(&fsp->timer); |
1739 | fsp->timer.data = (unsigned long)fsp; | 1823 | fsp->timer.data = (unsigned long)fsp; |
@@ -1743,7 +1827,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1743 | * if we get -1 return then put the request in the pending | 1827 | * if we get -1 return then put the request in the pending |
1744 | * queue. | 1828 | * queue. |
1745 | */ | 1829 | */ |
1746 | rval = fc_fcp_pkt_send(lp, fsp); | 1830 | rval = fc_fcp_pkt_send(lport, fsp); |
1747 | if (rval != 0) { | 1831 | if (rval != 0) { |
1748 | fsp->state = FC_SRB_FREE; | 1832 | fsp->state = FC_SRB_FREE; |
1749 | fc_fcp_pkt_release(fsp); | 1833 | fc_fcp_pkt_release(fsp); |
@@ -1755,18 +1839,17 @@ out: | |||
1755 | EXPORT_SYMBOL(fc_queuecommand); | 1839 | EXPORT_SYMBOL(fc_queuecommand); |
1756 | 1840 | ||
1757 | /** | 1841 | /** |
1758 | * fc_io_compl() - Handle responses for completed commands | 1842 | * fc_io_compl() - Handle responses for completed commands |
1759 | * @fsp: scsi packet | 1843 | * @fsp: The FCP packet that is complete |
1760 | * | ||
1761 | * Translates a error to a Linux SCSI error. | ||
1762 | * | 1844 | * |
1845 | * Translates fcp_pkt errors to a Linux SCSI errors. | ||
1763 | * The fcp packet lock must be held when calling. | 1846 | * The fcp packet lock must be held when calling. |
1764 | */ | 1847 | */ |
1765 | static void fc_io_compl(struct fc_fcp_pkt *fsp) | 1848 | static void fc_io_compl(struct fc_fcp_pkt *fsp) |
1766 | { | 1849 | { |
1767 | struct fc_fcp_internal *si; | 1850 | struct fc_fcp_internal *si; |
1768 | struct scsi_cmnd *sc_cmd; | 1851 | struct scsi_cmnd *sc_cmd; |
1769 | struct fc_lport *lp; | 1852 | struct fc_lport *lport; |
1770 | unsigned long flags; | 1853 | unsigned long flags; |
1771 | 1854 | ||
1772 | /* release outstanding ddp context */ | 1855 | /* release outstanding ddp context */ |
@@ -1779,28 +1862,26 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1779 | spin_lock_bh(&fsp->scsi_pkt_lock); | 1862 | spin_lock_bh(&fsp->scsi_pkt_lock); |
1780 | } | 1863 | } |
1781 | 1864 | ||
1782 | lp = fsp->lp; | 1865 | lport = fsp->lp; |
1783 | si = fc_get_scsi_internal(lp); | 1866 | si = fc_get_scsi_internal(lport); |
1784 | spin_lock_irqsave(lp->host->host_lock, flags); | 1867 | spin_lock_irqsave(lport->host->host_lock, flags); |
1785 | if (!fsp->cmd) { | 1868 | if (!fsp->cmd) { |
1786 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1869 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1787 | return; | 1870 | return; |
1788 | } | 1871 | } |
1789 | 1872 | ||
1790 | /* | 1873 | /* |
1791 | * if a command timed out while we had to try and throttle IO | 1874 | * if can_queue ramp down is done then try can_queue ramp up |
1792 | * and it is now getting cleaned up, then we are about to | 1875 | * since commands are completing now. |
1793 | * try again so clear the throttled flag incase we get more | ||
1794 | * time outs. | ||
1795 | */ | 1876 | */ |
1796 | if (si->throttled && fsp->state & FC_SRB_NOMEM) | 1877 | if (si->last_can_queue_ramp_down_time) |
1797 | si->throttled = 0; | 1878 | fc_fcp_can_queue_ramp_up(lport); |
1798 | 1879 | ||
1799 | sc_cmd = fsp->cmd; | 1880 | sc_cmd = fsp->cmd; |
1800 | fsp->cmd = NULL; | 1881 | fsp->cmd = NULL; |
1801 | 1882 | ||
1802 | if (!sc_cmd->SCp.ptr) { | 1883 | if (!sc_cmd->SCp.ptr) { |
1803 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1884 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1804 | return; | 1885 | return; |
1805 | } | 1886 | } |
1806 | 1887 | ||
@@ -1814,21 +1895,6 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1814 | sc_cmd->result = DID_OK << 16; | 1895 | sc_cmd->result = DID_OK << 16; |
1815 | if (fsp->scsi_resid) | 1896 | if (fsp->scsi_resid) |
1816 | CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; | 1897 | CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; |
1817 | } else if (fsp->cdb_status == QUEUE_FULL) { | ||
1818 | struct scsi_device *tmp_sdev; | ||
1819 | struct scsi_device *sdev = sc_cmd->device; | ||
1820 | |||
1821 | shost_for_each_device(tmp_sdev, sdev->host) { | ||
1822 | if (tmp_sdev->id != sdev->id) | ||
1823 | continue; | ||
1824 | |||
1825 | if (tmp_sdev->queue_depth > 1) { | ||
1826 | scsi_track_queue_full(tmp_sdev, | ||
1827 | tmp_sdev-> | ||
1828 | queue_depth - 1); | ||
1829 | } | ||
1830 | } | ||
1831 | sc_cmd->result = (DID_OK << 16) | fsp->cdb_status; | ||
1832 | } else { | 1898 | } else { |
1833 | /* | 1899 | /* |
1834 | * transport level I/O was ok but scsi | 1900 | * transport level I/O was ok but scsi |
@@ -1846,7 +1912,8 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1846 | * scsi status is good but transport level | 1912 | * scsi status is good but transport level |
1847 | * underrun. | 1913 | * underrun. |
1848 | */ | 1914 | */ |
1849 | sc_cmd->result = DID_OK << 16; | 1915 | sc_cmd->result = (fsp->state & FC_SRB_RCV_STATUS ? |
1916 | DID_OK : DID_ERROR) << 16; | ||
1850 | } else { | 1917 | } else { |
1851 | /* | 1918 | /* |
1852 | * scsi got underrun, this is an error | 1919 | * scsi got underrun, this is an error |
@@ -1881,60 +1948,42 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1881 | list_del(&fsp->list); | 1948 | list_del(&fsp->list); |
1882 | sc_cmd->SCp.ptr = NULL; | 1949 | sc_cmd->SCp.ptr = NULL; |
1883 | sc_cmd->scsi_done(sc_cmd); | 1950 | sc_cmd->scsi_done(sc_cmd); |
1884 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1951 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1885 | 1952 | ||
1886 | /* release ref from initial allocation in queue command */ | 1953 | /* release ref from initial allocation in queue command */ |
1887 | fc_fcp_pkt_release(fsp); | 1954 | fc_fcp_pkt_release(fsp); |
1888 | } | 1955 | } |
1889 | 1956 | ||
1890 | /** | 1957 | /** |
1891 | * fc_fcp_complete() - complete processing of a fcp packet | ||
1892 | * @fsp: fcp packet | ||
1893 | * | ||
1894 | * This function may sleep if a fsp timer is pending. | ||
1895 | * The host lock must not be held by caller. | ||
1896 | */ | ||
1897 | void fc_fcp_complete(struct fc_fcp_pkt *fsp) | ||
1898 | { | ||
1899 | if (fc_fcp_lock_pkt(fsp)) | ||
1900 | return; | ||
1901 | |||
1902 | fc_fcp_complete_locked(fsp); | ||
1903 | fc_fcp_unlock_pkt(fsp); | ||
1904 | } | ||
1905 | EXPORT_SYMBOL(fc_fcp_complete); | ||
1906 | |||
1907 | /** | ||
1908 | * fc_eh_abort() - Abort a command | 1958 | * fc_eh_abort() - Abort a command |
1909 | * @sc_cmd: scsi command to abort | 1959 | * @sc_cmd: The SCSI command to abort |
1910 | * | 1960 | * |
1911 | * From scsi host template. | 1961 | * From SCSI host template. |
1912 | * send ABTS to the target device and wait for the response | 1962 | * Send an ABTS to the target device and wait for the response. |
1913 | * sc_cmd is the pointer to the command to be aborted. | ||
1914 | */ | 1963 | */ |
1915 | int fc_eh_abort(struct scsi_cmnd *sc_cmd) | 1964 | int fc_eh_abort(struct scsi_cmnd *sc_cmd) |
1916 | { | 1965 | { |
1917 | struct fc_fcp_pkt *fsp; | 1966 | struct fc_fcp_pkt *fsp; |
1918 | struct fc_lport *lp; | 1967 | struct fc_lport *lport; |
1919 | int rc = FAILED; | 1968 | int rc = FAILED; |
1920 | unsigned long flags; | 1969 | unsigned long flags; |
1921 | 1970 | ||
1922 | lp = shost_priv(sc_cmd->device->host); | 1971 | lport = shost_priv(sc_cmd->device->host); |
1923 | if (lp->state != LPORT_ST_READY) | 1972 | if (lport->state != LPORT_ST_READY) |
1924 | return rc; | 1973 | return rc; |
1925 | else if (!lp->link_up) | 1974 | else if (!lport->link_up) |
1926 | return rc; | 1975 | return rc; |
1927 | 1976 | ||
1928 | spin_lock_irqsave(lp->host->host_lock, flags); | 1977 | spin_lock_irqsave(lport->host->host_lock, flags); |
1929 | fsp = CMD_SP(sc_cmd); | 1978 | fsp = CMD_SP(sc_cmd); |
1930 | if (!fsp) { | 1979 | if (!fsp) { |
1931 | /* command completed while scsi eh was setting up */ | 1980 | /* command completed while scsi eh was setting up */ |
1932 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1981 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1933 | return SUCCESS; | 1982 | return SUCCESS; |
1934 | } | 1983 | } |
1935 | /* grab a ref so the fsp and sc_cmd cannot be relased from under us */ | 1984 | /* grab a ref so the fsp and sc_cmd cannot be relased from under us */ |
1936 | fc_fcp_pkt_hold(fsp); | 1985 | fc_fcp_pkt_hold(fsp); |
1937 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1986 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1938 | 1987 | ||
1939 | if (fc_fcp_lock_pkt(fsp)) { | 1988 | if (fc_fcp_lock_pkt(fsp)) { |
1940 | /* completed while we were waiting for timer to be deleted */ | 1989 | /* completed while we were waiting for timer to be deleted */ |
@@ -1942,7 +1991,7 @@ int fc_eh_abort(struct scsi_cmnd *sc_cmd) | |||
1942 | goto release_pkt; | 1991 | goto release_pkt; |
1943 | } | 1992 | } |
1944 | 1993 | ||
1945 | rc = fc_fcp_pkt_abort(lp, fsp); | 1994 | rc = fc_fcp_pkt_abort(fsp); |
1946 | fc_fcp_unlock_pkt(fsp); | 1995 | fc_fcp_unlock_pkt(fsp); |
1947 | 1996 | ||
1948 | release_pkt: | 1997 | release_pkt: |
@@ -1952,37 +2001,34 @@ release_pkt: | |||
1952 | EXPORT_SYMBOL(fc_eh_abort); | 2001 | EXPORT_SYMBOL(fc_eh_abort); |
1953 | 2002 | ||
1954 | /** | 2003 | /** |
1955 | * fc_eh_device_reset() Reset a single LUN | 2004 | * fc_eh_device_reset() - Reset a single LUN |
1956 | * @sc_cmd: scsi command | 2005 | * @sc_cmd: The SCSI command which identifies the device whose |
2006 | * LUN is to be reset | ||
1957 | * | 2007 | * |
1958 | * Set from scsi host template to send tm cmd to the target and wait for the | 2008 | * Set from SCSI host template. |
1959 | * response. | ||
1960 | */ | 2009 | */ |
1961 | int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) | 2010 | int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) |
1962 | { | 2011 | { |
1963 | struct fc_lport *lp; | 2012 | struct fc_lport *lport; |
1964 | struct fc_fcp_pkt *fsp; | 2013 | struct fc_fcp_pkt *fsp; |
1965 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); | 2014 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); |
1966 | int rc = FAILED; | 2015 | int rc = FAILED; |
1967 | struct fc_rport_libfc_priv *rp; | ||
1968 | int rval; | 2016 | int rval; |
1969 | 2017 | ||
1970 | rval = fc_remote_port_chkready(rport); | 2018 | rval = fc_remote_port_chkready(rport); |
1971 | if (rval) | 2019 | if (rval) |
1972 | goto out; | 2020 | goto out; |
1973 | 2021 | ||
1974 | rp = rport->dd_data; | 2022 | lport = shost_priv(sc_cmd->device->host); |
1975 | lp = shost_priv(sc_cmd->device->host); | ||
1976 | 2023 | ||
1977 | if (lp->state != LPORT_ST_READY) | 2024 | if (lport->state != LPORT_ST_READY) |
1978 | return rc; | 2025 | return rc; |
1979 | 2026 | ||
1980 | FC_SCSI_DBG(lp, "Resetting rport (%6x)\n", rport->port_id); | 2027 | FC_SCSI_DBG(lport, "Resetting rport (%6x)\n", rport->port_id); |
1981 | 2028 | ||
1982 | fsp = fc_fcp_pkt_alloc(lp, GFP_NOIO); | 2029 | fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO); |
1983 | if (fsp == NULL) { | 2030 | if (fsp == NULL) { |
1984 | printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n"); | 2031 | printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n"); |
1985 | sc_cmd->result = DID_NO_CONNECT << 16; | ||
1986 | goto out; | 2032 | goto out; |
1987 | } | 2033 | } |
1988 | 2034 | ||
@@ -1991,13 +2037,13 @@ int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) | |||
1991 | * the sc passed in is not setup for execution like when sent | 2037 | * the sc passed in is not setup for execution like when sent |
1992 | * through the queuecommand callout. | 2038 | * through the queuecommand callout. |
1993 | */ | 2039 | */ |
1994 | fsp->lp = lp; /* save the softc ptr */ | 2040 | fsp->lp = lport; /* save the softc ptr */ |
1995 | fsp->rport = rport; /* set the remote port ptr */ | 2041 | fsp->rport = rport; /* set the remote port ptr */ |
1996 | 2042 | ||
1997 | /* | 2043 | /* |
1998 | * flush outstanding commands | 2044 | * flush outstanding commands |
1999 | */ | 2045 | */ |
2000 | rc = fc_lun_reset(lp, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); | 2046 | rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); |
2001 | fsp->state = FC_SRB_FREE; | 2047 | fsp->state = FC_SRB_FREE; |
2002 | fc_fcp_pkt_release(fsp); | 2048 | fc_fcp_pkt_release(fsp); |
2003 | 2049 | ||
@@ -2007,38 +2053,39 @@ out: | |||
2007 | EXPORT_SYMBOL(fc_eh_device_reset); | 2053 | EXPORT_SYMBOL(fc_eh_device_reset); |
2008 | 2054 | ||
2009 | /** | 2055 | /** |
2010 | * fc_eh_host_reset() - The reset function will reset the ports on the host. | 2056 | * fc_eh_host_reset() - Reset a Scsi_Host. |
2011 | * @sc_cmd: scsi command | 2057 | * @sc_cmd: The SCSI command that identifies the SCSI host to be reset |
2012 | */ | 2058 | */ |
2013 | int fc_eh_host_reset(struct scsi_cmnd *sc_cmd) | 2059 | int fc_eh_host_reset(struct scsi_cmnd *sc_cmd) |
2014 | { | 2060 | { |
2015 | struct Scsi_Host *shost = sc_cmd->device->host; | 2061 | struct Scsi_Host *shost = sc_cmd->device->host; |
2016 | struct fc_lport *lp = shost_priv(shost); | 2062 | struct fc_lport *lport = shost_priv(shost); |
2017 | unsigned long wait_tmo; | 2063 | unsigned long wait_tmo; |
2018 | 2064 | ||
2019 | FC_SCSI_DBG(lp, "Resetting host\n"); | 2065 | FC_SCSI_DBG(lport, "Resetting host\n"); |
2020 | 2066 | ||
2021 | lp->tt.lport_reset(lp); | 2067 | lport->tt.lport_reset(lport); |
2022 | wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT; | 2068 | wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT; |
2023 | while (!fc_fcp_lport_queue_ready(lp) && time_before(jiffies, wait_tmo)) | 2069 | while (!fc_fcp_lport_queue_ready(lport) && time_before(jiffies, |
2070 | wait_tmo)) | ||
2024 | msleep(1000); | 2071 | msleep(1000); |
2025 | 2072 | ||
2026 | if (fc_fcp_lport_queue_ready(lp)) { | 2073 | if (fc_fcp_lport_queue_ready(lport)) { |
2027 | shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded " | 2074 | shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded " |
2028 | "on port (%6x)\n", fc_host_port_id(lp->host)); | 2075 | "on port (%6x)\n", fc_host_port_id(lport->host)); |
2029 | return SUCCESS; | 2076 | return SUCCESS; |
2030 | } else { | 2077 | } else { |
2031 | shost_printk(KERN_INFO, shost, "libfc: Host reset failed, " | 2078 | shost_printk(KERN_INFO, shost, "libfc: Host reset failed, " |
2032 | "port (%6x) is not ready.\n", | 2079 | "port (%6x) is not ready.\n", |
2033 | fc_host_port_id(lp->host)); | 2080 | fc_host_port_id(lport->host)); |
2034 | return FAILED; | 2081 | return FAILED; |
2035 | } | 2082 | } |
2036 | } | 2083 | } |
2037 | EXPORT_SYMBOL(fc_eh_host_reset); | 2084 | EXPORT_SYMBOL(fc_eh_host_reset); |
2038 | 2085 | ||
2039 | /** | 2086 | /** |
2040 | * fc_slave_alloc() - configure queue depth | 2087 | * fc_slave_alloc() - Configure the queue depth of a Scsi_Host |
2041 | * @sdev: scsi device | 2088 | * @sdev: The SCSI device that identifies the SCSI host |
2042 | * | 2089 | * |
2043 | * Configures queue depth based on host's cmd_per_len. If not set | 2090 | * Configures queue depth based on host's cmd_per_len. If not set |
2044 | * then we use the libfc default. | 2091 | * then we use the libfc default. |
@@ -2046,29 +2093,50 @@ EXPORT_SYMBOL(fc_eh_host_reset); | |||
2046 | int fc_slave_alloc(struct scsi_device *sdev) | 2093 | int fc_slave_alloc(struct scsi_device *sdev) |
2047 | { | 2094 | { |
2048 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | 2095 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
2049 | int queue_depth; | ||
2050 | 2096 | ||
2051 | if (!rport || fc_remote_port_chkready(rport)) | 2097 | if (!rport || fc_remote_port_chkready(rport)) |
2052 | return -ENXIO; | 2098 | return -ENXIO; |
2053 | 2099 | ||
2054 | if (sdev->tagged_supported) { | 2100 | if (sdev->tagged_supported) |
2055 | if (sdev->host->hostt->cmd_per_lun) | 2101 | scsi_activate_tcq(sdev, FC_FCP_DFLT_QUEUE_DEPTH); |
2056 | queue_depth = sdev->host->hostt->cmd_per_lun; | 2102 | else |
2057 | else | 2103 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), |
2058 | queue_depth = FC_FCP_DFLT_QUEUE_DEPTH; | 2104 | FC_FCP_DFLT_QUEUE_DEPTH); |
2059 | scsi_activate_tcq(sdev, queue_depth); | 2105 | |
2060 | } | ||
2061 | return 0; | 2106 | return 0; |
2062 | } | 2107 | } |
2063 | EXPORT_SYMBOL(fc_slave_alloc); | 2108 | EXPORT_SYMBOL(fc_slave_alloc); |
2064 | 2109 | ||
2065 | int fc_change_queue_depth(struct scsi_device *sdev, int qdepth) | 2110 | /** |
2111 | * fc_change_queue_depth() - Change a device's queue depth | ||
2112 | * @sdev: The SCSI device whose queue depth is to change | ||
2113 | * @qdepth: The new queue depth | ||
2114 | * @reason: The resason for the change | ||
2115 | */ | ||
2116 | int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) | ||
2066 | { | 2117 | { |
2067 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | 2118 | switch (reason) { |
2119 | case SCSI_QDEPTH_DEFAULT: | ||
2120 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | ||
2121 | break; | ||
2122 | case SCSI_QDEPTH_QFULL: | ||
2123 | scsi_track_queue_full(sdev, qdepth); | ||
2124 | break; | ||
2125 | case SCSI_QDEPTH_RAMP_UP: | ||
2126 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | ||
2127 | break; | ||
2128 | default: | ||
2129 | return -EOPNOTSUPP; | ||
2130 | } | ||
2068 | return sdev->queue_depth; | 2131 | return sdev->queue_depth; |
2069 | } | 2132 | } |
2070 | EXPORT_SYMBOL(fc_change_queue_depth); | 2133 | EXPORT_SYMBOL(fc_change_queue_depth); |
2071 | 2134 | ||
2135 | /** | ||
2136 | * fc_change_queue_type() - Change a device's queue type | ||
2137 | * @sdev: The SCSI device whose queue depth is to change | ||
2138 | * @tag_type: Identifier for queue type | ||
2139 | */ | ||
2072 | int fc_change_queue_type(struct scsi_device *sdev, int tag_type) | 2140 | int fc_change_queue_type(struct scsi_device *sdev, int tag_type) |
2073 | { | 2141 | { |
2074 | if (sdev->tagged_supported) { | 2142 | if (sdev->tagged_supported) { |
@@ -2084,38 +2152,69 @@ int fc_change_queue_type(struct scsi_device *sdev, int tag_type) | |||
2084 | } | 2152 | } |
2085 | EXPORT_SYMBOL(fc_change_queue_type); | 2153 | EXPORT_SYMBOL(fc_change_queue_type); |
2086 | 2154 | ||
2087 | void fc_fcp_destroy(struct fc_lport *lp) | 2155 | /** |
2156 | * fc_fcp_destory() - Tear down the FCP layer for a given local port | ||
2157 | * @lport: The local port that no longer needs the FCP layer | ||
2158 | */ | ||
2159 | void fc_fcp_destroy(struct fc_lport *lport) | ||
2088 | { | 2160 | { |
2089 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 2161 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
2090 | 2162 | ||
2091 | if (!list_empty(&si->scsi_pkt_queue)) | 2163 | if (!list_empty(&si->scsi_pkt_queue)) |
2092 | printk(KERN_ERR "libfc: Leaked SCSI packets when destroying " | 2164 | printk(KERN_ERR "libfc: Leaked SCSI packets when destroying " |
2093 | "port (%6x)\n", fc_host_port_id(lp->host)); | 2165 | "port (%6x)\n", fc_host_port_id(lport->host)); |
2094 | 2166 | ||
2095 | mempool_destroy(si->scsi_pkt_pool); | 2167 | mempool_destroy(si->scsi_pkt_pool); |
2096 | kfree(si); | 2168 | kfree(si); |
2097 | lp->scsi_priv = NULL; | 2169 | lport->scsi_priv = NULL; |
2098 | } | 2170 | } |
2099 | EXPORT_SYMBOL(fc_fcp_destroy); | 2171 | EXPORT_SYMBOL(fc_fcp_destroy); |
2100 | 2172 | ||
2101 | int fc_fcp_init(struct fc_lport *lp) | 2173 | int fc_setup_fcp() |
2174 | { | ||
2175 | int rc = 0; | ||
2176 | |||
2177 | scsi_pkt_cachep = kmem_cache_create("libfc_fcp_pkt", | ||
2178 | sizeof(struct fc_fcp_pkt), | ||
2179 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2180 | if (!scsi_pkt_cachep) { | ||
2181 | printk(KERN_ERR "libfc: Unable to allocate SRB cache, " | ||
2182 | "module load failed!"); | ||
2183 | rc = -ENOMEM; | ||
2184 | } | ||
2185 | |||
2186 | return rc; | ||
2187 | } | ||
2188 | |||
2189 | void fc_destroy_fcp() | ||
2190 | { | ||
2191 | if (scsi_pkt_cachep) | ||
2192 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2193 | } | ||
2194 | |||
2195 | /** | ||
2196 | * fc_fcp_init() - Initialize the FCP layer for a local port | ||
2197 | * @lport: The local port to initialize the exchange layer for | ||
2198 | */ | ||
2199 | int fc_fcp_init(struct fc_lport *lport) | ||
2102 | { | 2200 | { |
2103 | int rc; | 2201 | int rc; |
2104 | struct fc_fcp_internal *si; | 2202 | struct fc_fcp_internal *si; |
2105 | 2203 | ||
2106 | if (!lp->tt.fcp_cmd_send) | 2204 | if (!lport->tt.fcp_cmd_send) |
2107 | lp->tt.fcp_cmd_send = fc_fcp_cmd_send; | 2205 | lport->tt.fcp_cmd_send = fc_fcp_cmd_send; |
2108 | 2206 | ||
2109 | if (!lp->tt.fcp_cleanup) | 2207 | if (!lport->tt.fcp_cleanup) |
2110 | lp->tt.fcp_cleanup = fc_fcp_cleanup; | 2208 | lport->tt.fcp_cleanup = fc_fcp_cleanup; |
2111 | 2209 | ||
2112 | if (!lp->tt.fcp_abort_io) | 2210 | if (!lport->tt.fcp_abort_io) |
2113 | lp->tt.fcp_abort_io = fc_fcp_abort_io; | 2211 | lport->tt.fcp_abort_io = fc_fcp_abort_io; |
2114 | 2212 | ||
2115 | si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL); | 2213 | si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL); |
2116 | if (!si) | 2214 | if (!si) |
2117 | return -ENOMEM; | 2215 | return -ENOMEM; |
2118 | lp->scsi_priv = si; | 2216 | lport->scsi_priv = si; |
2217 | si->max_can_queue = lport->host->can_queue; | ||
2119 | INIT_LIST_HEAD(&si->scsi_pkt_queue); | 2218 | INIT_LIST_HEAD(&si->scsi_pkt_queue); |
2120 | 2219 | ||
2121 | si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep); | 2220 | si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep); |
@@ -2130,42 +2229,3 @@ free_internal: | |||
2130 | return rc; | 2229 | return rc; |
2131 | } | 2230 | } |
2132 | EXPORT_SYMBOL(fc_fcp_init); | 2231 | EXPORT_SYMBOL(fc_fcp_init); |
2133 | |||
2134 | static int __init libfc_init(void) | ||
2135 | { | ||
2136 | int rc; | ||
2137 | |||
2138 | scsi_pkt_cachep = kmem_cache_create("libfc_fcp_pkt", | ||
2139 | sizeof(struct fc_fcp_pkt), | ||
2140 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2141 | if (scsi_pkt_cachep == NULL) { | ||
2142 | printk(KERN_ERR "libfc: Unable to allocate SRB cache, " | ||
2143 | "module load failed!"); | ||
2144 | return -ENOMEM; | ||
2145 | } | ||
2146 | |||
2147 | rc = fc_setup_exch_mgr(); | ||
2148 | if (rc) | ||
2149 | goto destroy_pkt_cache; | ||
2150 | |||
2151 | rc = fc_setup_rport(); | ||
2152 | if (rc) | ||
2153 | goto destroy_em; | ||
2154 | |||
2155 | return rc; | ||
2156 | destroy_em: | ||
2157 | fc_destroy_exch_mgr(); | ||
2158 | destroy_pkt_cache: | ||
2159 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2160 | return rc; | ||
2161 | } | ||
2162 | |||
2163 | static void __exit libfc_exit(void) | ||
2164 | { | ||
2165 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2166 | fc_destroy_exch_mgr(); | ||
2167 | fc_destroy_rport(); | ||
2168 | } | ||
2169 | |||
2170 | module_init(libfc_init); | ||
2171 | module_exit(libfc_exit); | ||