aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/esas2r/esas2r.h125
-rw-r--r--drivers/scsi/esas2r/esas2r_disc.c55
-rw-r--r--drivers/scsi/esas2r/esas2r_flash.c34
-rw-r--r--drivers/scsi/esas2r/esas2r_init.c143
-rw-r--r--drivers/scsi/esas2r/esas2r_int.c97
-rw-r--r--drivers/scsi/esas2r/esas2r_io.c73
-rw-r--r--drivers/scsi/esas2r/esas2r_ioctl.c28
-rw-r--r--drivers/scsi/esas2r/esas2r_main.c34
-rw-r--r--drivers/scsi/esas2r/esas2r_targdb.c2
-rw-r--r--drivers/scsi/esas2r/esas2r_vda.c6
10 files changed, 291 insertions, 306 deletions
diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 0838e265e0b9..d128c96a501d 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -799,47 +799,47 @@ struct esas2r_adapter {
799 struct esas2r_target *targetdb_end; 799 struct esas2r_target *targetdb_end;
800 unsigned char *regs; 800 unsigned char *regs;
801 unsigned char *data_window; 801 unsigned char *data_window;
802 u32 volatile flags; 802 long flags;
803 #define AF_PORT_CHANGE (u32)(0x00000001) 803 #define AF_PORT_CHANGE 0
804 #define AF_CHPRST_NEEDED (u32)(0x00000004) 804 #define AF_CHPRST_NEEDED 1
805 #define AF_CHPRST_PENDING (u32)(0x00000008) 805 #define AF_CHPRST_PENDING 2
806 #define AF_CHPRST_DETECTED (u32)(0x00000010) 806 #define AF_CHPRST_DETECTED 3
807 #define AF_BUSRST_NEEDED (u32)(0x00000020) 807 #define AF_BUSRST_NEEDED 4
808 #define AF_BUSRST_PENDING (u32)(0x00000040) 808 #define AF_BUSRST_PENDING 5
809 #define AF_BUSRST_DETECTED (u32)(0x00000080) 809 #define AF_BUSRST_DETECTED 6
810 #define AF_DISABLED (u32)(0x00000100) 810 #define AF_DISABLED 7
811 #define AF_FLASH_LOCK (u32)(0x00000200) 811 #define AF_FLASH_LOCK 8
812 #define AF_OS_RESET (u32)(0x00002000) 812 #define AF_OS_RESET 9
813 #define AF_FLASHING (u32)(0x00004000) 813 #define AF_FLASHING 10
814 #define AF_POWER_MGT (u32)(0x00008000) 814 #define AF_POWER_MGT 11
815 #define AF_NVR_VALID (u32)(0x00010000) 815 #define AF_NVR_VALID 12
816 #define AF_DEGRADED_MODE (u32)(0x00020000) 816 #define AF_DEGRADED_MODE 13
817 #define AF_DISC_PENDING (u32)(0x00040000) 817 #define AF_DISC_PENDING 14
818 #define AF_TASKLET_SCHEDULED (u32)(0x00080000) 818 #define AF_TASKLET_SCHEDULED 15
819 #define AF_HEARTBEAT (u32)(0x00200000) 819 #define AF_HEARTBEAT 16
820 #define AF_HEARTBEAT_ENB (u32)(0x00400000) 820 #define AF_HEARTBEAT_ENB 17
821 #define AF_NOT_PRESENT (u32)(0x00800000) 821 #define AF_NOT_PRESENT 18
822 #define AF_CHPRST_STARTED (u32)(0x01000000) 822 #define AF_CHPRST_STARTED 19
823 #define AF_FIRST_INIT (u32)(0x02000000) 823 #define AF_FIRST_INIT 20
824 #define AF_POWER_DOWN (u32)(0x04000000) 824 #define AF_POWER_DOWN 21
825 #define AF_DISC_IN_PROG (u32)(0x08000000) 825 #define AF_DISC_IN_PROG 22
826 #define AF_COMM_LIST_TOGGLE (u32)(0x10000000) 826 #define AF_COMM_LIST_TOGGLE 23
827 #define AF_LEGACY_SGE_MODE (u32)(0x20000000) 827 #define AF_LEGACY_SGE_MODE 24
828 #define AF_DISC_POLLED (u32)(0x40000000) 828 #define AF_DISC_POLLED 25
829 u32 volatile flags2; 829 long flags2;
830 #define AF2_SERIAL_FLASH (u32)(0x00000001) 830 #define AF2_SERIAL_FLASH 0
831 #define AF2_DEV_SCAN (u32)(0x00000002) 831 #define AF2_DEV_SCAN 1
832 #define AF2_DEV_CNT_OK (u32)(0x00000004) 832 #define AF2_DEV_CNT_OK 2
833 #define AF2_COREDUMP_AVAIL (u32)(0x00000008) 833 #define AF2_COREDUMP_AVAIL 3
834 #define AF2_COREDUMP_SAVED (u32)(0x00000010) 834 #define AF2_COREDUMP_SAVED 4
835 #define AF2_VDA_POWER_DOWN (u32)(0x00000100) 835 #define AF2_VDA_POWER_DOWN 5
836 #define AF2_THUNDERLINK (u32)(0x00000200) 836 #define AF2_THUNDERLINK 6
837 #define AF2_THUNDERBOLT (u32)(0x00000400) 837 #define AF2_THUNDERBOLT 7
838 #define AF2_INIT_DONE (u32)(0x00000800) 838 #define AF2_INIT_DONE 8
839 #define AF2_INT_PENDING (u32)(0x00001000) 839 #define AF2_INT_PENDING 9
840 #define AF2_TIMER_TICK (u32)(0x00002000) 840 #define AF2_TIMER_TICK 10
841 #define AF2_IRQ_CLAIMED (u32)(0x00004000) 841 #define AF2_IRQ_CLAIMED 11
842 #define AF2_MSI_ENABLED (u32)(0x00008000) 842 #define AF2_MSI_ENABLED 12
843 atomic_t disable_cnt; 843 atomic_t disable_cnt;
844 atomic_t dis_ints_cnt; 844 atomic_t dis_ints_cnt;
845 u32 int_stat; 845 u32 int_stat;
@@ -1150,16 +1150,6 @@ void esas2r_queue_fw_event(struct esas2r_adapter *a,
1150 int data_sz); 1150 int data_sz);
1151 1151
1152/* Inline functions */ 1152/* Inline functions */
1153static inline u32 esas2r_lock_set_flags(volatile u32 *flags, u32 bits)
1154{
1155 return test_and_set_bit(ilog2(bits), (volatile unsigned long *)flags);
1156}
1157
1158static inline u32 esas2r_lock_clear_flags(volatile u32 *flags, u32 bits)
1159{
1160 return test_and_clear_bit(ilog2(bits),
1161 (volatile unsigned long *)flags);
1162}
1163 1153
1164/* Allocate a chip scatter/gather list entry */ 1154/* Allocate a chip scatter/gather list entry */
1165static inline struct esas2r_mem_desc *esas2r_alloc_sgl(struct esas2r_adapter *a) 1155static inline struct esas2r_mem_desc *esas2r_alloc_sgl(struct esas2r_adapter *a)
@@ -1303,10 +1293,13 @@ static inline void esas2r_rq_destroy_request(struct esas2r_request *rq,
1303 1293
1304static inline bool esas2r_is_tasklet_pending(struct esas2r_adapter *a) 1294static inline bool esas2r_is_tasklet_pending(struct esas2r_adapter *a)
1305{ 1295{
1306 return (a->flags & (AF_BUSRST_NEEDED | AF_BUSRST_DETECTED 1296
1307 | AF_CHPRST_NEEDED | AF_CHPRST_DETECTED 1297 return test_bit(AF_BUSRST_NEEDED, &a->flags) ||
1308 | AF_PORT_CHANGE)) 1298 test_bit(AF_BUSRST_DETECTED, &a->flags) ||
1309 ? true : false; 1299 test_bit(AF_CHPRST_NEEDED, &a->flags) ||
1300 test_bit(AF_CHPRST_DETECTED, &a->flags) ||
1301 test_bit(AF_PORT_CHANGE, &a->flags);
1302
1310} 1303}
1311 1304
1312/* 1305/*
@@ -1345,24 +1338,24 @@ static inline void esas2r_enable_chip_interrupts(struct esas2r_adapter *a)
1345static inline void esas2r_schedule_tasklet(struct esas2r_adapter *a) 1338static inline void esas2r_schedule_tasklet(struct esas2r_adapter *a)
1346{ 1339{
1347 /* make sure we don't schedule twice */ 1340 /* make sure we don't schedule twice */
1348 if (!(esas2r_lock_set_flags(&a->flags, AF_TASKLET_SCHEDULED) & 1341 if (!test_and_set_bit(AF_TASKLET_SCHEDULED, &a->flags))
1349 ilog2(AF_TASKLET_SCHEDULED)))
1350 tasklet_hi_schedule(&a->tasklet); 1342 tasklet_hi_schedule(&a->tasklet);
1351} 1343}
1352 1344
1353static inline void esas2r_enable_heartbeat(struct esas2r_adapter *a) 1345static inline void esas2r_enable_heartbeat(struct esas2r_adapter *a)
1354{ 1346{
1355 if (!(a->flags & (AF_DEGRADED_MODE | AF_CHPRST_PENDING)) 1347 if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
1356 && (a->nvram->options2 & SASNVR2_HEARTBEAT)) 1348 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
1357 esas2r_lock_set_flags(&a->flags, AF_HEARTBEAT_ENB); 1349 (a->nvram->options2 & SASNVR2_HEARTBEAT))
1350 set_bit(AF_HEARTBEAT_ENB, &a->flags);
1358 else 1351 else
1359 esas2r_lock_clear_flags(&a->flags, AF_HEARTBEAT_ENB); 1352 clear_bit(AF_HEARTBEAT_ENB, &a->flags);
1360} 1353}
1361 1354
1362static inline void esas2r_disable_heartbeat(struct esas2r_adapter *a) 1355static inline void esas2r_disable_heartbeat(struct esas2r_adapter *a)
1363{ 1356{
1364 esas2r_lock_clear_flags(&a->flags, AF_HEARTBEAT_ENB); 1357 clear_bit(AF_HEARTBEAT_ENB, &a->flags);
1365 esas2r_lock_clear_flags(&a->flags, AF_HEARTBEAT); 1358 clear_bit(AF_HEARTBEAT, &a->flags);
1366} 1359}
1367 1360
1368/* Set the initial state for resetting the adapter on the next pass through 1361/* Set the initial state for resetting the adapter on the next pass through
@@ -1372,9 +1365,9 @@ static inline void esas2r_local_reset_adapter(struct esas2r_adapter *a)
1372{ 1365{
1373 esas2r_disable_heartbeat(a); 1366 esas2r_disable_heartbeat(a);
1374 1367
1375 esas2r_lock_set_flags(&a->flags, AF_CHPRST_NEEDED); 1368 set_bit(AF_CHPRST_NEEDED, &a->flags);
1376 esas2r_lock_set_flags(&a->flags, AF_CHPRST_PENDING); 1369 set_bit(AF_CHPRST_PENDING, &a->flags);
1377 esas2r_lock_set_flags(&a->flags, AF_DISC_PENDING); 1370 set_bit(AF_DISC_PENDING, &a->flags);
1378} 1371}
1379 1372
1380/* See if an interrupt is pending on the adapter. */ 1373/* See if an interrupt is pending on the adapter. */
diff --git a/drivers/scsi/esas2r/esas2r_disc.c b/drivers/scsi/esas2r/esas2r_disc.c
index dec6c334ce3e..1c079f4300a5 100644
--- a/drivers/scsi/esas2r/esas2r_disc.c
+++ b/drivers/scsi/esas2r/esas2r_disc.c
@@ -86,9 +86,9 @@ void esas2r_disc_initialize(struct esas2r_adapter *a)
86 86
87 esas2r_trace_enter(); 87 esas2r_trace_enter();
88 88
89 esas2r_lock_clear_flags(&a->flags, AF_DISC_IN_PROG); 89 clear_bit(AF_DISC_IN_PROG, &a->flags);
90 esas2r_lock_clear_flags(&a->flags2, AF2_DEV_SCAN); 90 clear_bit(AF2_DEV_SCAN, &a->flags2);
91 esas2r_lock_clear_flags(&a->flags2, AF2_DEV_CNT_OK); 91 clear_bit(AF2_DEV_CNT_OK, &a->flags2);
92 92
93 a->disc_start_time = jiffies_to_msecs(jiffies); 93 a->disc_start_time = jiffies_to_msecs(jiffies);
94 a->disc_wait_time = nvr->dev_wait_time * 1000; 94 a->disc_wait_time = nvr->dev_wait_time * 1000;
@@ -107,7 +107,8 @@ void esas2r_disc_initialize(struct esas2r_adapter *a)
107 107
108 a->general_req.interrupt_cx = NULL; 108 a->general_req.interrupt_cx = NULL;
109 109
110 if (a->flags & (AF_CHPRST_DETECTED | AF_POWER_MGT)) { 110 if (test_bit(AF_CHPRST_DETECTED, &a->flags) ||
111 test_bit(AF_POWER_MGT, &a->flags)) {
111 if (a->prev_dev_cnt == 0) { 112 if (a->prev_dev_cnt == 0) {
112 /* Don't bother waiting if there is nothing to wait 113 /* Don't bother waiting if there is nothing to wait
113 * for. 114 * for.
@@ -212,9 +213,7 @@ void esas2r_disc_check_complete(struct esas2r_adapter *a)
212 || a->disc_wait_cnt == 0)) { 213 || a->disc_wait_cnt == 0)) {
213 /* After three seconds of waiting, schedule a scan. */ 214 /* After three seconds of waiting, schedule a scan. */
214 if (time >= 3000 215 if (time >= 3000
215 && !(esas2r_lock_set_flags(&a->flags2, 216 && !test_and_set_bit(AF2_DEV_SCAN, &a->flags2)) {
216 AF2_DEV_SCAN) &
217 ilog2(AF2_DEV_SCAN))) {
218 spin_lock_irqsave(&a->mem_lock, flags); 217 spin_lock_irqsave(&a->mem_lock, flags);
219 esas2r_disc_queue_event(a, DCDE_DEV_SCAN); 218 esas2r_disc_queue_event(a, DCDE_DEV_SCAN);
220 spin_unlock_irqrestore(&a->mem_lock, flags); 219 spin_unlock_irqrestore(&a->mem_lock, flags);
@@ -228,18 +227,14 @@ void esas2r_disc_check_complete(struct esas2r_adapter *a)
228 * We are done waiting...we think. Adjust the wait time to 227 * We are done waiting...we think. Adjust the wait time to
229 * consume events after the count is met. 228 * consume events after the count is met.
230 */ 229 */
231 if (!(esas2r_lock_set_flags(&a->flags2, AF2_DEV_CNT_OK) 230 if (!test_and_set_bit(AF2_DEV_CNT_OK, &a->flags2))
232 & ilog2(AF2_DEV_CNT_OK)))
233 a->disc_wait_time = time + 3000; 231 a->disc_wait_time = time + 3000;
234 232
235 /* If we haven't done a full scan yet, do it now. */ 233 /* If we haven't done a full scan yet, do it now. */
236 if (!(esas2r_lock_set_flags(&a->flags2, 234 if (!test_and_set_bit(AF2_DEV_SCAN, &a->flags2)) {
237 AF2_DEV_SCAN) &
238 ilog2(AF2_DEV_SCAN))) {
239 spin_lock_irqsave(&a->mem_lock, flags); 235 spin_lock_irqsave(&a->mem_lock, flags);
240 esas2r_disc_queue_event(a, DCDE_DEV_SCAN); 236 esas2r_disc_queue_event(a, DCDE_DEV_SCAN);
241 spin_unlock_irqrestore(&a->mem_lock, flags); 237 spin_unlock_irqrestore(&a->mem_lock, flags);
242
243 esas2r_trace_exit(); 238 esas2r_trace_exit();
244 return; 239 return;
245 } 240 }
@@ -253,9 +248,7 @@ void esas2r_disc_check_complete(struct esas2r_adapter *a)
253 return; 248 return;
254 } 249 }
255 } else { 250 } else {
256 if (!(esas2r_lock_set_flags(&a->flags2, 251 if (!test_and_set_bit(AF2_DEV_SCAN, &a->flags2)) {
257 AF2_DEV_SCAN) &
258 ilog2(AF2_DEV_SCAN))) {
259 spin_lock_irqsave(&a->mem_lock, flags); 252 spin_lock_irqsave(&a->mem_lock, flags);
260 esas2r_disc_queue_event(a, DCDE_DEV_SCAN); 253 esas2r_disc_queue_event(a, DCDE_DEV_SCAN);
261 spin_unlock_irqrestore(&a->mem_lock, flags); 254 spin_unlock_irqrestore(&a->mem_lock, flags);
@@ -265,8 +258,8 @@ void esas2r_disc_check_complete(struct esas2r_adapter *a)
265 /* We want to stop waiting for devices. */ 258 /* We want to stop waiting for devices. */
266 a->disc_wait_time = 0; 259 a->disc_wait_time = 0;
267 260
268 if ((a->flags & AF_DISC_POLLED) 261 if (test_bit(AF_DISC_POLLED, &a->flags) &&
269 && (a->flags & AF_DISC_IN_PROG)) { 262 test_bit(AF_DISC_IN_PROG, &a->flags)) {
270 /* 263 /*
271 * Polled discovery is still pending so continue the active 264 * Polled discovery is still pending so continue the active
272 * discovery until it is done. At that point, we will stop 265 * discovery until it is done. At that point, we will stop
@@ -280,14 +273,14 @@ void esas2r_disc_check_complete(struct esas2r_adapter *a)
280 * driven; i.e. There is no transition. 273 * driven; i.e. There is no transition.
281 */ 274 */
282 esas2r_disc_fix_curr_requests(a); 275 esas2r_disc_fix_curr_requests(a);
283 esas2r_lock_clear_flags(&a->flags, AF_DISC_PENDING); 276 clear_bit(AF_DISC_PENDING, &a->flags);
284 277
285 /* 278 /*
286 * We have deferred target state changes until now because we 279 * We have deferred target state changes until now because we
287 * don't want to report any removals (due to the first arrival) 280 * don't want to report any removals (due to the first arrival)
288 * until the device wait time expires. 281 * until the device wait time expires.
289 */ 282 */
290 esas2r_lock_set_flags(&a->flags, AF_PORT_CHANGE); 283 set_bit(AF_PORT_CHANGE, &a->flags);
291 } 284 }
292 285
293 esas2r_trace_exit(); 286 esas2r_trace_exit();
@@ -308,7 +301,8 @@ void esas2r_disc_queue_event(struct esas2r_adapter *a, u8 disc_evt)
308 * Don't start discovery before or during polled discovery. if we did, 301 * Don't start discovery before or during polled discovery. if we did,
309 * we would have a deadlock if we are in the ISR already. 302 * we would have a deadlock if we are in the ISR already.
310 */ 303 */
311 if (!(a->flags & (AF_CHPRST_PENDING | AF_DISC_POLLED))) 304 if (!test_bit(AF_CHPRST_PENDING, &a->flags) &&
305 !test_bit(AF_DISC_POLLED, &a->flags))
312 esas2r_disc_start_port(a); 306 esas2r_disc_start_port(a);
313 307
314 esas2r_trace_exit(); 308 esas2r_trace_exit();
@@ -322,7 +316,7 @@ bool esas2r_disc_start_port(struct esas2r_adapter *a)
322 316
323 esas2r_trace_enter(); 317 esas2r_trace_enter();
324 318
325 if (a->flags & AF_DISC_IN_PROG) { 319 if (test_bit(AF_DISC_IN_PROG, &a->flags)) {
326 esas2r_trace_exit(); 320 esas2r_trace_exit();
327 321
328 return false; 322 return false;
@@ -330,7 +324,7 @@ bool esas2r_disc_start_port(struct esas2r_adapter *a)
330 324
331 /* If there is a discovery waiting, process it. */ 325 /* If there is a discovery waiting, process it. */
332 if (dc->disc_evt) { 326 if (dc->disc_evt) {
333 if ((a->flags & AF_DISC_POLLED) 327 if (test_bit(AF_DISC_POLLED, &a->flags)
334 && a->disc_wait_time == 0) { 328 && a->disc_wait_time == 0) {
335 /* 329 /*
336 * We are doing polled discovery, but we no longer want 330 * We are doing polled discovery, but we no longer want
@@ -347,7 +341,7 @@ bool esas2r_disc_start_port(struct esas2r_adapter *a)
347 341
348 esas2r_hdebug("disc done"); 342 esas2r_hdebug("disc done");
349 343
350 esas2r_lock_set_flags(&a->flags, AF_PORT_CHANGE); 344 set_bit(AF_PORT_CHANGE, &a->flags);
351 345
352 esas2r_trace_exit(); 346 esas2r_trace_exit();
353 347
@@ -356,10 +350,10 @@ bool esas2r_disc_start_port(struct esas2r_adapter *a)
356 350
357 /* Handle the discovery context */ 351 /* Handle the discovery context */
358 esas2r_trace("disc_evt: %d", dc->disc_evt); 352 esas2r_trace("disc_evt: %d", dc->disc_evt);
359 esas2r_lock_set_flags(&a->flags, AF_DISC_IN_PROG); 353 set_bit(AF_DISC_IN_PROG, &a->flags);
360 dc->flags = 0; 354 dc->flags = 0;
361 355
362 if (a->flags & AF_DISC_POLLED) 356 if (test_bit(AF_DISC_POLLED, &a->flags))
363 dc->flags |= DCF_POLLED; 357 dc->flags |= DCF_POLLED;
364 358
365 rq->interrupt_cx = dc; 359 rq->interrupt_cx = dc;
@@ -379,7 +373,7 @@ bool esas2r_disc_start_port(struct esas2r_adapter *a)
379 } 373 }
380 374
381 /* Continue interrupt driven discovery */ 375 /* Continue interrupt driven discovery */
382 if (!(a->flags & AF_DISC_POLLED)) 376 if (!test_bit(AF_DISC_POLLED, &a->flags))
383 ret = esas2r_disc_continue(a, rq); 377 ret = esas2r_disc_continue(a, rq);
384 else 378 else
385 ret = true; 379 ret = true;
@@ -453,10 +447,10 @@ static bool esas2r_disc_continue(struct esas2r_adapter *a,
453 /* Discovery is done...for now. */ 447 /* Discovery is done...for now. */
454 rq->interrupt_cx = NULL; 448 rq->interrupt_cx = NULL;
455 449
456 if (!(a->flags & AF_DISC_PENDING)) 450 if (!test_bit(AF_DISC_PENDING, &a->flags))
457 esas2r_disc_fix_curr_requests(a); 451 esas2r_disc_fix_curr_requests(a);
458 452
459 esas2r_lock_clear_flags(&a->flags, AF_DISC_IN_PROG); 453 clear_bit(AF_DISC_IN_PROG, &a->flags);
460 454
461 /* Start the next discovery. */ 455 /* Start the next discovery. */
462 return esas2r_disc_start_port(a); 456 return esas2r_disc_start_port(a);
@@ -480,7 +474,8 @@ static bool esas2r_disc_start_request(struct esas2r_adapter *a,
480 474
481 spin_lock_irqsave(&a->queue_lock, flags); 475 spin_lock_irqsave(&a->queue_lock, flags);
482 476
483 if (!(a->flags & (AF_CHPRST_PENDING | AF_FLASHING))) 477 if (!test_bit(AF_CHPRST_PENDING, &a->flags) &&
478 !test_bit(AF_FLASHING, &a->flags))
484 esas2r_disc_local_start_request(a, rq); 479 esas2r_disc_local_start_request(a, rq);
485 else 480 else
486 list_add_tail(&rq->req_list, &a->defer_list); 481 list_add_tail(&rq->req_list, &a->defer_list);
diff --git a/drivers/scsi/esas2r/esas2r_flash.c b/drivers/scsi/esas2r/esas2r_flash.c
index 2ec3c23275b8..b7dc59fca7a6 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -231,7 +231,7 @@ static bool load_image(struct esas2r_adapter *a, struct esas2r_request *rq)
231 * RS_PENDING, FM API tasks will continue. 231 * RS_PENDING, FM API tasks will continue.
232 */ 232 */
233 rq->req_stat = RS_PENDING; 233 rq->req_stat = RS_PENDING;
234 if (a->flags & AF_DEGRADED_MODE) 234 if (test_bit(AF_DEGRADED_MODE, &a->flags))
235 /* not suppported for now */; 235 /* not suppported for now */;
236 else 236 else
237 build_flash_msg(a, rq); 237 build_flash_msg(a, rq);
@@ -315,7 +315,7 @@ static bool complete_fmapi_req(struct esas2r_adapter *a,
315 memset(fc->scratch, 0, FM_BUF_SZ); 315 memset(fc->scratch, 0, FM_BUF_SZ);
316 316
317 esas2r_enable_heartbeat(a); 317 esas2r_enable_heartbeat(a);
318 esas2r_lock_clear_flags(&a->flags, AF_FLASH_LOCK); 318 clear_bit(AF_FLASH_LOCK, &a->flags);
319 return false; 319 return false;
320} 320}
321 321
@@ -526,7 +526,7 @@ no_cfg:
526 * The download is complete. If in degraded mode, 526 * The download is complete. If in degraded mode,
527 * attempt a chip reset. 527 * attempt a chip reset.
528 */ 528 */
529 if (a->flags & AF_DEGRADED_MODE) 529 if (test_bit(AF_DEGRADED_MODE, &a->flags))
530 esas2r_local_reset_adapter(a); 530 esas2r_local_reset_adapter(a);
531 531
532 a->flash_ver = fi->cmp_hdr[CH_IT_BIOS].version; 532 a->flash_ver = fi->cmp_hdr[CH_IT_BIOS].version;
@@ -890,7 +890,7 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
890 } 890 }
891 } 891 }
892 892
893 if (a->flags & AF_DEGRADED_MODE) { 893 if (test_bit(AF_DEGRADED_MODE, &a->flags)) {
894 fs->status = ATTO_STS_DEGRADED; 894 fs->status = ATTO_STS_DEGRADED;
895 return false; 895 return false;
896 } 896 }
@@ -945,8 +945,12 @@ static bool esas2r_flash_access(struct esas2r_adapter *a, u32 function)
945 945
946 /* Now wait for the firmware to process it */ 946 /* Now wait for the firmware to process it */
947 starttime = jiffies_to_msecs(jiffies); 947 starttime = jiffies_to_msecs(jiffies);
948 timeout = a->flags & 948
949 (AF_CHPRST_PENDING | AF_DISC_PENDING) ? 40000 : 5000; 949 if (test_bit(AF_CHPRST_PENDING, &a->flags) ||
950 test_bit(AF_DISC_PENDING, &a->flags))
951 timeout = 40000;
952 else
953 timeout = 5000;
950 954
951 while (true) { 955 while (true) {
952 intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT); 956 intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
@@ -1008,7 +1012,7 @@ bool esas2r_read_flash_block(struct esas2r_adapter *a,
1008 u32 offset; 1012 u32 offset;
1009 u32 iatvr; 1013 u32 iatvr;
1010 1014
1011 if (a->flags2 & AF2_SERIAL_FLASH) 1015 if (test_bit(AF2_SERIAL_FLASH, &a->flags2))
1012 iatvr = MW_DATA_ADDR_SER_FLASH + (from & -WINDOW_SIZE); 1016 iatvr = MW_DATA_ADDR_SER_FLASH + (from & -WINDOW_SIZE);
1013 else 1017 else
1014 iatvr = MW_DATA_ADDR_PAR_FLASH + (from & -WINDOW_SIZE); 1018 iatvr = MW_DATA_ADDR_PAR_FLASH + (from & -WINDOW_SIZE);
@@ -1236,9 +1240,9 @@ static void esas2r_nvram_callback(struct esas2r_adapter *a,
1236 if (rq->req_stat != RS_PENDING) { 1240 if (rq->req_stat != RS_PENDING) {
1237 /* update the NVRAM state */ 1241 /* update the NVRAM state */
1238 if (rq->req_stat == RS_SUCCESS) 1242 if (rq->req_stat == RS_SUCCESS)
1239 esas2r_lock_set_flags(&a->flags, AF_NVR_VALID); 1243 set_bit(AF_NVR_VALID, &a->flags);
1240 else 1244 else
1241 esas2r_lock_clear_flags(&a->flags, AF_NVR_VALID); 1245 clear_bit(AF_NVR_VALID, &a->flags);
1242 1246
1243 esas2r_enable_heartbeat(a); 1247 esas2r_enable_heartbeat(a);
1244 1248
@@ -1258,7 +1262,7 @@ bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
1258 u32 *sas_address_dwords = (u32 *)&sas_address_bytes[0]; 1262 u32 *sas_address_dwords = (u32 *)&sas_address_bytes[0];
1259 struct atto_vda_flash_req *vrq = &rq->vrq->flash; 1263 struct atto_vda_flash_req *vrq = &rq->vrq->flash;
1260 1264
1261 if (a->flags & AF_DEGRADED_MODE) 1265 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1262 return false; 1266 return false;
1263 1267
1264 if (down_interruptible(&a->nvram_semaphore)) 1268 if (down_interruptible(&a->nvram_semaphore))
@@ -1302,7 +1306,7 @@ bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
1302 FLS_OFFSET_NVR, 1306 FLS_OFFSET_NVR,
1303 sizeof(struct esas2r_sas_nvram)); 1307 sizeof(struct esas2r_sas_nvram));
1304 1308
1305 if (a->flags & AF_LEGACY_SGE_MODE) { 1309 if (test_bit(AF_LEGACY_SGE_MODE, &a->flags)) {
1306 1310
1307 vrq->data.sge[0].length = 1311 vrq->data.sge[0].length =
1308 cpu_to_le32(SGE_LAST | 1312 cpu_to_le32(SGE_LAST |
@@ -1337,7 +1341,7 @@ bool esas2r_nvram_validate(struct esas2r_adapter *a)
1337 } else if (n->version > SASNVR_VERSION) { 1341 } else if (n->version > SASNVR_VERSION) {
1338 esas2r_hdebug("invalid NVRAM version"); 1342 esas2r_hdebug("invalid NVRAM version");
1339 } else { 1343 } else {
1340 esas2r_lock_set_flags(&a->flags, AF_NVR_VALID); 1344 set_bit(AF_NVR_VALID, &a->flags);
1341 rslt = true; 1345 rslt = true;
1342 } 1346 }
1343 1347
@@ -1359,7 +1363,7 @@ void esas2r_nvram_set_defaults(struct esas2r_adapter *a)
1359 struct esas2r_sas_nvram *n = a->nvram; 1363 struct esas2r_sas_nvram *n = a->nvram;
1360 u32 time = jiffies_to_msecs(jiffies); 1364 u32 time = jiffies_to_msecs(jiffies);
1361 1365
1362 esas2r_lock_clear_flags(&a->flags, AF_NVR_VALID); 1366 clear_bit(AF_NVR_VALID, &a->flags);
1363 *n = default_sas_nvram; 1367 *n = default_sas_nvram;
1364 n->sas_addr[3] |= 0x0F; 1368 n->sas_addr[3] |= 0x0F;
1365 n->sas_addr[4] = HIBYTE(LOWORD(time)); 1369 n->sas_addr[4] = HIBYTE(LOWORD(time));
@@ -1389,7 +1393,7 @@ bool esas2r_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi,
1389 u8 j; 1393 u8 j;
1390 struct esas2r_component_header *ch; 1394 struct esas2r_component_header *ch;
1391 1395
1392 if (esas2r_lock_set_flags(&a->flags, AF_FLASH_LOCK) & AF_FLASH_LOCK) { 1396 if (test_and_set_bit(AF_FLASH_LOCK, &a->flags)) {
1393 /* flag was already set */ 1397 /* flag was already set */
1394 fi->status = FI_STAT_BUSY; 1398 fi->status = FI_STAT_BUSY;
1395 return false; 1399 return false;
@@ -1413,7 +1417,7 @@ bool esas2r_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi,
1413 return complete_fmapi_req(a, rq, FI_STAT_IMG_VER); 1417 return complete_fmapi_req(a, rq, FI_STAT_IMG_VER);
1414 } 1418 }
1415 1419
1416 if (a->flags & AF_DEGRADED_MODE) 1420 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1417 return complete_fmapi_req(a, rq, FI_STAT_DEGRADED); 1421 return complete_fmapi_req(a, rq, FI_STAT_DEGRADED);
1418 1422
1419 switch (fi->action) { 1423 switch (fi->action) {
diff --git a/drivers/scsi/esas2r/esas2r_init.c b/drivers/scsi/esas2r/esas2r_init.c
index da1869df2408..15d222b407f6 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -216,7 +216,7 @@ use_legacy_interrupts:
216 goto use_legacy_interrupts; 216 goto use_legacy_interrupts;
217 } 217 }
218 a->intr_mode = INTR_MODE_MSI; 218 a->intr_mode = INTR_MODE_MSI;
219 esas2r_lock_set_flags(&a->flags2, AF2_MSI_ENABLED); 219 set_bit(AF2_MSI_ENABLED, &a->flags2);
220 break; 220 break;
221 221
222 222
@@ -252,7 +252,7 @@ static void esas2r_claim_interrupts(struct esas2r_adapter *a)
252 return; 252 return;
253 } 253 }
254 254
255 esas2r_lock_set_flags(&a->flags2, AF2_IRQ_CLAIMED); 255 set_bit(AF2_IRQ_CLAIMED, &a->flags2);
256 esas2r_log(ESAS2R_LOG_INFO, 256 esas2r_log(ESAS2R_LOG_INFO,
257 "claimed IRQ %d flags: 0x%lx", 257 "claimed IRQ %d flags: 0x%lx",
258 a->pcid->irq, flags); 258 a->pcid->irq, flags);
@@ -380,10 +380,10 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
380 /* interrupts will be disabled until we are done with init */ 380 /* interrupts will be disabled until we are done with init */
381 atomic_inc(&a->dis_ints_cnt); 381 atomic_inc(&a->dis_ints_cnt);
382 atomic_inc(&a->disable_cnt); 382 atomic_inc(&a->disable_cnt);
383 a->flags |= AF_CHPRST_PENDING 383 set_bit(AF_CHPRST_PENDING, &a->flags);
384 | AF_DISC_PENDING 384 set_bit(AF_DISC_PENDING, &a->flags);
385 | AF_FIRST_INIT 385 set_bit(AF_FIRST_INIT, &a->flags);
386 | AF_LEGACY_SGE_MODE; 386 set_bit(AF_LEGACY_SGE_MODE, &a->flags);
387 387
388 a->init_msg = ESAS2R_INIT_MSG_START; 388 a->init_msg = ESAS2R_INIT_MSG_START;
389 a->max_vdareq_size = 128; 389 a->max_vdareq_size = 128;
@@ -440,11 +440,11 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
440 440
441 esas2r_claim_interrupts(a); 441 esas2r_claim_interrupts(a);
442 442
443 if (a->flags2 & AF2_IRQ_CLAIMED) 443 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2))
444 esas2r_enable_chip_interrupts(a); 444 esas2r_enable_chip_interrupts(a);
445 445
446 esas2r_lock_set_flags(&a->flags2, AF2_INIT_DONE); 446 set_bit(AF2_INIT_DONE, &a->flags2);
447 if (!(a->flags & AF_DEGRADED_MODE)) 447 if (!test_bit(AF_DEGRADED_MODE, &a->flags))
448 esas2r_kickoff_timer(a); 448 esas2r_kickoff_timer(a);
449 esas2r_debug("esas2r_init_adapter done for %p (%d)", 449 esas2r_debug("esas2r_init_adapter done for %p (%d)",
450 a, a->disable_cnt); 450 a, a->disable_cnt);
@@ -457,8 +457,8 @@ static void esas2r_adapter_power_down(struct esas2r_adapter *a,
457{ 457{
458 struct esas2r_mem_desc *memdesc, *next; 458 struct esas2r_mem_desc *memdesc, *next;
459 459
460 if ((a->flags2 & AF2_INIT_DONE) 460 if ((test_bit(AF2_INIT_DONE, &a->flags2))
461 && (!(a->flags & AF_DEGRADED_MODE))) { 461 && (!test_bit(AF_DEGRADED_MODE, &a->flags))) {
462 if (!power_management) { 462 if (!power_management) {
463 del_timer_sync(&a->timer); 463 del_timer_sync(&a->timer);
464 tasklet_kill(&a->tasklet); 464 tasklet_kill(&a->tasklet);
@@ -508,19 +508,19 @@ static void esas2r_adapter_power_down(struct esas2r_adapter *a,
508 } 508 }
509 509
510 /* Clean up interrupts */ 510 /* Clean up interrupts */
511 if (a->flags2 & AF2_IRQ_CLAIMED) { 511 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2)) {
512 esas2r_log_dev(ESAS2R_LOG_INFO, 512 esas2r_log_dev(ESAS2R_LOG_INFO,
513 &(a->pcid->dev), 513 &(a->pcid->dev),
514 "free_irq(%d) called", a->pcid->irq); 514 "free_irq(%d) called", a->pcid->irq);
515 515
516 free_irq(a->pcid->irq, a); 516 free_irq(a->pcid->irq, a);
517 esas2r_debug("IRQ released"); 517 esas2r_debug("IRQ released");
518 esas2r_lock_clear_flags(&a->flags2, AF2_IRQ_CLAIMED); 518 clear_bit(AF2_IRQ_CLAIMED, &a->flags2);
519 } 519 }
520 520
521 if (a->flags2 & AF2_MSI_ENABLED) { 521 if (test_bit(AF2_MSI_ENABLED, &a->flags2)) {
522 pci_disable_msi(a->pcid); 522 pci_disable_msi(a->pcid);
523 esas2r_lock_clear_flags(&a->flags2, AF2_MSI_ENABLED); 523 clear_bit(AF2_MSI_ENABLED, &a->flags2);
524 esas2r_debug("MSI disabled"); 524 esas2r_debug("MSI disabled");
525 } 525 }
526 526
@@ -641,12 +641,10 @@ void esas2r_kill_adapter(int i)
641 pci_set_drvdata(a->pcid, NULL); 641 pci_set_drvdata(a->pcid, NULL);
642 esas2r_adapters[i] = NULL; 642 esas2r_adapters[i] = NULL;
643 643
644 if (a->flags2 & AF2_INIT_DONE) { 644 if (test_bit(AF2_INIT_DONE, &a->flags2)) {
645 esas2r_lock_clear_flags(&a->flags2, 645 clear_bit(AF2_INIT_DONE, &a->flags2);
646 AF2_INIT_DONE);
647 646
648 esas2r_lock_set_flags(&a->flags, 647 set_bit(AF_DEGRADED_MODE, &a->flags);
649 AF_DEGRADED_MODE);
650 648
651 esas2r_log_dev(ESAS2R_LOG_INFO, 649 esas2r_log_dev(ESAS2R_LOG_INFO,
652 &(a->host->shost_gendev), 650 &(a->host->shost_gendev),
@@ -759,7 +757,7 @@ int esas2r_resume(struct pci_dev *pdev)
759 757
760 esas2r_claim_interrupts(a); 758 esas2r_claim_interrupts(a);
761 759
762 if (a->flags2 & AF2_IRQ_CLAIMED) { 760 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2)) {
763 /* 761 /*
764 * Now that system interrupt(s) are claimed, we can enable 762 * Now that system interrupt(s) are claimed, we can enable
765 * chip interrupts. 763 * chip interrupts.
@@ -781,7 +779,7 @@ error_exit:
781 779
782bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str) 780bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str)
783{ 781{
784 esas2r_lock_set_flags(&a->flags, AF_DEGRADED_MODE); 782 set_bit(AF_DEGRADED_MODE, &a->flags);
785 esas2r_log(ESAS2R_LOG_CRIT, 783 esas2r_log(ESAS2R_LOG_CRIT,
786 "setting adapter to degraded mode: %s\n", error_str); 784 "setting adapter to degraded mode: %s\n", error_str);
787 return false; 785 return false;
@@ -896,7 +894,7 @@ bool esas2r_init_adapter_struct(struct esas2r_adapter *a,
896 && (a->pcid->subsystem_device & ATTO_SSDID_TBT)) 894 && (a->pcid->subsystem_device & ATTO_SSDID_TBT))
897 a->flags2 |= AF2_THUNDERBOLT; 895 a->flags2 |= AF2_THUNDERBOLT;
898 896
899 if (a->flags2 & AF2_THUNDERBOLT) 897 if (test_bit(AF2_THUNDERBOLT, &a->flags2))
900 a->flags2 |= AF2_SERIAL_FLASH; 898 a->flags2 |= AF2_SERIAL_FLASH;
901 899
902 if (a->pcid->subsystem_device == ATTO_TLSH_1068) 900 if (a->pcid->subsystem_device == ATTO_TLSH_1068)
@@ -956,14 +954,14 @@ bool esas2r_init_adapter_struct(struct esas2r_adapter *a,
956 a->outbound_copy = (u32 volatile *)high; 954 a->outbound_copy = (u32 volatile *)high;
957 high += sizeof(u32); 955 high += sizeof(u32);
958 956
959 if (!(a->flags & AF_NVR_VALID)) 957 if (!test_bit(AF_NVR_VALID, &a->flags))
960 esas2r_nvram_set_defaults(a); 958 esas2r_nvram_set_defaults(a);
961 959
962 /* update the caller's uncached memory area pointer */ 960 /* update the caller's uncached memory area pointer */
963 *uncached_area = (void *)high; 961 *uncached_area = (void *)high;
964 962
965 /* initialize the allocated memory */ 963 /* initialize the allocated memory */
966 if (a->flags & AF_FIRST_INIT) { 964 if (test_bit(AF_FIRST_INIT, &a->flags)) {
967 memset(a->req_table, 0, 965 memset(a->req_table, 0,
968 (num_requests + num_ae_requests + 966 (num_requests + num_ae_requests +
969 1) * sizeof(struct esas2r_request *)); 967 1) * sizeof(struct esas2r_request *));
@@ -1019,7 +1017,7 @@ bool esas2r_check_adapter(struct esas2r_adapter *a)
1019 * if the chip reset detected flag is set, we can bypass a bunch of 1017 * if the chip reset detected flag is set, we can bypass a bunch of
1020 * stuff. 1018 * stuff.
1021 */ 1019 */
1022 if (a->flags & AF_CHPRST_DETECTED) 1020 if (test_bit(AF_CHPRST_DETECTED, &a->flags))
1023 goto skip_chip_reset; 1021 goto skip_chip_reset;
1024 1022
1025 /* 1023 /*
@@ -1057,14 +1055,12 @@ bool esas2r_check_adapter(struct esas2r_adapter *a)
1057 doorbell); 1055 doorbell);
1058 1056
1059 if (ver == DRBL_FW_VER_0) { 1057 if (ver == DRBL_FW_VER_0) {
1060 esas2r_lock_set_flags(&a->flags, 1058 set_bit(AF_LEGACY_SGE_MODE, &a->flags);
1061 AF_LEGACY_SGE_MODE);
1062 1059
1063 a->max_vdareq_size = 128; 1060 a->max_vdareq_size = 128;
1064 a->build_sgl = esas2r_build_sg_list_sge; 1061 a->build_sgl = esas2r_build_sg_list_sge;
1065 } else if (ver == DRBL_FW_VER_1) { 1062 } else if (ver == DRBL_FW_VER_1) {
1066 esas2r_lock_clear_flags(&a->flags, 1063 clear_bit(AF_LEGACY_SGE_MODE, &a->flags);
1067 AF_LEGACY_SGE_MODE);
1068 1064
1069 a->max_vdareq_size = 1024; 1065 a->max_vdareq_size = 1024;
1070 a->build_sgl = esas2r_build_sg_list_prd; 1066 a->build_sgl = esas2r_build_sg_list_prd;
@@ -1139,7 +1135,7 @@ skip_chip_reset:
1139 *a->outbound_copy = 1135 *a->outbound_copy =
1140 a->last_write = 1136 a->last_write =
1141 a->last_read = a->list_size - 1; 1137 a->last_read = a->list_size - 1;
1142 esas2r_lock_set_flags(&a->flags, AF_COMM_LIST_TOGGLE); 1138 set_bit(AF_COMM_LIST_TOGGLE, &a->flags);
1143 esas2r_write_register_dword(a, MU_IN_LIST_WRITE, MU_ILW_TOGGLE | 1139 esas2r_write_register_dword(a, MU_IN_LIST_WRITE, MU_ILW_TOGGLE |
1144 a->last_write); 1140 a->last_write);
1145 esas2r_write_register_dword(a, MU_OUT_LIST_COPY, MU_OLC_TOGGLE | 1141 esas2r_write_register_dword(a, MU_OUT_LIST_COPY, MU_OLC_TOGGLE |
@@ -1204,9 +1200,9 @@ skip_chip_reset:
1204 */ 1200 */
1205 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_IN_ENB); 1201 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_IN_ENB);
1206 if (doorbell & DRBL_POWER_DOWN) 1202 if (doorbell & DRBL_POWER_DOWN)
1207 esas2r_lock_set_flags(&a->flags2, AF2_VDA_POWER_DOWN); 1203 set_bit(AF2_VDA_POWER_DOWN, &a->flags2);
1208 else 1204 else
1209 esas2r_lock_clear_flags(&a->flags2, AF2_VDA_POWER_DOWN); 1205 clear_bit(AF2_VDA_POWER_DOWN, &a->flags2);
1210 1206
1211 /* 1207 /*
1212 * enable assertion of outbound queue and doorbell interrupts in the 1208 * enable assertion of outbound queue and doorbell interrupts in the
@@ -1266,9 +1262,8 @@ static bool esas2r_format_init_msg(struct esas2r_adapter *a,
1266 * unsupported config requests correctly. 1262 * unsupported config requests correctly.
1267 */ 1263 */
1268 1264
1269 if ((a->flags2 & AF2_THUNDERBOLT) 1265 if ((test_bit(AF2_THUNDERBOLT, &a->flags2))
1270 || (be32_to_cpu(a->fw_version) > 1266 || (be32_to_cpu(a->fw_version) > 0x00524702)) {
1271 be32_to_cpu(0x47020052))) {
1272 esas2r_hdebug("CFG get init"); 1267 esas2r_hdebug("CFG get init");
1273 esas2r_build_cfg_req(a, 1268 esas2r_build_cfg_req(a,
1274 rq, 1269 rq,
@@ -1361,10 +1356,10 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1361 struct esas2r_request *rq; 1356 struct esas2r_request *rq;
1362 u32 i; 1357 u32 i;
1363 1358
1364 if (a->flags & AF_DEGRADED_MODE) 1359 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1365 goto exit; 1360 goto exit;
1366 1361
1367 if (!(a->flags & AF_NVR_VALID)) { 1362 if (!test_bit(AF_NVR_VALID, &a->flags)) {
1368 if (!esas2r_nvram_read_direct(a)) 1363 if (!esas2r_nvram_read_direct(a))
1369 esas2r_log(ESAS2R_LOG_WARN, 1364 esas2r_log(ESAS2R_LOG_WARN,
1370 "invalid/missing NVRAM parameters"); 1365 "invalid/missing NVRAM parameters");
@@ -1376,8 +1371,8 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1376 } 1371 }
1377 1372
1378 /* The firmware is ready. */ 1373 /* The firmware is ready. */
1379 esas2r_lock_clear_flags(&a->flags, AF_DEGRADED_MODE); 1374 clear_bit(AF_DEGRADED_MODE, &a->flags);
1380 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_PENDING); 1375 clear_bit(AF_CHPRST_PENDING, &a->flags);
1381 1376
1382 /* Post all the async event requests */ 1377 /* Post all the async event requests */
1383 for (i = 0, rq = a->first_ae_req; i < num_ae_requests; i++, rq++) 1378 for (i = 0, rq = a->first_ae_req; i < num_ae_requests; i++, rq++)
@@ -1398,8 +1393,8 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1398 1393
1399 esas2r_hdebug("firmware revision: %s", a->fw_rev); 1394 esas2r_hdebug("firmware revision: %s", a->fw_rev);
1400 1395
1401 if ((a->flags & AF_CHPRST_DETECTED) 1396 if (test_bit(AF_CHPRST_DETECTED, &a->flags)
1402 && (a->flags & AF_FIRST_INIT)) { 1397 && (test_bit(AF_FIRST_INIT, &a->flags))) {
1403 esas2r_enable_chip_interrupts(a); 1398 esas2r_enable_chip_interrupts(a);
1404 return true; 1399 return true;
1405 } 1400 }
@@ -1423,18 +1418,18 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1423 * Block Tasklets from getting scheduled and indicate this is 1418 * Block Tasklets from getting scheduled and indicate this is
1424 * polled discovery. 1419 * polled discovery.
1425 */ 1420 */
1426 esas2r_lock_set_flags(&a->flags, AF_TASKLET_SCHEDULED); 1421 set_bit(AF_TASKLET_SCHEDULED, &a->flags);
1427 esas2r_lock_set_flags(&a->flags, AF_DISC_POLLED); 1422 set_bit(AF_DISC_POLLED, &a->flags);
1428 1423
1429 /* 1424 /*
1430 * Temporarily bring the disable count to zero to enable 1425 * Temporarily bring the disable count to zero to enable
1431 * deferred processing. Note that the count is already zero 1426 * deferred processing. Note that the count is already zero
1432 * after the first initialization. 1427 * after the first initialization.
1433 */ 1428 */
1434 if (a->flags & AF_FIRST_INIT) 1429 if (test_bit(AF_FIRST_INIT, &a->flags))
1435 atomic_dec(&a->disable_cnt); 1430 atomic_dec(&a->disable_cnt);
1436 1431
1437 while (a->flags & AF_DISC_PENDING) { 1432 while (test_bit(AF_DISC_PENDING, &a->flags)) {
1438 schedule_timeout_interruptible(msecs_to_jiffies(100)); 1433 schedule_timeout_interruptible(msecs_to_jiffies(100));
1439 1434
1440 /* 1435 /*
@@ -1453,7 +1448,7 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1453 * we have to make sure the timer tick processes the 1448 * we have to make sure the timer tick processes the
1454 * doorbell indicating the firmware is ready. 1449 * doorbell indicating the firmware is ready.
1455 */ 1450 */
1456 if (!(a->flags & AF_CHPRST_PENDING)) 1451 if (!test_bit(AF_CHPRST_PENDING, &a->flags))
1457 esas2r_disc_check_for_work(a); 1452 esas2r_disc_check_for_work(a);
1458 1453
1459 /* Simulate a timer tick. */ 1454 /* Simulate a timer tick. */
@@ -1473,11 +1468,11 @@ bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll)
1473 1468
1474 } 1469 }
1475 1470
1476 if (a->flags & AF_FIRST_INIT) 1471 if (test_bit(AF_FIRST_INIT, &a->flags))
1477 atomic_inc(&a->disable_cnt); 1472 atomic_inc(&a->disable_cnt);
1478 1473
1479 esas2r_lock_clear_flags(&a->flags, AF_DISC_POLLED); 1474 clear_bit(AF_DISC_POLLED, &a->flags);
1480 esas2r_lock_clear_flags(&a->flags, AF_TASKLET_SCHEDULED); 1475 clear_bit(AF_TASKLET_SCHEDULED, &a->flags);
1481 } 1476 }
1482 1477
1483 1478
@@ -1504,26 +1499,26 @@ exit:
1504 * need to get done before we exit. 1499 * need to get done before we exit.
1505 */ 1500 */
1506 1501
1507 if ((a->flags & AF_CHPRST_DETECTED) 1502 if (test_bit(AF_CHPRST_DETECTED, &a->flags) &&
1508 && (a->flags & AF_FIRST_INIT)) { 1503 test_bit(AF_FIRST_INIT, &a->flags)) {
1509 /* 1504 /*
1510 * Reinitialization was performed during the first 1505 * Reinitialization was performed during the first
1511 * initialization. Only clear the chip reset flag so the 1506 * initialization. Only clear the chip reset flag so the
1512 * original device polling is not cancelled. 1507 * original device polling is not cancelled.
1513 */ 1508 */
1514 if (!rslt) 1509 if (!rslt)
1515 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_PENDING); 1510 clear_bit(AF_CHPRST_PENDING, &a->flags);
1516 } else { 1511 } else {
1517 /* First initialization or a subsequent re-init is complete. */ 1512 /* First initialization or a subsequent re-init is complete. */
1518 if (!rslt) { 1513 if (!rslt) {
1519 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_PENDING); 1514 clear_bit(AF_CHPRST_PENDING, &a->flags);
1520 esas2r_lock_clear_flags(&a->flags, AF_DISC_PENDING); 1515 clear_bit(AF_DISC_PENDING, &a->flags);
1521 } 1516 }
1522 1517
1523 1518
1524 /* Enable deferred processing after the first initialization. */ 1519 /* Enable deferred processing after the first initialization. */
1525 if (a->flags & AF_FIRST_INIT) { 1520 if (test_bit(AF_FIRST_INIT, &a->flags)) {
1526 esas2r_lock_clear_flags(&a->flags, AF_FIRST_INIT); 1521 clear_bit(AF_FIRST_INIT, &a->flags);
1527 1522
1528 if (atomic_dec_return(&a->disable_cnt) == 0) 1523 if (atomic_dec_return(&a->disable_cnt) == 0)
1529 esas2r_do_deferred_processes(a); 1524 esas2r_do_deferred_processes(a);
@@ -1535,7 +1530,7 @@ exit:
1535 1530
1536void esas2r_reset_adapter(struct esas2r_adapter *a) 1531void esas2r_reset_adapter(struct esas2r_adapter *a)
1537{ 1532{
1538 esas2r_lock_set_flags(&a->flags, AF_OS_RESET); 1533 set_bit(AF_OS_RESET, &a->flags);
1539 esas2r_local_reset_adapter(a); 1534 esas2r_local_reset_adapter(a);
1540 esas2r_schedule_tasklet(a); 1535 esas2r_schedule_tasklet(a);
1541} 1536}
@@ -1550,17 +1545,17 @@ void esas2r_reset_chip(struct esas2r_adapter *a)
1550 * dump is located in the upper 512KB of the onchip SRAM. Make sure 1545 * dump is located in the upper 512KB of the onchip SRAM. Make sure
1551 * to not overwrite a previous crash that was saved. 1546 * to not overwrite a previous crash that was saved.
1552 */ 1547 */
1553 if ((a->flags2 & AF2_COREDUMP_AVAIL) 1548 if (test_bit(AF2_COREDUMP_AVAIL, &a->flags2) &&
1554 && !(a->flags2 & AF2_COREDUMP_SAVED)) { 1549 !test_bit(AF2_COREDUMP_SAVED, &a->flags2)) {
1555 esas2r_read_mem_block(a, 1550 esas2r_read_mem_block(a,
1556 a->fw_coredump_buff, 1551 a->fw_coredump_buff,
1557 MW_DATA_ADDR_SRAM + 0x80000, 1552 MW_DATA_ADDR_SRAM + 0x80000,
1558 ESAS2R_FWCOREDUMP_SZ); 1553 ESAS2R_FWCOREDUMP_SZ);
1559 1554
1560 esas2r_lock_set_flags(&a->flags2, AF2_COREDUMP_SAVED); 1555 set_bit(AF2_COREDUMP_SAVED, &a->flags2);
1561 } 1556 }
1562 1557
1563 esas2r_lock_clear_flags(&a->flags2, AF2_COREDUMP_AVAIL); 1558 clear_bit(AF2_COREDUMP_AVAIL, &a->flags2);
1564 1559
1565 /* Reset the chip */ 1560 /* Reset the chip */
1566 if (a->pcid->revision == MVR_FREY_B2) 1561 if (a->pcid->revision == MVR_FREY_B2)
@@ -1606,10 +1601,10 @@ static void esas2r_power_down_notify_firmware(struct esas2r_adapter *a)
1606 */ 1601 */
1607void esas2r_power_down(struct esas2r_adapter *a) 1602void esas2r_power_down(struct esas2r_adapter *a)
1608{ 1603{
1609 esas2r_lock_set_flags(&a->flags, AF_POWER_MGT); 1604 set_bit(AF_POWER_MGT, &a->flags);
1610 esas2r_lock_set_flags(&a->flags, AF_POWER_DOWN); 1605 set_bit(AF_POWER_DOWN, &a->flags);
1611 1606
1612 if (!(a->flags & AF_DEGRADED_MODE)) { 1607 if (!test_bit(AF_DEGRADED_MODE, &a->flags)) {
1613 u32 starttime; 1608 u32 starttime;
1614 u32 doorbell; 1609 u32 doorbell;
1615 1610
@@ -1649,14 +1644,14 @@ void esas2r_power_down(struct esas2r_adapter *a)
1649 * For versions of firmware that support it tell them the driver 1644 * For versions of firmware that support it tell them the driver
1650 * is powering down. 1645 * is powering down.
1651 */ 1646 */
1652 if (a->flags2 & AF2_VDA_POWER_DOWN) 1647 if (test_bit(AF2_VDA_POWER_DOWN, &a->flags2))
1653 esas2r_power_down_notify_firmware(a); 1648 esas2r_power_down_notify_firmware(a);
1654 } 1649 }
1655 1650
1656 /* Suspend I/O processing. */ 1651 /* Suspend I/O processing. */
1657 esas2r_lock_set_flags(&a->flags, AF_OS_RESET); 1652 set_bit(AF_OS_RESET, &a->flags);
1658 esas2r_lock_set_flags(&a->flags, AF_DISC_PENDING); 1653 set_bit(AF_DISC_PENDING, &a->flags);
1659 esas2r_lock_set_flags(&a->flags, AF_CHPRST_PENDING); 1654 set_bit(AF_CHPRST_PENDING, &a->flags);
1660 1655
1661 esas2r_process_adapter_reset(a); 1656 esas2r_process_adapter_reset(a);
1662 1657
@@ -1673,9 +1668,9 @@ bool esas2r_power_up(struct esas2r_adapter *a, bool init_poll)
1673{ 1668{
1674 bool ret; 1669 bool ret;
1675 1670
1676 esas2r_lock_clear_flags(&a->flags, AF_POWER_DOWN); 1671 clear_bit(AF_POWER_DOWN, &a->flags);
1677 esas2r_init_pci_cfg_space(a); 1672 esas2r_init_pci_cfg_space(a);
1678 esas2r_lock_set_flags(&a->flags, AF_FIRST_INIT); 1673 set_bit(AF_FIRST_INIT, &a->flags);
1679 atomic_inc(&a->disable_cnt); 1674 atomic_inc(&a->disable_cnt);
1680 1675
1681 /* reinitialize the adapter */ 1676 /* reinitialize the adapter */
@@ -1687,17 +1682,17 @@ bool esas2r_power_up(struct esas2r_adapter *a, bool init_poll)
1687 esas2r_send_reset_ae(a, true); 1682 esas2r_send_reset_ae(a, true);
1688 1683
1689 /* clear this flag after initialization. */ 1684 /* clear this flag after initialization. */
1690 esas2r_lock_clear_flags(&a->flags, AF_POWER_MGT); 1685 clear_bit(AF_POWER_MGT, &a->flags);
1691 return ret; 1686 return ret;
1692} 1687}
1693 1688
1694bool esas2r_is_adapter_present(struct esas2r_adapter *a) 1689bool esas2r_is_adapter_present(struct esas2r_adapter *a)
1695{ 1690{
1696 if (a->flags & AF_NOT_PRESENT) 1691 if (test_bit(AF_NOT_PRESENT, &a->flags))
1697 return false; 1692 return false;
1698 1693
1699 if (esas2r_read_register_dword(a, MU_DOORBELL_OUT) == 0xFFFFFFFF) { 1694 if (esas2r_read_register_dword(a, MU_DOORBELL_OUT) == 0xFFFFFFFF) {
1700 esas2r_lock_set_flags(&a->flags, AF_NOT_PRESENT); 1695 set_bit(AF_NOT_PRESENT, &a->flags);
1701 1696
1702 return false; 1697 return false;
1703 } 1698 }
diff --git a/drivers/scsi/esas2r/esas2r_int.c b/drivers/scsi/esas2r/esas2r_int.c
index c2d4ff57c5c3..f16d6bcf9bb6 100644
--- a/drivers/scsi/esas2r/esas2r_int.c
+++ b/drivers/scsi/esas2r/esas2r_int.c
@@ -96,7 +96,7 @@ irqreturn_t esas2r_interrupt(int irq, void *dev_id)
96 if (!esas2r_adapter_interrupt_pending(a)) 96 if (!esas2r_adapter_interrupt_pending(a))
97 return IRQ_NONE; 97 return IRQ_NONE;
98 98
99 esas2r_lock_set_flags(&a->flags2, AF2_INT_PENDING); 99 set_bit(AF2_INT_PENDING, &a->flags2);
100 esas2r_schedule_tasklet(a); 100 esas2r_schedule_tasklet(a);
101 101
102 return IRQ_HANDLED; 102 return IRQ_HANDLED;
@@ -317,9 +317,10 @@ void esas2r_do_deferred_processes(struct esas2r_adapter *a)
317 * = 2 - can start any request 317 * = 2 - can start any request
318 */ 318 */
319 319
320 if (a->flags & (AF_CHPRST_PENDING | AF_FLASHING)) 320 if (test_bit(AF_CHPRST_PENDING, &a->flags) ||
321 test_bit(AF_FLASHING, &a->flags))
321 startreqs = 0; 322 startreqs = 0;
322 else if (a->flags & AF_DISC_PENDING) 323 else if (test_bit(AF_DISC_PENDING, &a->flags))
323 startreqs = 1; 324 startreqs = 1;
324 325
325 atomic_inc(&a->disable_cnt); 326 atomic_inc(&a->disable_cnt);
@@ -367,7 +368,7 @@ void esas2r_do_deferred_processes(struct esas2r_adapter *a)
367 * Flashing could have been set by last local 368 * Flashing could have been set by last local
368 * start 369 * start
369 */ 370 */
370 if (a->flags & AF_FLASHING) 371 if (test_bit(AF_FLASHING, &a->flags))
371 break; 372 break;
372 } 373 }
373 } 374 }
@@ -404,7 +405,7 @@ void esas2r_process_adapter_reset(struct esas2r_adapter *a)
404 405
405 dc->disc_evt = 0; 406 dc->disc_evt = 0;
406 407
407 esas2r_lock_clear_flags(&a->flags, AF_DISC_IN_PROG); 408 clear_bit(AF_DISC_IN_PROG, &a->flags);
408 } 409 }
409 410
410 /* 411 /*
@@ -425,7 +426,7 @@ void esas2r_process_adapter_reset(struct esas2r_adapter *a)
425 a->last_write = 426 a->last_write =
426 a->last_read = a->list_size - 1; 427 a->last_read = a->list_size - 1;
427 428
428 esas2r_lock_set_flags(&a->flags, AF_COMM_LIST_TOGGLE); 429 set_bit(AF_COMM_LIST_TOGGLE, &a->flags);
429 430
430 /* Kill all the requests on the active list */ 431 /* Kill all the requests on the active list */
431 list_for_each(element, &a->defer_list) { 432 list_for_each(element, &a->defer_list) {
@@ -470,7 +471,7 @@ static void esas2r_process_bus_reset(struct esas2r_adapter *a)
470 if (atomic_read(&a->disable_cnt) == 0) 471 if (atomic_read(&a->disable_cnt) == 0)
471 esas2r_do_deferred_processes(a); 472 esas2r_do_deferred_processes(a);
472 473
473 esas2r_lock_clear_flags(&a->flags, AF_OS_RESET); 474 clear_bit(AF_OS_RESET, &a->flags);
474 475
475 esas2r_trace_exit(); 476 esas2r_trace_exit();
476} 477}
@@ -478,10 +479,10 @@ static void esas2r_process_bus_reset(struct esas2r_adapter *a)
478static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a) 479static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
479{ 480{
480 481
481 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_NEEDED); 482 clear_bit(AF_CHPRST_NEEDED, &a->flags);
482 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_NEEDED); 483 clear_bit(AF_BUSRST_NEEDED, &a->flags);
483 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_DETECTED); 484 clear_bit(AF_BUSRST_DETECTED, &a->flags);
484 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_PENDING); 485 clear_bit(AF_BUSRST_PENDING, &a->flags);
485 /* 486 /*
486 * Make sure we don't get attempt more than 3 resets 487 * Make sure we don't get attempt more than 3 resets
487 * when the uptime between resets does not exceed one 488 * when the uptime between resets does not exceed one
@@ -507,10 +508,10 @@ static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
507 * prevent the heartbeat from trying to recover. 508 * prevent the heartbeat from trying to recover.
508 */ 509 */
509 510
510 esas2r_lock_set_flags(&a->flags, AF_DEGRADED_MODE); 511 set_bit(AF_DEGRADED_MODE, &a->flags);
511 esas2r_lock_set_flags(&a->flags, AF_DISABLED); 512 set_bit(AF_DISABLED, &a->flags);
512 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_PENDING); 513 clear_bit(AF_CHPRST_PENDING, &a->flags);
513 esas2r_lock_clear_flags(&a->flags, AF_DISC_PENDING); 514 clear_bit(AF_DISC_PENDING, &a->flags);
514 515
515 esas2r_disable_chip_interrupts(a); 516 esas2r_disable_chip_interrupts(a);
516 a->int_mask = 0; 517 a->int_mask = 0;
@@ -519,18 +520,17 @@ static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
519 esas2r_log(ESAS2R_LOG_CRIT, 520 esas2r_log(ESAS2R_LOG_CRIT,
520 "Adapter disabled because of hardware failure"); 521 "Adapter disabled because of hardware failure");
521 } else { 522 } else {
522 u32 flags = 523 bool alrdyrst = test_and_set_bit(AF_CHPRST_STARTED, &a->flags);
523 esas2r_lock_set_flags(&a->flags, AF_CHPRST_STARTED);
524 524
525 if (!(flags & AF_CHPRST_STARTED)) 525 if (!alrdyrst)
526 /* 526 /*
527 * Only disable interrupts if this is 527 * Only disable interrupts if this is
528 * the first reset attempt. 528 * the first reset attempt.
529 */ 529 */
530 esas2r_disable_chip_interrupts(a); 530 esas2r_disable_chip_interrupts(a);
531 531
532 if ((a->flags & AF_POWER_MGT) && !(a->flags & AF_FIRST_INIT) && 532 if ((test_bit(AF_POWER_MGT, &a->flags)) &&
533 !(flags & AF_CHPRST_STARTED)) { 533 !test_bit(AF_FIRST_INIT, &a->flags) && !alrdyrst) {
534 /* 534 /*
535 * Don't reset the chip on the first 535 * Don't reset the chip on the first
536 * deferred power up attempt. 536 * deferred power up attempt.
@@ -543,10 +543,10 @@ static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
543 /* Kick off the reinitialization */ 543 /* Kick off the reinitialization */
544 a->chip_uptime += ESAS2R_CHP_UPTIME_CNT; 544 a->chip_uptime += ESAS2R_CHP_UPTIME_CNT;
545 a->chip_init_time = jiffies_to_msecs(jiffies); 545 a->chip_init_time = jiffies_to_msecs(jiffies);
546 if (!(a->flags & AF_POWER_MGT)) { 546 if (!test_bit(AF_POWER_MGT, &a->flags)) {
547 esas2r_process_adapter_reset(a); 547 esas2r_process_adapter_reset(a);
548 548
549 if (!(flags & AF_CHPRST_STARTED)) { 549 if (!alrdyrst) {
550 /* Remove devices now that I/O is cleaned up. */ 550 /* Remove devices now that I/O is cleaned up. */
551 a->prev_dev_cnt = 551 a->prev_dev_cnt =
552 esas2r_targ_db_get_tgt_cnt(a); 552 esas2r_targ_db_get_tgt_cnt(a);
@@ -560,38 +560,37 @@ static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
560 560
561static void esas2r_handle_chip_rst_during_tasklet(struct esas2r_adapter *a) 561static void esas2r_handle_chip_rst_during_tasklet(struct esas2r_adapter *a)
562{ 562{
563 while (a->flags & AF_CHPRST_DETECTED) { 563 while (test_bit(AF_CHPRST_DETECTED, &a->flags)) {
564 /* 564 /*
565 * Balance the enable in esas2r_initadapter_hw. 565 * Balance the enable in esas2r_initadapter_hw.
566 * Esas2r_power_down already took care of it for power 566 * Esas2r_power_down already took care of it for power
567 * management. 567 * management.
568 */ 568 */
569 if (!(a->flags & AF_DEGRADED_MODE) && !(a->flags & 569 if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
570 AF_POWER_MGT)) 570 !test_bit(AF_POWER_MGT, &a->flags))
571 esas2r_disable_chip_interrupts(a); 571 esas2r_disable_chip_interrupts(a);
572 572
573 /* Reinitialize the chip. */ 573 /* Reinitialize the chip. */
574 esas2r_check_adapter(a); 574 esas2r_check_adapter(a);
575 esas2r_init_adapter_hw(a, 0); 575 esas2r_init_adapter_hw(a, 0);
576 576
577 if (a->flags & AF_CHPRST_NEEDED) 577 if (test_bit(AF_CHPRST_NEEDED, &a->flags))
578 break; 578 break;
579 579
580 if (a->flags & AF_POWER_MGT) { 580 if (test_bit(AF_POWER_MGT, &a->flags)) {
581 /* Recovery from power management. */ 581 /* Recovery from power management. */
582 if (a->flags & AF_FIRST_INIT) { 582 if (test_bit(AF_FIRST_INIT, &a->flags)) {
583 /* Chip reset during normal power up */ 583 /* Chip reset during normal power up */
584 esas2r_log(ESAS2R_LOG_CRIT, 584 esas2r_log(ESAS2R_LOG_CRIT,
585 "The firmware was reset during a normal power-up sequence"); 585 "The firmware was reset during a normal power-up sequence");
586 } else { 586 } else {
587 /* Deferred power up complete. */ 587 /* Deferred power up complete. */
588 esas2r_lock_clear_flags(&a->flags, 588 clear_bit(AF_POWER_MGT, &a->flags);
589 AF_POWER_MGT);
590 esas2r_send_reset_ae(a, true); 589 esas2r_send_reset_ae(a, true);
591 } 590 }
592 } else { 591 } else {
593 /* Recovery from online chip reset. */ 592 /* Recovery from online chip reset. */
594 if (a->flags & AF_FIRST_INIT) { 593 if (test_bit(AF_FIRST_INIT, &a->flags)) {
595 /* Chip reset during driver load */ 594 /* Chip reset during driver load */
596 } else { 595 } else {
597 /* Chip reset after driver load */ 596 /* Chip reset after driver load */
@@ -602,14 +601,14 @@ static void esas2r_handle_chip_rst_during_tasklet(struct esas2r_adapter *a)
602 "Recovering from a chip reset while the chip was online"); 601 "Recovering from a chip reset while the chip was online");
603 } 602 }
604 603
605 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_STARTED); 604 clear_bit(AF_CHPRST_STARTED, &a->flags);
606 esas2r_enable_chip_interrupts(a); 605 esas2r_enable_chip_interrupts(a);
607 606
608 /* 607 /*
609 * Clear this flag last! this indicates that the chip has been 608 * Clear this flag last! this indicates that the chip has been
610 * reset already during initialization. 609 * reset already during initialization.
611 */ 610 */
612 esas2r_lock_clear_flags(&a->flags, AF_CHPRST_DETECTED); 611 clear_bit(AF_CHPRST_DETECTED, &a->flags);
613 } 612 }
614} 613}
615 614
@@ -617,26 +616,28 @@ static void esas2r_handle_chip_rst_during_tasklet(struct esas2r_adapter *a)
617/* Perform deferred tasks when chip interrupts are disabled */ 616/* Perform deferred tasks when chip interrupts are disabled */
618void esas2r_do_tasklet_tasks(struct esas2r_adapter *a) 617void esas2r_do_tasklet_tasks(struct esas2r_adapter *a)
619{ 618{
620 if (a->flags & (AF_CHPRST_NEEDED | AF_CHPRST_DETECTED)) { 619
621 if (a->flags & AF_CHPRST_NEEDED) 620 if (test_bit(AF_CHPRST_NEEDED, &a->flags) ||
621 test_bit(AF_CHPRST_DETECTED, &a->flags)) {
622 if (test_bit(AF_CHPRST_NEEDED, &a->flags))
622 esas2r_chip_rst_needed_during_tasklet(a); 623 esas2r_chip_rst_needed_during_tasklet(a);
623 624
624 esas2r_handle_chip_rst_during_tasklet(a); 625 esas2r_handle_chip_rst_during_tasklet(a);
625 } 626 }
626 627
627 if (a->flags & AF_BUSRST_NEEDED) { 628 if (test_bit(AF_BUSRST_NEEDED, &a->flags)) {
628 esas2r_hdebug("hard resetting bus"); 629 esas2r_hdebug("hard resetting bus");
629 630
630 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_NEEDED); 631 clear_bit(AF_BUSRST_NEEDED, &a->flags);
631 632
632 if (a->flags & AF_FLASHING) 633 if (test_bit(AF_FLASHING, &a->flags))
633 esas2r_lock_set_flags(&a->flags, AF_BUSRST_DETECTED); 634 set_bit(AF_BUSRST_DETECTED, &a->flags);
634 else 635 else
635 esas2r_write_register_dword(a, MU_DOORBELL_IN, 636 esas2r_write_register_dword(a, MU_DOORBELL_IN,
636 DRBL_RESET_BUS); 637 DRBL_RESET_BUS);
637 } 638 }
638 639
639 if (a->flags & AF_BUSRST_DETECTED) { 640 if (test_bit(AF_BUSRST_DETECTED, &a->flags)) {
640 esas2r_process_bus_reset(a); 641 esas2r_process_bus_reset(a);
641 642
642 esas2r_log_dev(ESAS2R_LOG_WARN, 643 esas2r_log_dev(ESAS2R_LOG_WARN,
@@ -645,14 +646,14 @@ void esas2r_do_tasklet_tasks(struct esas2r_adapter *a)
645 646
646 scsi_report_bus_reset(a->host, 0); 647 scsi_report_bus_reset(a->host, 0);
647 648
648 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_DETECTED); 649 clear_bit(AF_BUSRST_DETECTED, &a->flags);
649 esas2r_lock_clear_flags(&a->flags, AF_BUSRST_PENDING); 650 clear_bit(AF_BUSRST_PENDING, &a->flags);
650 651
651 esas2r_log(ESAS2R_LOG_WARN, "Bus reset complete"); 652 esas2r_log(ESAS2R_LOG_WARN, "Bus reset complete");
652 } 653 }
653 654
654 if (a->flags & AF_PORT_CHANGE) { 655 if (test_bit(AF_PORT_CHANGE, &a->flags)) {
655 esas2r_lock_clear_flags(&a->flags, AF_PORT_CHANGE); 656 clear_bit(AF_PORT_CHANGE, &a->flags);
656 657
657 esas2r_targ_db_report_changes(a); 658 esas2r_targ_db_report_changes(a);
658 } 659 }
@@ -672,10 +673,10 @@ static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell)
672 esas2r_write_register_dword(a, MU_DOORBELL_OUT, doorbell); 673 esas2r_write_register_dword(a, MU_DOORBELL_OUT, doorbell);
673 674
674 if (doorbell & DRBL_RESET_BUS) 675 if (doorbell & DRBL_RESET_BUS)
675 esas2r_lock_set_flags(&a->flags, AF_BUSRST_DETECTED); 676 set_bit(AF_BUSRST_DETECTED, &a->flags);
676 677
677 if (doorbell & DRBL_FORCE_INT) 678 if (doorbell & DRBL_FORCE_INT)
678 esas2r_lock_clear_flags(&a->flags, AF_HEARTBEAT); 679 clear_bit(AF_HEARTBEAT, &a->flags);
679 680
680 if (doorbell & DRBL_PANIC_REASON_MASK) { 681 if (doorbell & DRBL_PANIC_REASON_MASK) {
681 esas2r_hdebug("*** Firmware Panic ***"); 682 esas2r_hdebug("*** Firmware Panic ***");
@@ -683,7 +684,7 @@ static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell)
683 } 684 }
684 685
685 if (doorbell & DRBL_FW_RESET) { 686 if (doorbell & DRBL_FW_RESET) {
686 esas2r_lock_set_flags(&a->flags2, AF2_COREDUMP_AVAIL); 687 set_bit(AF2_COREDUMP_AVAIL, &a->flags2);
687 esas2r_local_reset_adapter(a); 688 esas2r_local_reset_adapter(a);
688 } 689 }
689 690
@@ -918,7 +919,7 @@ void esas2r_complete_request(struct esas2r_adapter *a,
918{ 919{
919 if (rq->vrq->scsi.function == VDA_FUNC_FLASH 920 if (rq->vrq->scsi.function == VDA_FUNC_FLASH
920 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT) 921 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT)
921 esas2r_lock_clear_flags(&a->flags, AF_FLASHING); 922 clear_bit(AF_FLASHING, &a->flags);
922 923
923 /* See if we setup a callback to do special processing */ 924 /* See if we setup a callback to do special processing */
924 925
diff --git a/drivers/scsi/esas2r/esas2r_io.c b/drivers/scsi/esas2r/esas2r_io.c
index 324e2626a08b..a8df916cd57a 100644
--- a/drivers/scsi/esas2r/esas2r_io.c
+++ b/drivers/scsi/esas2r/esas2r_io.c
@@ -49,7 +49,8 @@ void esas2r_start_request(struct esas2r_adapter *a, struct esas2r_request *rq)
49 struct esas2r_request *startrq = rq; 49 struct esas2r_request *startrq = rq;
50 unsigned long flags; 50 unsigned long flags;
51 51
52 if (unlikely(a->flags & (AF_DEGRADED_MODE | AF_POWER_DOWN))) { 52 if (unlikely(test_bit(AF_DEGRADED_MODE, &a->flags) ||
53 test_bit(AF_POWER_DOWN, &a->flags))) {
53 if (rq->vrq->scsi.function == VDA_FUNC_SCSI) 54 if (rq->vrq->scsi.function == VDA_FUNC_SCSI)
54 rq->req_stat = RS_SEL2; 55 rq->req_stat = RS_SEL2;
55 else 56 else
@@ -69,8 +70,8 @@ void esas2r_start_request(struct esas2r_adapter *a, struct esas2r_request *rq)
69 * Note that if AF_DISC_PENDING is set than this will 70 * Note that if AF_DISC_PENDING is set than this will
70 * go on the defer queue. 71 * go on the defer queue.
71 */ 72 */
72 if (unlikely(t->target_state != TS_PRESENT 73 if (unlikely(t->target_state != TS_PRESENT &&
73 && !(a->flags & AF_DISC_PENDING))) 74 !test_bit(AF_DISC_PENDING, &a->flags)))
74 rq->req_stat = RS_SEL; 75 rq->req_stat = RS_SEL;
75 } 76 }
76 } 77 }
@@ -91,8 +92,9 @@ void esas2r_start_request(struct esas2r_adapter *a, struct esas2r_request *rq)
91 spin_lock_irqsave(&a->queue_lock, flags); 92 spin_lock_irqsave(&a->queue_lock, flags);
92 93
93 if (likely(list_empty(&a->defer_list) && 94 if (likely(list_empty(&a->defer_list) &&
94 !(a->flags & 95 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
95 (AF_CHPRST_PENDING | AF_FLASHING | AF_DISC_PENDING)))) 96 !test_bit(AF_FLASHING, &a->flags) &&
97 !test_bit(AF_DISC_PENDING, &a->flags)))
96 esas2r_local_start_request(a, startrq); 98 esas2r_local_start_request(a, startrq);
97 else 99 else
98 list_add_tail(&startrq->req_list, &a->defer_list); 100 list_add_tail(&startrq->req_list, &a->defer_list);
@@ -124,7 +126,7 @@ void esas2r_local_start_request(struct esas2r_adapter *a,
124 126
125 if (unlikely(rq->vrq->scsi.function == VDA_FUNC_FLASH 127 if (unlikely(rq->vrq->scsi.function == VDA_FUNC_FLASH
126 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT)) 128 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT))
127 esas2r_lock_set_flags(&a->flags, AF_FLASHING); 129 set_bit(AF_FLASHING, &a->flags);
128 130
129 list_add_tail(&rq->req_list, &a->active_list); 131 list_add_tail(&rq->req_list, &a->active_list);
130 esas2r_start_vda_request(a, rq); 132 esas2r_start_vda_request(a, rq);
@@ -147,11 +149,10 @@ void esas2r_start_vda_request(struct esas2r_adapter *a,
147 if (a->last_write >= a->list_size) { 149 if (a->last_write >= a->list_size) {
148 a->last_write = 0; 150 a->last_write = 0;
149 /* update the toggle bit */ 151 /* update the toggle bit */
150 if (a->flags & AF_COMM_LIST_TOGGLE) 152 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags))
151 esas2r_lock_clear_flags(&a->flags, 153 clear_bit(AF_COMM_LIST_TOGGLE, &a->flags);
152 AF_COMM_LIST_TOGGLE);
153 else 154 else
154 esas2r_lock_set_flags(&a->flags, AF_COMM_LIST_TOGGLE); 155 set_bit(AF_COMM_LIST_TOGGLE, &a->flags);
155 } 156 }
156 157
157 element = 158 element =
@@ -169,7 +170,7 @@ void esas2r_start_vda_request(struct esas2r_adapter *a,
169 /* Update the write pointer */ 170 /* Update the write pointer */
170 dw = a->last_write; 171 dw = a->last_write;
171 172
172 if (a->flags & AF_COMM_LIST_TOGGLE) 173 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags))
173 dw |= MU_ILW_TOGGLE; 174 dw |= MU_ILW_TOGGLE;
174 175
175 esas2r_trace("rq->vrq->scsi.handle:%x", rq->vrq->scsi.handle); 176 esas2r_trace("rq->vrq->scsi.handle:%x", rq->vrq->scsi.handle);
@@ -687,18 +688,14 @@ static void esas2r_handle_pending_reset(struct esas2r_adapter *a, u32 currtime)
687 esas2r_write_register_dword(a, MU_DOORBELL_OUT, 688 esas2r_write_register_dword(a, MU_DOORBELL_OUT,
688 doorbell); 689 doorbell);
689 if (ver == DRBL_FW_VER_0) { 690 if (ver == DRBL_FW_VER_0) {
690 esas2r_lock_set_flags(&a->flags, 691 set_bit(AF_CHPRST_DETECTED, &a->flags);
691 AF_CHPRST_DETECTED); 692 set_bit(AF_LEGACY_SGE_MODE, &a->flags);
692 esas2r_lock_set_flags(&a->flags,
693 AF_LEGACY_SGE_MODE);
694 693
695 a->max_vdareq_size = 128; 694 a->max_vdareq_size = 128;
696 a->build_sgl = esas2r_build_sg_list_sge; 695 a->build_sgl = esas2r_build_sg_list_sge;
697 } else if (ver == DRBL_FW_VER_1) { 696 } else if (ver == DRBL_FW_VER_1) {
698 esas2r_lock_set_flags(&a->flags, 697 set_bit(AF_CHPRST_DETECTED, &a->flags);
699 AF_CHPRST_DETECTED); 698 clear_bit(AF_LEGACY_SGE_MODE, &a->flags);
700 esas2r_lock_clear_flags(&a->flags,
701 AF_LEGACY_SGE_MODE);
702 699
703 a->max_vdareq_size = 1024; 700 a->max_vdareq_size = 1024;
704 a->build_sgl = esas2r_build_sg_list_prd; 701 a->build_sgl = esas2r_build_sg_list_prd;
@@ -719,28 +716,27 @@ void esas2r_timer_tick(struct esas2r_adapter *a)
719 a->last_tick_time = currtime; 716 a->last_tick_time = currtime;
720 717
721 /* count down the uptime */ 718 /* count down the uptime */
722 if (a->chip_uptime 719 if (a->chip_uptime &&
723 && !(a->flags & (AF_CHPRST_PENDING | AF_DISC_PENDING))) { 720 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
721 !test_bit(AF_DISC_PENDING, &a->flags)) {
724 if (deltatime >= a->chip_uptime) 722 if (deltatime >= a->chip_uptime)
725 a->chip_uptime = 0; 723 a->chip_uptime = 0;
726 else 724 else
727 a->chip_uptime -= deltatime; 725 a->chip_uptime -= deltatime;
728 } 726 }
729 727
730 if (a->flags & AF_CHPRST_PENDING) { 728 if (test_bit(AF_CHPRST_PENDING, &a->flags)) {
731 if (!(a->flags & AF_CHPRST_NEEDED) 729 if (!test_bit(AF_CHPRST_NEEDED, &a->flags) &&
732 && !(a->flags & AF_CHPRST_DETECTED)) 730 !test_bit(AF_CHPRST_DETECTED, &a->flags))
733 esas2r_handle_pending_reset(a, currtime); 731 esas2r_handle_pending_reset(a, currtime);
734 } else { 732 } else {
735 if (a->flags & AF_DISC_PENDING) 733 if (test_bit(AF_DISC_PENDING, &a->flags))
736 esas2r_disc_check_complete(a); 734 esas2r_disc_check_complete(a);
737 735 if (test_bit(AF_HEARTBEAT_ENB, &a->flags)) {
738 if (a->flags & AF_HEARTBEAT_ENB) { 736 if (test_bit(AF_HEARTBEAT, &a->flags)) {
739 if (a->flags & AF_HEARTBEAT) {
740 if ((currtime - a->heartbeat_time) >= 737 if ((currtime - a->heartbeat_time) >=
741 ESAS2R_HEARTBEAT_TIME) { 738 ESAS2R_HEARTBEAT_TIME) {
742 esas2r_lock_clear_flags(&a->flags, 739 clear_bit(AF_HEARTBEAT, &a->flags);
743 AF_HEARTBEAT);
744 esas2r_hdebug("heartbeat failed"); 740 esas2r_hdebug("heartbeat failed");
745 esas2r_log(ESAS2R_LOG_CRIT, 741 esas2r_log(ESAS2R_LOG_CRIT,
746 "heartbeat failed"); 742 "heartbeat failed");
@@ -748,7 +744,7 @@ void esas2r_timer_tick(struct esas2r_adapter *a)
748 esas2r_local_reset_adapter(a); 744 esas2r_local_reset_adapter(a);
749 } 745 }
750 } else { 746 } else {
751 esas2r_lock_set_flags(&a->flags, AF_HEARTBEAT); 747 set_bit(AF_HEARTBEAT, &a->flags);
752 a->heartbeat_time = currtime; 748 a->heartbeat_time = currtime;
753 esas2r_force_interrupt(a); 749 esas2r_force_interrupt(a);
754 } 750 }
@@ -812,7 +808,7 @@ bool esas2r_send_task_mgmt(struct esas2r_adapter *a,
812 rqaux->vrq->scsi.flags |= 808 rqaux->vrq->scsi.flags |=
813 cpu_to_le16(task_mgt_func * LOBIT(FCP_CMND_TM_MASK)); 809 cpu_to_le16(task_mgt_func * LOBIT(FCP_CMND_TM_MASK));
814 810
815 if (a->flags & AF_FLASHING) { 811 if (test_bit(AF_FLASHING, &a->flags)) {
816 /* Assume success. if there are active requests, return busy */ 812 /* Assume success. if there are active requests, return busy */
817 rqaux->req_stat = RS_SUCCESS; 813 rqaux->req_stat = RS_SUCCESS;
818 814
@@ -831,7 +827,7 @@ bool esas2r_send_task_mgmt(struct esas2r_adapter *a,
831 827
832 spin_unlock_irqrestore(&a->queue_lock, flags); 828 spin_unlock_irqrestore(&a->queue_lock, flags);
833 829
834 if (!(a->flags & AF_FLASHING)) 830 if (!test_bit(AF_FLASHING, &a->flags))
835 esas2r_start_request(a, rqaux); 831 esas2r_start_request(a, rqaux);
836 832
837 esas2r_comp_list_drain(a, &comp_list); 833 esas2r_comp_list_drain(a, &comp_list);
@@ -848,11 +844,12 @@ void esas2r_reset_bus(struct esas2r_adapter *a)
848{ 844{
849 esas2r_log(ESAS2R_LOG_INFO, "performing a bus reset"); 845 esas2r_log(ESAS2R_LOG_INFO, "performing a bus reset");
850 846
851 if (!(a->flags & AF_DEGRADED_MODE) 847 if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
852 && !(a->flags & (AF_CHPRST_PENDING | AF_DISC_PENDING))) { 848 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
853 esas2r_lock_set_flags(&a->flags, AF_BUSRST_NEEDED); 849 !test_bit(AF_DISC_PENDING, &a->flags)) {
854 esas2r_lock_set_flags(&a->flags, AF_BUSRST_PENDING); 850 set_bit(AF_BUSRST_NEEDED, &a->flags);
855 esas2r_lock_set_flags(&a->flags, AF_OS_RESET); 851 set_bit(AF_BUSRST_PENDING, &a->flags);
852 set_bit(AF_OS_RESET, &a->flags);
856 853
857 esas2r_schedule_tasklet(a); 854 esas2r_schedule_tasklet(a);
858 } 855 }
diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index e5b09027e066..d89a0277a8e1 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -347,7 +347,7 @@ static bool csmi_ioctl_tunnel(struct esas2r_adapter *a,
347{ 347{
348 struct atto_vda_ioctl_req *ioctl = &rq->vrq->ioctl; 348 struct atto_vda_ioctl_req *ioctl = &rq->vrq->ioctl;
349 349
350 if (a->flags & AF_DEGRADED_MODE) 350 if (test_bit(AF_DEGRADED_MODE, &a->flags))
351 return false; 351 return false;
352 352
353 esas2r_sgc_init(sgc, a, rq, rq->vrq->ioctl.sge); 353 esas2r_sgc_init(sgc, a, rq, rq->vrq->ioctl.sge);
@@ -463,7 +463,7 @@ static int csmi_ioctl_callback(struct esas2r_adapter *a,
463 gcc->bios_minor_rev = LOBYTE(HIWORD(a->flash_ver)); 463 gcc->bios_minor_rev = LOBYTE(HIWORD(a->flash_ver));
464 gcc->bios_build_rev = LOWORD(a->flash_ver); 464 gcc->bios_build_rev = LOWORD(a->flash_ver);
465 465
466 if (a->flags2 & AF2_THUNDERLINK) 466 if (test_bit(AF2_THUNDERLINK, &a->flags2))
467 gcc->cntlr_flags = CSMI_CNTLRF_SAS_HBA 467 gcc->cntlr_flags = CSMI_CNTLRF_SAS_HBA
468 | CSMI_CNTLRF_SATA_HBA; 468 | CSMI_CNTLRF_SATA_HBA;
469 else 469 else
@@ -485,7 +485,7 @@ static int csmi_ioctl_callback(struct esas2r_adapter *a,
485 { 485 {
486 struct atto_csmi_get_cntlr_sts *gcs = &ioctl_csmi->cntlr_sts; 486 struct atto_csmi_get_cntlr_sts *gcs = &ioctl_csmi->cntlr_sts;
487 487
488 if (a->flags & AF_DEGRADED_MODE) 488 if (test_bit(AF_DEGRADED_MODE, &a->flags))
489 gcs->status = CSMI_CNTLR_STS_FAILED; 489 gcs->status = CSMI_CNTLR_STS_FAILED;
490 else 490 else
491 gcs->status = CSMI_CNTLR_STS_GOOD; 491 gcs->status = CSMI_CNTLR_STS_GOOD;
@@ -819,10 +819,10 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
819 819
820 gai->adap_type = ATTO_GAI_AT_ESASRAID2; 820 gai->adap_type = ATTO_GAI_AT_ESASRAID2;
821 821
822 if (a->flags2 & AF2_THUNDERLINK) 822 if (test_bit(AF2_THUNDERLINK, &a->flags2))
823 gai->adap_type = ATTO_GAI_AT_TLSASHBA; 823 gai->adap_type = ATTO_GAI_AT_TLSASHBA;
824 824
825 if (a->flags & AF_DEGRADED_MODE) 825 if (test_bit(AF_DEGRADED_MODE, &a->flags))
826 gai->adap_flags |= ATTO_GAI_AF_DEGRADED; 826 gai->adap_flags |= ATTO_GAI_AF_DEGRADED;
827 827
828 gai->adap_flags |= ATTO_GAI_AF_SPT_SUPP | 828 gai->adap_flags |= ATTO_GAI_AF_SPT_SUPP |
@@ -938,7 +938,7 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
938 u32 total_len = ESAS2R_FWCOREDUMP_SZ; 938 u32 total_len = ESAS2R_FWCOREDUMP_SZ;
939 939
940 /* Size is zero if a core dump isn't present */ 940 /* Size is zero if a core dump isn't present */
941 if (!(a->flags2 & AF2_COREDUMP_SAVED)) 941 if (!test_bit(AF2_COREDUMP_SAVED, &a->flags2))
942 total_len = 0; 942 total_len = 0;
943 943
944 if (len > total_len) 944 if (len > total_len)
@@ -960,8 +960,7 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
960 memset(a->fw_coredump_buff, 0, 960 memset(a->fw_coredump_buff, 0,
961 ESAS2R_FWCOREDUMP_SZ); 961 ESAS2R_FWCOREDUMP_SZ);
962 962
963 esas2r_lock_clear_flags(&a->flags2, 963 clear_bit(AF2_COREDUMP_SAVED, &a->flags2);
964 AF2_COREDUMP_SAVED);
965 } else if (trc->trace_func != ATTO_TRC_TF_GET_INFO) { 964 } else if (trc->trace_func != ATTO_TRC_TF_GET_INFO) {
966 hi->status = ATTO_STS_UNSUPPORTED; 965 hi->status = ATTO_STS_UNSUPPORTED;
967 break; 966 break;
@@ -973,7 +972,7 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
973 trc->total_length = ESAS2R_FWCOREDUMP_SZ; 972 trc->total_length = ESAS2R_FWCOREDUMP_SZ;
974 973
975 /* Return zero length buffer if core dump not present */ 974 /* Return zero length buffer if core dump not present */
976 if (!(a->flags2 & AF2_COREDUMP_SAVED)) 975 if (!test_bit(AF2_COREDUMP_SAVED, &a->flags2))
977 trc->total_length = 0; 976 trc->total_length = 0;
978 } else { 977 } else {
979 hi->status = ATTO_STS_UNSUPPORTED; 978 hi->status = ATTO_STS_UNSUPPORTED;
@@ -1048,6 +1047,7 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
1048 else if (spt->flags & ATTO_SPTF_HEAD_OF_Q) 1047 else if (spt->flags & ATTO_SPTF_HEAD_OF_Q)
1049 rq->vrq->scsi.flags |= cpu_to_le32(FCP_CMND_TA_HEAD_Q); 1048 rq->vrq->scsi.flags |= cpu_to_le32(FCP_CMND_TA_HEAD_Q);
1050 1049
1050
1051 if (!esas2r_build_sg_list(a, rq, sgc)) { 1051 if (!esas2r_build_sg_list(a, rq, sgc)) {
1052 hi->status = ATTO_STS_OUT_OF_RSRC; 1052 hi->status = ATTO_STS_OUT_OF_RSRC;
1053 break; 1053 break;
@@ -1139,15 +1139,15 @@ static int hba_ioctl_callback(struct esas2r_adapter *a,
1139 break; 1139 break;
1140 } 1140 }
1141 1141
1142 if (a->flags & AF_CHPRST_NEEDED) 1142 if (test_bit(AF_CHPRST_NEEDED, &a->flags))
1143 ac->adap_state = ATTO_AC_AS_RST_SCHED; 1143 ac->adap_state = ATTO_AC_AS_RST_SCHED;
1144 else if (a->flags & AF_CHPRST_PENDING) 1144 else if (test_bit(AF_CHPRST_PENDING, &a->flags))
1145 ac->adap_state = ATTO_AC_AS_RST_IN_PROG; 1145 ac->adap_state = ATTO_AC_AS_RST_IN_PROG;
1146 else if (a->flags & AF_DISC_PENDING) 1146 else if (test_bit(AF_DISC_PENDING, &a->flags))
1147 ac->adap_state = ATTO_AC_AS_RST_DISC; 1147 ac->adap_state = ATTO_AC_AS_RST_DISC;
1148 else if (a->flags & AF_DISABLED) 1148 else if (test_bit(AF_DISABLED, &a->flags))
1149 ac->adap_state = ATTO_AC_AS_DISABLED; 1149 ac->adap_state = ATTO_AC_AS_DISABLED;
1150 else if (a->flags & AF_DEGRADED_MODE) 1150 else if (test_bit(AF_DEGRADED_MODE, &a->flags))
1151 ac->adap_state = ATTO_AC_AS_DEGRADED; 1151 ac->adap_state = ATTO_AC_AS_DEGRADED;
1152 else 1152 else
1153 ac->adap_state = ATTO_AC_AS_OK; 1153 ac->adap_state = ATTO_AC_AS_OK;
diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index 4abf1272e1eb..f37f3e3dd5d5 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -889,7 +889,7 @@ int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
889 /* Assume success, if it fails we will fix the result later. */ 889 /* Assume success, if it fails we will fix the result later. */
890 cmd->result = DID_OK << 16; 890 cmd->result = DID_OK << 16;
891 891
892 if (unlikely(a->flags & AF_DEGRADED_MODE)) { 892 if (unlikely(test_bit(AF_DEGRADED_MODE, &a->flags))) {
893 cmd->result = DID_NO_CONNECT << 16; 893 cmd->result = DID_NO_CONNECT << 16;
894 cmd->scsi_done(cmd); 894 cmd->scsi_done(cmd);
895 return 0; 895 return 0;
@@ -1050,7 +1050,7 @@ int esas2r_eh_abort(struct scsi_cmnd *cmd)
1050 1050
1051 esas2r_log(ESAS2R_LOG_INFO, "eh_abort (%p)", cmd); 1051 esas2r_log(ESAS2R_LOG_INFO, "eh_abort (%p)", cmd);
1052 1052
1053 if (a->flags & AF_DEGRADED_MODE) { 1053 if (test_bit(AF_DEGRADED_MODE, &a->flags)) {
1054 cmd->result = DID_ABORT << 16; 1054 cmd->result = DID_ABORT << 16;
1055 1055
1056 scsi_set_resid(cmd, 0); 1056 scsi_set_resid(cmd, 0);
@@ -1131,7 +1131,7 @@ static int esas2r_host_bus_reset(struct scsi_cmnd *cmd, bool host_reset)
1131 struct esas2r_adapter *a = 1131 struct esas2r_adapter *a =
1132 (struct esas2r_adapter *)cmd->device->host->hostdata; 1132 (struct esas2r_adapter *)cmd->device->host->hostdata;
1133 1133
1134 if (a->flags & AF_DEGRADED_MODE) 1134 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1135 return FAILED; 1135 return FAILED;
1136 1136
1137 if (host_reset) 1137 if (host_reset)
@@ -1141,14 +1141,14 @@ static int esas2r_host_bus_reset(struct scsi_cmnd *cmd, bool host_reset)
1141 1141
1142 /* above call sets the AF_OS_RESET flag. wait for it to clear. */ 1142 /* above call sets the AF_OS_RESET flag. wait for it to clear. */
1143 1143
1144 while (a->flags & AF_OS_RESET) { 1144 while (test_bit(AF_OS_RESET, &a->flags)) {
1145 msleep(10); 1145 msleep(10);
1146 1146
1147 if (a->flags & AF_DEGRADED_MODE) 1147 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1148 return FAILED; 1148 return FAILED;
1149 } 1149 }
1150 1150
1151 if (a->flags & AF_DEGRADED_MODE) 1151 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1152 return FAILED; 1152 return FAILED;
1153 1153
1154 return SUCCESS; 1154 return SUCCESS;
@@ -1176,7 +1176,7 @@ static int esas2r_dev_targ_reset(struct scsi_cmnd *cmd, bool target_reset)
1176 u8 task_management_status = RS_PENDING; 1176 u8 task_management_status = RS_PENDING;
1177 bool completed; 1177 bool completed;
1178 1178
1179 if (a->flags & AF_DEGRADED_MODE) 1179 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1180 return FAILED; 1180 return FAILED;
1181 1181
1182retry: 1182retry:
@@ -1229,7 +1229,7 @@ retry:
1229 msleep(10); 1229 msleep(10);
1230 } 1230 }
1231 1231
1232 if (a->flags & AF_DEGRADED_MODE) 1232 if (test_bit(AF_DEGRADED_MODE, &a->flags))
1233 return FAILED; 1233 return FAILED;
1234 1234
1235 if (task_management_status == RS_BUSY) { 1235 if (task_management_status == RS_BUSY) {
@@ -1666,13 +1666,13 @@ void esas2r_adapter_tasklet(unsigned long context)
1666{ 1666{
1667 struct esas2r_adapter *a = (struct esas2r_adapter *)context; 1667 struct esas2r_adapter *a = (struct esas2r_adapter *)context;
1668 1668
1669 if (unlikely(a->flags2 & AF2_TIMER_TICK)) { 1669 if (unlikely(test_bit(AF2_TIMER_TICK, &a->flags2))) {
1670 esas2r_lock_clear_flags(&a->flags2, AF2_TIMER_TICK); 1670 clear_bit(AF2_TIMER_TICK, &a->flags2);
1671 esas2r_timer_tick(a); 1671 esas2r_timer_tick(a);
1672 } 1672 }
1673 1673
1674 if (likely(a->flags2 & AF2_INT_PENDING)) { 1674 if (likely(test_bit(AF2_INT_PENDING, &a->flags2))) {
1675 esas2r_lock_clear_flags(&a->flags2, AF2_INT_PENDING); 1675 clear_bit(AF2_INT_PENDING, &a->flags2);
1676 esas2r_adapter_interrupt(a); 1676 esas2r_adapter_interrupt(a);
1677 } 1677 }
1678 1678
@@ -1680,12 +1680,12 @@ void esas2r_adapter_tasklet(unsigned long context)
1680 esas2r_do_tasklet_tasks(a); 1680 esas2r_do_tasklet_tasks(a);
1681 1681
1682 if (esas2r_is_tasklet_pending(a) 1682 if (esas2r_is_tasklet_pending(a)
1683 || (a->flags2 & AF2_INT_PENDING) 1683 || (test_bit(AF2_INT_PENDING, &a->flags2))
1684 || (a->flags2 & AF2_TIMER_TICK)) { 1684 || (test_bit(AF2_TIMER_TICK, &a->flags2))) {
1685 esas2r_lock_clear_flags(&a->flags, AF_TASKLET_SCHEDULED); 1685 clear_bit(AF_TASKLET_SCHEDULED, &a->flags);
1686 esas2r_schedule_tasklet(a); 1686 esas2r_schedule_tasklet(a);
1687 } else { 1687 } else {
1688 esas2r_lock_clear_flags(&a->flags, AF_TASKLET_SCHEDULED); 1688 clear_bit(AF_TASKLET_SCHEDULED, &a->flags);
1689 } 1689 }
1690} 1690}
1691 1691
@@ -1707,7 +1707,7 @@ static void esas2r_timer_callback(unsigned long context)
1707{ 1707{
1708 struct esas2r_adapter *a = (struct esas2r_adapter *)context; 1708 struct esas2r_adapter *a = (struct esas2r_adapter *)context;
1709 1709
1710 esas2r_lock_set_flags(&a->flags2, AF2_TIMER_TICK); 1710 set_bit(AF2_TIMER_TICK, &a->flags2);
1711 1711
1712 esas2r_schedule_tasklet(a); 1712 esas2r_schedule_tasklet(a);
1713 1713
diff --git a/drivers/scsi/esas2r/esas2r_targdb.c b/drivers/scsi/esas2r/esas2r_targdb.c
index e540a2fa3d15..bf45beaad439 100644
--- a/drivers/scsi/esas2r/esas2r_targdb.c
+++ b/drivers/scsi/esas2r/esas2r_targdb.c
@@ -86,7 +86,7 @@ void esas2r_targ_db_report_changes(struct esas2r_adapter *a)
86 86
87 esas2r_trace_enter(); 87 esas2r_trace_enter();
88 88
89 if (a->flags & AF_DISC_PENDING) { 89 if (test_bit(AF_DISC_PENDING, &a->flags)) {
90 esas2r_trace_exit(); 90 esas2r_trace_exit();
91 return; 91 return;
92 } 92 }
diff --git a/drivers/scsi/esas2r/esas2r_vda.c b/drivers/scsi/esas2r/esas2r_vda.c
index fd1392879647..27e97215bb2f 100644
--- a/drivers/scsi/esas2r/esas2r_vda.c
+++ b/drivers/scsi/esas2r/esas2r_vda.c
@@ -84,7 +84,7 @@ bool esas2r_process_vda_ioctl(struct esas2r_adapter *a,
84 return false; 84 return false;
85 } 85 }
86 86
87 if (a->flags & AF_DEGRADED_MODE) { 87 if (test_bit(AF_DEGRADED_MODE, &a->flags)) {
88 vi->status = ATTO_STS_DEGRADED; 88 vi->status = ATTO_STS_DEGRADED;
89 return false; 89 return false;
90 } 90 }
@@ -389,7 +389,7 @@ void esas2r_build_mgt_req(struct esas2r_adapter *a,
389 vrq->length = cpu_to_le32(length); 389 vrq->length = cpu_to_le32(length);
390 390
391 if (vrq->length) { 391 if (vrq->length) {
392 if (a->flags & AF_LEGACY_SGE_MODE) { 392 if (test_bit(AF_LEGACY_SGE_MODE, &a->flags)) {
393 vrq->sg_list_offset = (u8)offsetof( 393 vrq->sg_list_offset = (u8)offsetof(
394 struct atto_vda_mgmt_req, sge); 394 struct atto_vda_mgmt_req, sge);
395 395
@@ -427,7 +427,7 @@ void esas2r_build_ae_req(struct esas2r_adapter *a, struct esas2r_request *rq)
427 427
428 vrq->length = cpu_to_le32(sizeof(struct atto_vda_ae_data)); 428 vrq->length = cpu_to_le32(sizeof(struct atto_vda_ae_data));
429 429
430 if (a->flags & AF_LEGACY_SGE_MODE) { 430 if (test_bit(AF_LEGACY_SGE_MODE, &a->flags)) {
431 vrq->sg_list_offset = 431 vrq->sg_list_offset =
432 (u8)offsetof(struct atto_vda_ae_req, sge); 432 (u8)offsetof(struct atto_vda_ae_req, sge);
433 vrq->sge[0].length = cpu_to_le32(SGE_LAST | vrq->length); 433 vrq->sge[0].length = cpu_to_le32(SGE_LAST | vrq->length);