@@ -174,6 +174,7 @@ struct sbp2_target {
174174 unsigned int mgt_orb_timeout ;
175175 unsigned int max_payload ;
176176
177+ spinlock_t lock ;
177178 int dont_block ; /* counter for each logical unit */
178179 int blocked ; /* ditto */
179180};
@@ -270,6 +271,7 @@ struct sbp2_orb {
270271 dma_addr_t request_bus ;
271272 int rcode ;
272273 void (* callback )(struct sbp2_orb * orb , struct sbp2_status * status );
274+ struct sbp2_logical_unit * lu ;
273275 struct list_head link ;
274276};
275277
@@ -321,7 +323,6 @@ struct sbp2_command_orb {
321323 u8 command_block [SBP2_MAX_CDB_SIZE ];
322324 } request ;
323325 struct scsi_cmnd * cmd ;
324- struct sbp2_logical_unit * lu ;
325326
326327 struct sbp2_pointer page_table [SG_ALL ] __attribute__((aligned (8 )));
327328 dma_addr_t page_table_bus ;
@@ -444,7 +445,7 @@ static void sbp2_status_write(struct fw_card *card, struct fw_request *request,
444445 }
445446
446447 /* Lookup the orb corresponding to this status write. */
447- spin_lock_irqsave (& card -> lock , flags );
448+ spin_lock_irqsave (& lu -> tgt -> lock , flags );
448449 list_for_each_entry (orb , & lu -> orb_list , link ) {
449450 if (STATUS_GET_ORB_HIGH (status ) == 0 &&
450451 STATUS_GET_ORB_LOW (status ) == orb -> request_bus ) {
@@ -453,7 +454,7 @@ static void sbp2_status_write(struct fw_card *card, struct fw_request *request,
453454 break ;
454455 }
455456 }
456- spin_unlock_irqrestore (& card -> lock , flags );
457+ spin_unlock_irqrestore (& lu -> tgt -> lock , flags );
457458
458459 if (& orb -> link != & lu -> orb_list ) {
459460 orb -> callback (orb , & status );
@@ -480,18 +481,18 @@ static void complete_transaction(struct fw_card *card, int rcode,
480481 * been set and only does the cleanup if the transaction
481482 * failed and we didn't already get a status write.
482483 */
483- spin_lock_irqsave (& card -> lock , flags );
484+ spin_lock_irqsave (& orb -> lu -> tgt -> lock , flags );
484485
485486 if (orb -> rcode == -1 )
486487 orb -> rcode = rcode ;
487488 if (orb -> rcode != RCODE_COMPLETE ) {
488489 list_del (& orb -> link );
489- spin_unlock_irqrestore (& card -> lock , flags );
490+ spin_unlock_irqrestore (& orb -> lu -> tgt -> lock , flags );
490491
491492 orb -> callback (orb , NULL );
492493 kref_put (& orb -> kref , free_orb ); /* orb callback reference */
493494 } else {
494- spin_unlock_irqrestore (& card -> lock , flags );
495+ spin_unlock_irqrestore (& orb -> lu -> tgt -> lock , flags );
495496 }
496497
497498 kref_put (& orb -> kref , free_orb ); /* transaction callback reference */
@@ -507,9 +508,10 @@ static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
507508 orb_pointer .high = 0 ;
508509 orb_pointer .low = cpu_to_be32 (orb -> request_bus );
509510
510- spin_lock_irqsave (& device -> card -> lock , flags );
511+ orb -> lu = lu ;
512+ spin_lock_irqsave (& lu -> tgt -> lock , flags );
511513 list_add_tail (& orb -> link , & lu -> orb_list );
512- spin_unlock_irqrestore (& device -> card -> lock , flags );
514+ spin_unlock_irqrestore (& lu -> tgt -> lock , flags );
513515
514516 kref_get (& orb -> kref ); /* transaction callback reference */
515517 kref_get (& orb -> kref ); /* orb callback reference */
@@ -527,9 +529,9 @@ static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu)
527529 int retval = - ENOENT ;
528530
529531 INIT_LIST_HEAD (& list );
530- spin_lock_irq (& device -> card -> lock );
532+ spin_lock_irq (& lu -> tgt -> lock );
531533 list_splice_init (& lu -> orb_list , & list );
532- spin_unlock_irq (& device -> card -> lock );
534+ spin_unlock_irq (& lu -> tgt -> lock );
533535
534536 list_for_each_entry_safe (orb , next , & list , link ) {
535537 retval = 0 ;
@@ -686,14 +688,11 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu)
686688 & d , 4 , complete_agent_reset_write_no_wait , t );
687689}
688690
689- static inline void sbp2_allow_block (struct sbp2_logical_unit * lu )
691+ static inline void sbp2_allow_block (struct sbp2_target * tgt )
690692{
691- struct sbp2_target * tgt = lu -> tgt ;
692- struct fw_card * card = target_parent_device (tgt )-> card ;
693-
694- spin_lock_irq (& card -> lock );
693+ spin_lock_irq (& tgt -> lock );
695694 -- tgt -> dont_block ;
696- spin_unlock_irq (& card -> lock );
695+ spin_unlock_irq (& tgt -> lock );
697696}
698697
699698/*
@@ -702,7 +701,7 @@ static inline void sbp2_allow_block(struct sbp2_logical_unit *lu)
702701 * logical units have been finished (indicated by dont_block == 0).
703702 * - lu->generation is stale.
704703 *
705- * Note, scsi_block_requests() must be called while holding card ->lock,
704+ * Note, scsi_block_requests() must be called while holding tgt ->lock,
706705 * otherwise it might foil sbp2_[conditionally_]unblock()'s attempt to
707706 * unblock the target.
708707 */
@@ -714,20 +713,20 @@ static void sbp2_conditionally_block(struct sbp2_logical_unit *lu)
714713 container_of ((void * )tgt , struct Scsi_Host , hostdata [0 ]);
715714 unsigned long flags ;
716715
717- spin_lock_irqsave (& card -> lock , flags );
716+ spin_lock_irqsave (& tgt -> lock , flags );
718717 if (!tgt -> dont_block && !lu -> blocked &&
719718 lu -> generation != card -> generation ) {
720719 lu -> blocked = true;
721720 if (++ tgt -> blocked == 1 )
722721 scsi_block_requests (shost );
723722 }
724- spin_unlock_irqrestore (& card -> lock , flags );
723+ spin_unlock_irqrestore (& tgt -> lock , flags );
725724}
726725
727726/*
728727 * Unblocks lu->tgt as soon as all its logical units can be unblocked.
729728 * Note, it is harmless to run scsi_unblock_requests() outside the
730- * card ->lock protected section. On the other hand, running it inside
729+ * tgt ->lock protected section. On the other hand, running it inside
731730 * the section might clash with shost->host_lock.
732731 */
733732static void sbp2_conditionally_unblock (struct sbp2_logical_unit * lu )
@@ -738,12 +737,12 @@ static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
738737 container_of ((void * )tgt , struct Scsi_Host , hostdata [0 ]);
739738 bool unblock = false;
740739
741- spin_lock_irq (& card -> lock );
740+ spin_lock_irq (& tgt -> lock );
742741 if (lu -> blocked && lu -> generation == card -> generation ) {
743742 lu -> blocked = false;
744743 unblock = -- tgt -> blocked == 0 ;
745744 }
746- spin_unlock_irq (& card -> lock );
745+ spin_unlock_irq (& tgt -> lock );
747746
748747 if (unblock )
749748 scsi_unblock_requests (shost );
@@ -752,18 +751,17 @@ static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
752751/*
753752 * Prevents future blocking of tgt and unblocks it.
754753 * Note, it is harmless to run scsi_unblock_requests() outside the
755- * card ->lock protected section. On the other hand, running it inside
754+ * tgt ->lock protected section. On the other hand, running it inside
756755 * the section might clash with shost->host_lock.
757756 */
758757static void sbp2_unblock (struct sbp2_target * tgt )
759758{
760- struct fw_card * card = target_parent_device (tgt )-> card ;
761759 struct Scsi_Host * shost =
762760 container_of ((void * )tgt , struct Scsi_Host , hostdata [0 ]);
763761
764- spin_lock_irq (& card -> lock );
762+ spin_lock_irq (& tgt -> lock );
765763 ++ tgt -> dont_block ;
766- spin_unlock_irq (& card -> lock );
764+ spin_unlock_irq (& tgt -> lock );
767765
768766 scsi_unblock_requests (shost );
769767}
@@ -899,7 +897,7 @@ static void sbp2_login(struct work_struct *work)
899897 /* No error during __scsi_add_device() */
900898 lu -> has_sdev = true;
901899 scsi_device_put (sdev );
902- sbp2_allow_block (lu );
900+ sbp2_allow_block (tgt );
903901
904902 return ;
905903
@@ -1158,6 +1156,7 @@ static int sbp2_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
11581156 dev_set_drvdata (& unit -> device , tgt );
11591157 tgt -> unit = unit ;
11601158 INIT_LIST_HEAD (& tgt -> lu_list );
1159+ spin_lock_init (& tgt -> lock );
11611160 tgt -> guid = (u64 )device -> config_rom [3 ] << 32 | device -> config_rom [4 ];
11621161
11631162 if (fw_device_enable_phys_dma (device ) < 0 )
@@ -1354,12 +1353,12 @@ static void complete_command_orb(struct sbp2_orb *base_orb,
13541353{
13551354 struct sbp2_command_orb * orb =
13561355 container_of (base_orb , struct sbp2_command_orb , base );
1357- struct fw_device * device = target_parent_device (orb -> lu -> tgt );
1356+ struct fw_device * device = target_parent_device (base_orb -> lu -> tgt );
13581357 int result ;
13591358
13601359 if (status != NULL ) {
13611360 if (STATUS_GET_DEAD (* status ))
1362- sbp2_agent_reset_no_wait (orb -> lu );
1361+ sbp2_agent_reset_no_wait (base_orb -> lu );
13631362
13641363 switch (STATUS_GET_RESPONSE (* status )) {
13651364 case SBP2_STATUS_REQUEST_COMPLETE :
@@ -1385,7 +1384,7 @@ static void complete_command_orb(struct sbp2_orb *base_orb,
13851384 * or when sending the write (less likely).
13861385 */
13871386 result = DID_BUS_BUSY << 16 ;
1388- sbp2_conditionally_block (orb -> lu );
1387+ sbp2_conditionally_block (base_orb -> lu );
13891388 }
13901389
13911390 dma_unmap_single (device -> card -> device , orb -> base .request_bus ,
@@ -1482,7 +1481,6 @@ static int sbp2_scsi_queuecommand(struct Scsi_Host *shost,
14821481 /* Initialize rcode to something not RCODE_COMPLETE. */
14831482 orb -> base .rcode = -1 ;
14841483 kref_init (& orb -> base .kref );
1485- orb -> lu = lu ;
14861484 orb -> cmd = cmd ;
14871485 orb -> request .next .high = cpu_to_be32 (SBP2_ORB_NULL );
14881486 orb -> request .misc = cpu_to_be32 (
0 commit comments