1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include <linux/module.h>
46#include <linux/kernel.h>
47#include <linux/init.h>
48#include <linux/errno.h>
49#include <linux/blkdev.h>
50#include <linux/sched.h>
51#include <linux/workqueue.h>
52#include <linux/delay.h>
53#include <linux/pci.h>
54#include <linux/pci-aspm.h>
55#include <linux/interrupt.h>
56#include <linux/aer.h>
57#include <linux/raid_class.h>
58#include <asm/unaligned.h>
59
60#include "mpt3sas_base.h"
61
62#define RAID_CHANNEL 1
63
64static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
65 struct _sas_node *sas_expander);
66static void _firmware_event_work(struct work_struct *work);
67
68static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
69 struct _sas_device *sas_device);
70static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
71 u8 retry_count, u8 is_pd);
72
73static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
74
75
76LIST_HEAD(mpt3sas_ioc_list);
77
78DEFINE_SPINLOCK(gioc_lock);
79
80MODULE_AUTHOR(MPT3SAS_AUTHOR);
81MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
82MODULE_LICENSE("GPL");
83MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
84MODULE_ALIAS("mpt2sas");
85
86
87static u8 scsi_io_cb_idx = -1;
88static u8 tm_cb_idx = -1;
89static u8 ctl_cb_idx = -1;
90static u8 base_cb_idx = -1;
91static u8 port_enable_cb_idx = -1;
92static u8 transport_cb_idx = -1;
93static u8 scsih_cb_idx = -1;
94static u8 config_cb_idx = -1;
95static int mpt2_ids;
96static int mpt3_ids;
97
98static u8 tm_tr_cb_idx = -1 ;
99static u8 tm_tr_volume_cb_idx = -1 ;
100static u8 tm_sas_control_cb_idx = -1;
101
102
103static u32 logging_level;
104MODULE_PARM_DESC(logging_level,
105 " bits for enabling additional logging info (default=0)");
106
107
108static ushort max_sectors = 0xFFFF;
109module_param(max_sectors, ushort, 0);
110MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
111
112
113static int missing_delay[2] = {-1, -1};
114module_param_array(missing_delay, int, NULL, 0);
115MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
116
117
118#define MPT3SAS_MAX_LUN (16895)
119static u64 max_lun = MPT3SAS_MAX_LUN;
120module_param(max_lun, ullong, 0);
121MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122
123static ushort hbas_to_enumerate;
124module_param(hbas_to_enumerate, ushort, 0);
125MODULE_PARM_DESC(hbas_to_enumerate,
126 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
127 1 - enumerates only SAS 2.0 generation HBAs\n \
128 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
129
130
131
132
133
134
135
136
137static int diag_buffer_enable = -1;
138module_param(diag_buffer_enable, int, 0);
139MODULE_PARM_DESC(diag_buffer_enable,
140 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
141static int disable_discovery = -1;
142module_param(disable_discovery, int, 0);
143MODULE_PARM_DESC(disable_discovery, " disable discovery ");
144
145
146
147static int prot_mask = -1;
148module_param(prot_mask, int, 0);
149MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
150
151
152
153struct raid_template *mpt3sas_raid_template;
154struct raid_template *mpt2sas_raid_template;
155
156
157
158
159
160
161
162
163struct sense_info {
164 u8 skey;
165 u8 asc;
166 u8 ascq;
167};
168
169#define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
170#define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
171#define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
172#define MPT3SAS_ABRT_TASK_SET (0xFFFE)
173#define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189struct fw_event_work {
190 struct list_head list;
191 struct work_struct work;
192
193 struct MPT3SAS_ADAPTER *ioc;
194 u16 device_handle;
195 u8 VF_ID;
196 u8 VP_ID;
197 u8 ignore;
198 u16 event;
199 struct kref refcount;
200 char event_data[0] __aligned(4);
201};
202
203static void fw_event_work_free(struct kref *r)
204{
205 kfree(container_of(r, struct fw_event_work, refcount));
206}
207
208static void fw_event_work_get(struct fw_event_work *fw_work)
209{
210 kref_get(&fw_work->refcount);
211}
212
213static void fw_event_work_put(struct fw_event_work *fw_work)
214{
215 kref_put(&fw_work->refcount, fw_event_work_free);
216}
217
218static struct fw_event_work *alloc_fw_event_work(int len)
219{
220 struct fw_event_work *fw_event;
221
222 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
223 if (!fw_event)
224 return NULL;
225
226 kref_init(&fw_event->refcount);
227 return fw_event;
228}
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255struct _scsi_io_transfer {
256 u16 handle;
257 u8 is_raid;
258 enum dma_data_direction dir;
259 u32 data_length;
260 dma_addr_t data_dma;
261 u8 sense[SCSI_SENSE_BUFFERSIZE];
262 u32 lun;
263 u8 cdb_length;
264 u8 cdb[32];
265 u8 timeout;
266 u8 VF_ID;
267 u8 VP_ID;
268 u8 valid_reply;
269
270 u32 sense_length;
271 u16 ioc_status;
272 u8 scsi_state;
273 u8 scsi_status;
274 u32 log_info;
275 u32 transfer_length;
276};
277
278
279
280
281
282
283static int
284_scsih_set_debug_level(const char *val, struct kernel_param *kp)
285{
286 int ret = param_set_int(val, kp);
287 struct MPT3SAS_ADAPTER *ioc;
288
289 if (ret)
290 return ret;
291
292 pr_info("setting logging_level(0x%08x)\n", logging_level);
293 spin_lock(&gioc_lock);
294 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
295 ioc->logging_level = logging_level;
296 spin_unlock(&gioc_lock);
297 return 0;
298}
299module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
300 &logging_level, 0644);
301
302
303
304
305
306
307
308
309static inline int
310_scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
312{
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
314}
315
316
317
318
319
320
321
322
323static inline int
324_scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
326{
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
328}
329
330
331
332
333
334
335
336
337
338static inline int
339_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
341{
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
345}
346
347
348
349
350
351
352
353
354
355
356
357
358static int
359_scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
362{
363 int rc = 0;
364
365 switch (form) {
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
367 if (!sas_address)
368 break;
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
371 break;
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
374 break;
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
378 break;
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
380 if (!device_name)
381 break;
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
384 break;
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
386 break;
387 }
388
389 return rc;
390}
391
392
393
394
395
396
397
398
399static int
400_scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
401 u64 *sas_address)
402{
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
405 u32 ioc_status;
406
407 *sas_address = 0;
408
409 if (handle <= ioc->sas_hba.num_phys) {
410 *sas_address = ioc->sas_hba.sas_address;
411 return 0;
412 }
413
414 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
416 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
417 __FILE__, __LINE__, __func__);
418 return -ENXIO;
419 }
420
421 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
422 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
423 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
424 return 0;
425 }
426
427
428 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
429 return -ENXIO;
430
431
432 pr_err(MPT3SAS_FMT
433 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
434 ioc->name, handle, ioc_status,
435 __FILE__, __LINE__, __func__);
436 return -EIO;
437}
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452static void
453_scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
454 void *device, u8 is_raid)
455{
456 struct _sas_device *sas_device;
457 struct _raid_device *raid_device;
458 u64 sas_address;
459 u64 device_name;
460 u64 enclosure_logical_id;
461 u16 slot;
462
463
464 if (!ioc->is_driver_loading)
465 return;
466
467
468 if (!ioc->bios_pg3.BiosVersion)
469 return;
470
471 if (!is_raid) {
472 sas_device = device;
473 sas_address = sas_device->sas_address;
474 device_name = sas_device->device_name;
475 enclosure_logical_id = sas_device->enclosure_logical_id;
476 slot = sas_device->slot;
477 } else {
478 raid_device = device;
479 sas_address = raid_device->wwid;
480 device_name = 0;
481 enclosure_logical_id = 0;
482 slot = 0;
483 }
484
485 if (!ioc->req_boot_device.device) {
486 if (_scsih_is_boot_device(sas_address, device_name,
487 enclosure_logical_id, slot,
488 (ioc->bios_pg2.ReqBootDeviceForm &
489 MPI2_BIOSPAGE2_FORM_MASK),
490 &ioc->bios_pg2.RequestedBootDevice)) {
491 dinitprintk(ioc, pr_info(MPT3SAS_FMT
492 "%s: req_boot_device(0x%016llx)\n",
493 ioc->name, __func__,
494 (unsigned long long)sas_address));
495 ioc->req_boot_device.device = device;
496 ioc->req_boot_device.is_raid = is_raid;
497 }
498 }
499
500 if (!ioc->req_alt_boot_device.device) {
501 if (_scsih_is_boot_device(sas_address, device_name,
502 enclosure_logical_id, slot,
503 (ioc->bios_pg2.ReqAltBootDeviceForm &
504 MPI2_BIOSPAGE2_FORM_MASK),
505 &ioc->bios_pg2.RequestedAltBootDevice)) {
506 dinitprintk(ioc, pr_info(MPT3SAS_FMT
507 "%s: req_alt_boot_device(0x%016llx)\n",
508 ioc->name, __func__,
509 (unsigned long long)sas_address));
510 ioc->req_alt_boot_device.device = device;
511 ioc->req_alt_boot_device.is_raid = is_raid;
512 }
513 }
514
515 if (!ioc->current_boot_device.device) {
516 if (_scsih_is_boot_device(sas_address, device_name,
517 enclosure_logical_id, slot,
518 (ioc->bios_pg2.CurrentBootDeviceForm &
519 MPI2_BIOSPAGE2_FORM_MASK),
520 &ioc->bios_pg2.CurrentBootDevice)) {
521 dinitprintk(ioc, pr_info(MPT3SAS_FMT
522 "%s: current_boot_device(0x%016llx)\n",
523 ioc->name, __func__,
524 (unsigned long long)sas_address));
525 ioc->current_boot_device.device = device;
526 ioc->current_boot_device.is_raid = is_raid;
527 }
528 }
529}
530
531static struct _sas_device *
532__mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
533 struct MPT3SAS_TARGET *tgt_priv)
534{
535 struct _sas_device *ret;
536
537 assert_spin_locked(&ioc->sas_device_lock);
538
539 ret = tgt_priv->sdev;
540 if (ret)
541 sas_device_get(ret);
542
543 return ret;
544}
545
546static struct _sas_device *
547mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
548 struct MPT3SAS_TARGET *tgt_priv)
549{
550 struct _sas_device *ret;
551 unsigned long flags;
552
553 spin_lock_irqsave(&ioc->sas_device_lock, flags);
554 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
555 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
556
557 return ret;
558}
559
560
561struct _sas_device *
562__mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
563 u64 sas_address)
564{
565 struct _sas_device *sas_device;
566
567 assert_spin_locked(&ioc->sas_device_lock);
568
569 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
570 if (sas_device->sas_address == sas_address)
571 goto found_device;
572
573 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
574 if (sas_device->sas_address == sas_address)
575 goto found_device;
576
577 return NULL;
578
579found_device:
580 sas_device_get(sas_device);
581 return sas_device;
582}
583
584
585
586
587
588
589
590
591
592
593struct _sas_device *
594mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
595 u64 sas_address)
596{
597 struct _sas_device *sas_device;
598 unsigned long flags;
599
600 spin_lock_irqsave(&ioc->sas_device_lock, flags);
601 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
602 sas_address);
603 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
604
605 return sas_device;
606}
607
608static struct _sas_device *
609__mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
610{
611 struct _sas_device *sas_device;
612
613 assert_spin_locked(&ioc->sas_device_lock);
614
615 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
616 if (sas_device->handle == handle)
617 goto found_device;
618
619 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
620 if (sas_device->handle == handle)
621 goto found_device;
622
623 return NULL;
624
625found_device:
626 sas_device_get(sas_device);
627 return sas_device;
628}
629
630
631
632
633
634
635
636
637
638
639static struct _sas_device *
640mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
641{
642 struct _sas_device *sas_device;
643 unsigned long flags;
644
645 spin_lock_irqsave(&ioc->sas_device_lock, flags);
646 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
647 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
648
649 return sas_device;
650}
651
652
653
654
655
656
657
658
659
660static void
661_scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
662 struct _sas_device *sas_device)
663{
664 unsigned long flags;
665
666 if (!sas_device)
667 return;
668 pr_info(MPT3SAS_FMT
669 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
670 ioc->name, sas_device->handle,
671 (unsigned long long) sas_device->sas_address);
672
673 if (sas_device->enclosure_handle != 0)
674 pr_info(MPT3SAS_FMT
675 "removing enclosure logical id(0x%016llx), slot(%d)\n",
676 ioc->name, (unsigned long long)
677 sas_device->enclosure_logical_id, sas_device->slot);
678
679 if (sas_device->connector_name[0] != '\0')
680 pr_info(MPT3SAS_FMT
681 "removing enclosure level(0x%04x), connector name( %s)\n",
682 ioc->name, sas_device->enclosure_level,
683 sas_device->connector_name);
684
685
686
687
688
689 spin_lock_irqsave(&ioc->sas_device_lock, flags);
690 if (!list_empty(&sas_device->list)) {
691 list_del_init(&sas_device->list);
692 sas_device_put(sas_device);
693 }
694 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
695}
696
697
698
699
700
701
702
703
704static void
705_scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
706{
707 struct _sas_device *sas_device;
708 unsigned long flags;
709
710 if (ioc->shost_recovery)
711 return;
712
713 spin_lock_irqsave(&ioc->sas_device_lock, flags);
714 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
715 if (sas_device) {
716 list_del_init(&sas_device->list);
717 sas_device_put(sas_device);
718 }
719 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
720 if (sas_device) {
721 _scsih_remove_device(ioc, sas_device);
722 sas_device_put(sas_device);
723 }
724}
725
726
727
728
729
730
731
732
733void
734mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
735 u64 sas_address)
736{
737 struct _sas_device *sas_device;
738 unsigned long flags;
739
740 if (ioc->shost_recovery)
741 return;
742
743 spin_lock_irqsave(&ioc->sas_device_lock, flags);
744 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
745 if (sas_device) {
746 list_del_init(&sas_device->list);
747 sas_device_put(sas_device);
748 }
749 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
750 if (sas_device) {
751 _scsih_remove_device(ioc, sas_device);
752 sas_device_put(sas_device);
753 }
754}
755
756
757
758
759
760
761
762
763
764static void
765_scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
766 struct _sas_device *sas_device)
767{
768 unsigned long flags;
769
770 dewtprintk(ioc, pr_info(MPT3SAS_FMT
771 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
772 ioc->name, __func__, sas_device->handle,
773 (unsigned long long)sas_device->sas_address));
774
775 if (sas_device->enclosure_handle != 0)
776 dewtprintk(ioc, pr_info(MPT3SAS_FMT
777 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
778 ioc->name, __func__, (unsigned long long)
779 sas_device->enclosure_logical_id, sas_device->slot));
780
781 if (sas_device->connector_name[0] != '\0')
782 dewtprintk(ioc, pr_info(MPT3SAS_FMT
783 "%s: enclosure level(0x%04x), connector name( %s)\n",
784 ioc->name, __func__,
785 sas_device->enclosure_level, sas_device->connector_name));
786
787 spin_lock_irqsave(&ioc->sas_device_lock, flags);
788 sas_device_get(sas_device);
789 list_add_tail(&sas_device->list, &ioc->sas_device_list);
790 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
791
792 if (ioc->hide_drives) {
793 clear_bit(sas_device->handle, ioc->pend_os_device_add);
794 return;
795 }
796
797 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
798 sas_device->sas_address_parent)) {
799 _scsih_sas_device_remove(ioc, sas_device);
800 } else if (!sas_device->starget) {
801
802
803
804
805
806 if (!ioc->is_driver_loading) {
807 mpt3sas_transport_port_remove(ioc,
808 sas_device->sas_address,
809 sas_device->sas_address_parent);
810 _scsih_sas_device_remove(ioc, sas_device);
811 }
812 } else
813 clear_bit(sas_device->handle, ioc->pend_os_device_add);
814}
815
816
817
818
819
820
821
822
823
824static void
825_scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
826 struct _sas_device *sas_device)
827{
828 unsigned long flags;
829
830 dewtprintk(ioc, pr_info(MPT3SAS_FMT
831 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
832 __func__, sas_device->handle,
833 (unsigned long long)sas_device->sas_address));
834
835 if (sas_device->enclosure_handle != 0)
836 dewtprintk(ioc, pr_info(MPT3SAS_FMT
837 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
838 ioc->name, __func__, (unsigned long long)
839 sas_device->enclosure_logical_id, sas_device->slot));
840
841 if (sas_device->connector_name[0] != '\0')
842 dewtprintk(ioc, pr_info(MPT3SAS_FMT
843 "%s: enclosure level(0x%04x), connector name( %s)\n",
844 ioc->name, __func__, sas_device->enclosure_level,
845 sas_device->connector_name));
846
847 spin_lock_irqsave(&ioc->sas_device_lock, flags);
848 sas_device_get(sas_device);
849 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
850 _scsih_determine_boot_device(ioc, sas_device, 0);
851 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
852}
853
854
855
856
857
858
859
860
861
862
863
864static struct _raid_device *
865_scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
866{
867 struct _raid_device *raid_device, *r;
868
869 r = NULL;
870 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
871 if (raid_device->id == id && raid_device->channel == channel) {
872 r = raid_device;
873 goto out;
874 }
875 }
876
877 out:
878 return r;
879}
880
881
882
883
884
885
886
887
888
889
890struct _raid_device *
891mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
892{
893 struct _raid_device *raid_device, *r;
894
895 r = NULL;
896 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
897 if (raid_device->handle != handle)
898 continue;
899 r = raid_device;
900 goto out;
901 }
902
903 out:
904 return r;
905}
906
907
908
909
910
911
912
913
914
915
916static struct _raid_device *
917_scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
918{
919 struct _raid_device *raid_device, *r;
920
921 r = NULL;
922 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
923 if (raid_device->wwid != wwid)
924 continue;
925 r = raid_device;
926 goto out;
927 }
928
929 out:
930 return r;
931}
932
933
934
935
936
937
938
939
940static void
941_scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
942 struct _raid_device *raid_device)
943{
944 unsigned long flags;
945
946 dewtprintk(ioc, pr_info(MPT3SAS_FMT
947 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
948 raid_device->handle, (unsigned long long)raid_device->wwid));
949
950 spin_lock_irqsave(&ioc->raid_device_lock, flags);
951 list_add_tail(&raid_device->list, &ioc->raid_device_list);
952 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
953}
954
955
956
957
958
959
960
961static void
962_scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
963 struct _raid_device *raid_device)
964{
965 unsigned long flags;
966
967 spin_lock_irqsave(&ioc->raid_device_lock, flags);
968 list_del(&raid_device->list);
969 kfree(raid_device);
970 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
971}
972
973
974
975
976
977
978
979
980
981
982struct _sas_node *
983mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
984{
985 struct _sas_node *sas_expander, *r;
986
987 r = NULL;
988 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
989 if (sas_expander->handle != handle)
990 continue;
991 r = sas_expander;
992 goto out;
993 }
994 out:
995 return r;
996}
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007struct _sas_node *
1008mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1009 u64 sas_address)
1010{
1011 struct _sas_node *sas_expander, *r;
1012
1013 r = NULL;
1014 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1015 if (sas_expander->sas_address != sas_address)
1016 continue;
1017 r = sas_expander;
1018 goto out;
1019 }
1020 out:
1021 return r;
1022}
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034static void
1035_scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1036 struct _sas_node *sas_expander)
1037{
1038 unsigned long flags;
1039
1040 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1041 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1042 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1043}
1044
1045
1046
1047
1048
1049
1050
1051
1052static int
1053_scsih_is_end_device(u32 device_info)
1054{
1055 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1056 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1057 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1058 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1059 return 1;
1060 else
1061 return 0;
1062}
1063
1064
1065
1066
1067
1068
1069
1070
1071static struct scsi_cmnd *
1072_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1073{
1074 return ioc->scsi_lookup[smid - 1].scmd;
1075}
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085static inline struct scsi_cmnd *
1086_scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1087{
1088 unsigned long flags;
1089 struct scsi_cmnd *scmd;
1090
1091 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1092 scmd = ioc->scsi_lookup[smid - 1].scmd;
1093 ioc->scsi_lookup[smid - 1].scmd = NULL;
1094 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1095
1096 return scmd;
1097}
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109static u16
1110_scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1111 *scmd)
1112{
1113 u16 smid;
1114 unsigned long flags;
1115 int i;
1116
1117 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1118 smid = 0;
1119 for (i = 0; i < ioc->scsiio_depth; i++) {
1120 if (ioc->scsi_lookup[i].scmd == scmd) {
1121 smid = ioc->scsi_lookup[i].smid;
1122 goto out;
1123 }
1124 }
1125 out:
1126 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1127 return smid;
1128}
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140static u8
1141_scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1142 int channel)
1143{
1144 u8 found;
1145 unsigned long flags;
1146 int i;
1147
1148 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1149 found = 0;
1150 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1151 if (ioc->scsi_lookup[i].scmd &&
1152 (ioc->scsi_lookup[i].scmd->device->id == id &&
1153 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1154 found = 1;
1155 goto out;
1156 }
1157 }
1158 out:
1159 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1160 return found;
1161}
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174static u8
1175_scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1176 unsigned int lun, int channel)
1177{
1178 u8 found;
1179 unsigned long flags;
1180 int i;
1181
1182 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1183 found = 0;
1184 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1185 if (ioc->scsi_lookup[i].scmd &&
1186 (ioc->scsi_lookup[i].scmd->device->id == id &&
1187 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1188 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1189 found = 1;
1190 goto out;
1191 }
1192 }
1193 out:
1194 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1195 return found;
1196}
1197
1198
1199
1200
1201
1202
1203
1204
1205static int
1206scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1207{
1208 struct Scsi_Host *shost = sdev->host;
1209 int max_depth;
1210 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1211 struct MPT3SAS_DEVICE *sas_device_priv_data;
1212 struct MPT3SAS_TARGET *sas_target_priv_data;
1213 struct _sas_device *sas_device;
1214 unsigned long flags;
1215
1216 max_depth = shost->can_queue;
1217
1218
1219 sas_device_priv_data = sdev->hostdata;
1220 if (!sas_device_priv_data)
1221 goto not_sata;
1222 sas_target_priv_data = sas_device_priv_data->sas_target;
1223 if (!sas_target_priv_data)
1224 goto not_sata;
1225 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1226 goto not_sata;
1227
1228 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1229 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1230 if (sas_device) {
1231 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1232 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1233
1234 sas_device_put(sas_device);
1235 }
1236 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1237
1238 not_sata:
1239
1240 if (!sdev->tagged_supported)
1241 max_depth = 1;
1242 if (qdepth > max_depth)
1243 qdepth = max_depth;
1244 return scsi_change_queue_depth(sdev, qdepth);
1245}
1246
1247
1248
1249
1250
1251
1252
1253
1254static int
1255scsih_target_alloc(struct scsi_target *starget)
1256{
1257 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1258 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1259 struct MPT3SAS_TARGET *sas_target_priv_data;
1260 struct _sas_device *sas_device;
1261 struct _raid_device *raid_device;
1262 unsigned long flags;
1263 struct sas_rphy *rphy;
1264
1265 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1266 GFP_KERNEL);
1267 if (!sas_target_priv_data)
1268 return -ENOMEM;
1269
1270 starget->hostdata = sas_target_priv_data;
1271 sas_target_priv_data->starget = starget;
1272 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1273
1274
1275 if (starget->channel == RAID_CHANNEL) {
1276 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1277 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1278 starget->channel);
1279 if (raid_device) {
1280 sas_target_priv_data->handle = raid_device->handle;
1281 sas_target_priv_data->sas_address = raid_device->wwid;
1282 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1283 if (ioc->is_warpdrive)
1284 sas_target_priv_data->raid_device = raid_device;
1285 raid_device->starget = starget;
1286 }
1287 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1288 return 0;
1289 }
1290
1291
1292 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1293 rphy = dev_to_rphy(starget->dev.parent);
1294 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1295 rphy->identify.sas_address);
1296
1297 if (sas_device) {
1298 sas_target_priv_data->handle = sas_device->handle;
1299 sas_target_priv_data->sas_address = sas_device->sas_address;
1300 sas_target_priv_data->sdev = sas_device;
1301 sas_device->starget = starget;
1302 sas_device->id = starget->id;
1303 sas_device->channel = starget->channel;
1304 if (test_bit(sas_device->handle, ioc->pd_handles))
1305 sas_target_priv_data->flags |=
1306 MPT_TARGET_FLAGS_RAID_COMPONENT;
1307 if (sas_device->fast_path)
1308 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1309 }
1310 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1311
1312 return 0;
1313}
1314
1315
1316
1317
1318
1319
1320
1321static void
1322scsih_target_destroy(struct scsi_target *starget)
1323{
1324 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1325 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1326 struct MPT3SAS_TARGET *sas_target_priv_data;
1327 struct _sas_device *sas_device;
1328 struct _raid_device *raid_device;
1329 unsigned long flags;
1330
1331 sas_target_priv_data = starget->hostdata;
1332 if (!sas_target_priv_data)
1333 return;
1334
1335 if (starget->channel == RAID_CHANNEL) {
1336 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1337 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1338 starget->channel);
1339 if (raid_device) {
1340 raid_device->starget = NULL;
1341 raid_device->sdev = NULL;
1342 }
1343 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1344 goto out;
1345 }
1346
1347 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1348 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1349 if (sas_device && (sas_device->starget == starget) &&
1350 (sas_device->id == starget->id) &&
1351 (sas_device->channel == starget->channel))
1352 sas_device->starget = NULL;
1353
1354 if (sas_device) {
1355
1356
1357
1358 sas_target_priv_data->sdev = NULL;
1359 sas_device_put(sas_device);
1360
1361 sas_device_put(sas_device);
1362 }
1363 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1364
1365 out:
1366 kfree(sas_target_priv_data);
1367 starget->hostdata = NULL;
1368}
1369
1370
1371
1372
1373
1374
1375
1376
1377static int
1378scsih_slave_alloc(struct scsi_device *sdev)
1379{
1380 struct Scsi_Host *shost;
1381 struct MPT3SAS_ADAPTER *ioc;
1382 struct MPT3SAS_TARGET *sas_target_priv_data;
1383 struct MPT3SAS_DEVICE *sas_device_priv_data;
1384 struct scsi_target *starget;
1385 struct _raid_device *raid_device;
1386 struct _sas_device *sas_device;
1387 unsigned long flags;
1388
1389 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1390 GFP_KERNEL);
1391 if (!sas_device_priv_data)
1392 return -ENOMEM;
1393
1394 sas_device_priv_data->lun = sdev->lun;
1395 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1396
1397 starget = scsi_target(sdev);
1398 sas_target_priv_data = starget->hostdata;
1399 sas_target_priv_data->num_luns++;
1400 sas_device_priv_data->sas_target = sas_target_priv_data;
1401 sdev->hostdata = sas_device_priv_data;
1402 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1403 sdev->no_uld_attach = 1;
1404
1405 shost = dev_to_shost(&starget->dev);
1406 ioc = shost_priv(shost);
1407 if (starget->channel == RAID_CHANNEL) {
1408 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1409 raid_device = _scsih_raid_device_find_by_id(ioc,
1410 starget->id, starget->channel);
1411 if (raid_device)
1412 raid_device->sdev = sdev;
1413 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1414 }
1415
1416 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1417 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1418 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1419 sas_target_priv_data->sas_address);
1420 if (sas_device && (sas_device->starget == NULL)) {
1421 sdev_printk(KERN_INFO, sdev,
1422 "%s : sas_device->starget set to starget @ %d\n",
1423 __func__, __LINE__);
1424 sas_device->starget = starget;
1425 }
1426
1427 if (sas_device)
1428 sas_device_put(sas_device);
1429
1430 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1431 }
1432
1433 return 0;
1434}
1435
1436
1437
1438
1439
1440
1441
1442static void
1443scsih_slave_destroy(struct scsi_device *sdev)
1444{
1445 struct MPT3SAS_TARGET *sas_target_priv_data;
1446 struct scsi_target *starget;
1447 struct Scsi_Host *shost;
1448 struct MPT3SAS_ADAPTER *ioc;
1449 struct _sas_device *sas_device;
1450 unsigned long flags;
1451
1452 if (!sdev->hostdata)
1453 return;
1454
1455 starget = scsi_target(sdev);
1456 sas_target_priv_data = starget->hostdata;
1457 sas_target_priv_data->num_luns--;
1458
1459 shost = dev_to_shost(&starget->dev);
1460 ioc = shost_priv(shost);
1461
1462 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1463 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1464 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1465 sas_target_priv_data);
1466 if (sas_device && !sas_target_priv_data->num_luns)
1467 sas_device->starget = NULL;
1468
1469 if (sas_device)
1470 sas_device_put(sas_device);
1471 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1472 }
1473
1474 kfree(sdev->hostdata);
1475 sdev->hostdata = NULL;
1476}
1477
1478
1479
1480
1481
1482
1483
1484static void
1485_scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1486 u16 handle, struct scsi_device *sdev)
1487{
1488 Mpi2ConfigReply_t mpi_reply;
1489 Mpi2SasDevicePage0_t sas_device_pg0;
1490 u32 ioc_status;
1491 u16 flags;
1492 u32 device_info;
1493
1494 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1495 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1496 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1497 ioc->name, __FILE__, __LINE__, __func__);
1498 return;
1499 }
1500
1501 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1502 MPI2_IOCSTATUS_MASK;
1503 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1504 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1505 ioc->name, __FILE__, __LINE__, __func__);
1506 return;
1507 }
1508
1509 flags = le16_to_cpu(sas_device_pg0.Flags);
1510 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1511
1512 sdev_printk(KERN_INFO, sdev,
1513 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1514 "sw_preserve(%s)\n",
1515 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1516 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1517 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1518 "n",
1519 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1520 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1521 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1522}
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535static int
1536scsih_is_raid(struct device *dev)
1537{
1538 struct scsi_device *sdev = to_scsi_device(dev);
1539 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1540
1541 if (ioc->is_warpdrive)
1542 return 0;
1543 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1544}
1545
1546
1547
1548
1549
1550static void
1551scsih_get_resync(struct device *dev)
1552{
1553 struct scsi_device *sdev = to_scsi_device(dev);
1554 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1555 static struct _raid_device *raid_device;
1556 unsigned long flags;
1557 Mpi2RaidVolPage0_t vol_pg0;
1558 Mpi2ConfigReply_t mpi_reply;
1559 u32 volume_status_flags;
1560 u8 percent_complete;
1561 u16 handle;
1562
1563 percent_complete = 0;
1564 handle = 0;
1565 if (ioc->is_warpdrive)
1566 goto out;
1567
1568 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1569 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1570 sdev->channel);
1571 if (raid_device) {
1572 handle = raid_device->handle;
1573 percent_complete = raid_device->percent_complete;
1574 }
1575 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1576
1577 if (!handle)
1578 goto out;
1579
1580 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1581 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1582 sizeof(Mpi2RaidVolPage0_t))) {
1583 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1584 ioc->name, __FILE__, __LINE__, __func__);
1585 percent_complete = 0;
1586 goto out;
1587 }
1588
1589 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1590 if (!(volume_status_flags &
1591 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1592 percent_complete = 0;
1593
1594 out:
1595
1596 switch (ioc->hba_mpi_version_belonged) {
1597 case MPI2_VERSION:
1598 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1599 break;
1600 case MPI25_VERSION:
1601 case MPI26_VERSION:
1602 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1603 break;
1604 }
1605}
1606
1607
1608
1609
1610
1611static void
1612scsih_get_state(struct device *dev)
1613{
1614 struct scsi_device *sdev = to_scsi_device(dev);
1615 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1616 static struct _raid_device *raid_device;
1617 unsigned long flags;
1618 Mpi2RaidVolPage0_t vol_pg0;
1619 Mpi2ConfigReply_t mpi_reply;
1620 u32 volstate;
1621 enum raid_state state = RAID_STATE_UNKNOWN;
1622 u16 handle = 0;
1623
1624 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1625 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1626 sdev->channel);
1627 if (raid_device)
1628 handle = raid_device->handle;
1629 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1630
1631 if (!raid_device)
1632 goto out;
1633
1634 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1635 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1636 sizeof(Mpi2RaidVolPage0_t))) {
1637 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1638 ioc->name, __FILE__, __LINE__, __func__);
1639 goto out;
1640 }
1641
1642 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1643 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1644 state = RAID_STATE_RESYNCING;
1645 goto out;
1646 }
1647
1648 switch (vol_pg0.VolumeState) {
1649 case MPI2_RAID_VOL_STATE_OPTIMAL:
1650 case MPI2_RAID_VOL_STATE_ONLINE:
1651 state = RAID_STATE_ACTIVE;
1652 break;
1653 case MPI2_RAID_VOL_STATE_DEGRADED:
1654 state = RAID_STATE_DEGRADED;
1655 break;
1656 case MPI2_RAID_VOL_STATE_FAILED:
1657 case MPI2_RAID_VOL_STATE_MISSING:
1658 state = RAID_STATE_OFFLINE;
1659 break;
1660 }
1661 out:
1662 switch (ioc->hba_mpi_version_belonged) {
1663 case MPI2_VERSION:
1664 raid_set_state(mpt2sas_raid_template, dev, state);
1665 break;
1666 case MPI25_VERSION:
1667 case MPI26_VERSION:
1668 raid_set_state(mpt3sas_raid_template, dev, state);
1669 break;
1670 }
1671}
1672
1673
1674
1675
1676
1677
1678static void
1679_scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1680 struct scsi_device *sdev, u8 volume_type)
1681{
1682 enum raid_level level = RAID_LEVEL_UNKNOWN;
1683
1684 switch (volume_type) {
1685 case MPI2_RAID_VOL_TYPE_RAID0:
1686 level = RAID_LEVEL_0;
1687 break;
1688 case MPI2_RAID_VOL_TYPE_RAID10:
1689 level = RAID_LEVEL_10;
1690 break;
1691 case MPI2_RAID_VOL_TYPE_RAID1E:
1692 level = RAID_LEVEL_1E;
1693 break;
1694 case MPI2_RAID_VOL_TYPE_RAID1:
1695 level = RAID_LEVEL_1;
1696 break;
1697 }
1698
1699 switch (ioc->hba_mpi_version_belonged) {
1700 case MPI2_VERSION:
1701 raid_set_level(mpt2sas_raid_template,
1702 &sdev->sdev_gendev, level);
1703 break;
1704 case MPI25_VERSION:
1705 case MPI26_VERSION:
1706 raid_set_level(mpt3sas_raid_template,
1707 &sdev->sdev_gendev, level);
1708 break;
1709 }
1710}
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720static int
1721_scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1722 struct _raid_device *raid_device)
1723{
1724 Mpi2RaidVolPage0_t *vol_pg0;
1725 Mpi2RaidPhysDiskPage0_t pd_pg0;
1726 Mpi2SasDevicePage0_t sas_device_pg0;
1727 Mpi2ConfigReply_t mpi_reply;
1728 u16 sz;
1729 u8 num_pds;
1730
1731 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1732 &num_pds)) || !num_pds) {
1733 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1734 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1735 __func__));
1736 return 1;
1737 }
1738
1739 raid_device->num_pds = num_pds;
1740 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1741 sizeof(Mpi2RaidVol0PhysDisk_t));
1742 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1743 if (!vol_pg0) {
1744 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1745 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1746 __func__));
1747 return 1;
1748 }
1749
1750 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1751 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1752 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1753 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1754 __func__));
1755 kfree(vol_pg0);
1756 return 1;
1757 }
1758
1759 raid_device->volume_type = vol_pg0->VolumeType;
1760
1761
1762
1763
1764 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1765 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1766 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1767 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1768 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1769 le16_to_cpu(pd_pg0.DevHandle)))) {
1770 raid_device->device_info =
1771 le32_to_cpu(sas_device_pg0.DeviceInfo);
1772 }
1773 }
1774
1775 kfree(vol_pg0);
1776 return 0;
1777}
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788static void
1789_scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1790{
1791
1792
1793 if (sdev->type != TYPE_TAPE)
1794 return;
1795
1796 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1797 return;
1798
1799 sas_enable_tlr(sdev);
1800 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1801 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1802 return;
1803
1804}
1805
1806
1807
1808
1809
1810
1811
1812
1813static int
1814scsih_slave_configure(struct scsi_device *sdev)
1815{
1816 struct Scsi_Host *shost = sdev->host;
1817 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1818 struct MPT3SAS_DEVICE *sas_device_priv_data;
1819 struct MPT3SAS_TARGET *sas_target_priv_data;
1820 struct _sas_device *sas_device;
1821 struct _raid_device *raid_device;
1822 unsigned long flags;
1823 int qdepth;
1824 u8 ssp_target = 0;
1825 char *ds = "";
1826 char *r_level = "";
1827 u16 handle, volume_handle = 0;
1828 u64 volume_wwid = 0;
1829
1830 qdepth = 1;
1831 sas_device_priv_data = sdev->hostdata;
1832 sas_device_priv_data->configured_lun = 1;
1833 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1834 sas_target_priv_data = sas_device_priv_data->sas_target;
1835 handle = sas_target_priv_data->handle;
1836
1837
1838 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1839
1840 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1841 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1842 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1843 if (!raid_device) {
1844 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1845 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1846 __LINE__, __func__));
1847 return 1;
1848 }
1849
1850 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1851 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1852 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1853 __LINE__, __func__));
1854 return 1;
1855 }
1856
1857
1858
1859
1860 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1861
1862
1863
1864
1865
1866
1867 if (raid_device->device_info &
1868 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1869 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1870 ds = "SSP";
1871 } else {
1872 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1873 if (raid_device->device_info &
1874 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1875 ds = "SATA";
1876 else
1877 ds = "STP";
1878 }
1879
1880 switch (raid_device->volume_type) {
1881 case MPI2_RAID_VOL_TYPE_RAID0:
1882 r_level = "RAID0";
1883 break;
1884 case MPI2_RAID_VOL_TYPE_RAID1E:
1885 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1886 if (ioc->manu_pg10.OEMIdentifier &&
1887 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1888 MFG10_GF0_R10_DISPLAY) &&
1889 !(raid_device->num_pds % 2))
1890 r_level = "RAID10";
1891 else
1892 r_level = "RAID1E";
1893 break;
1894 case MPI2_RAID_VOL_TYPE_RAID1:
1895 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1896 r_level = "RAID1";
1897 break;
1898 case MPI2_RAID_VOL_TYPE_RAID10:
1899 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1900 r_level = "RAID10";
1901 break;
1902 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1903 default:
1904 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1905 r_level = "RAIDX";
1906 break;
1907 }
1908
1909 if (!ioc->hide_ir_msg)
1910 sdev_printk(KERN_INFO, sdev,
1911 "%s: handle(0x%04x), wwid(0x%016llx),"
1912 " pd_count(%d), type(%s)\n",
1913 r_level, raid_device->handle,
1914 (unsigned long long)raid_device->wwid,
1915 raid_device->num_pds, ds);
1916
1917 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
1918 blk_queue_max_hw_sectors(sdev->request_queue,
1919 MPT3SAS_RAID_MAX_SECTORS);
1920 sdev_printk(KERN_INFO, sdev,
1921 "Set queue's max_sector to: %u\n",
1922 MPT3SAS_RAID_MAX_SECTORS);
1923 }
1924
1925 scsih_change_queue_depth(sdev, qdepth);
1926
1927
1928 if (!ioc->is_warpdrive)
1929 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1930 return 0;
1931 }
1932
1933
1934 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1935 if (mpt3sas_config_get_volume_handle(ioc, handle,
1936 &volume_handle)) {
1937 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1938 "failure at %s:%d/%s()!\n", ioc->name,
1939 __FILE__, __LINE__, __func__));
1940 return 1;
1941 }
1942 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1943 volume_handle, &volume_wwid)) {
1944 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1945 "failure at %s:%d/%s()!\n", ioc->name,
1946 __FILE__, __LINE__, __func__));
1947 return 1;
1948 }
1949 }
1950
1951 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1952 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1953 sas_device_priv_data->sas_target->sas_address);
1954 if (!sas_device) {
1955 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1956 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1957 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1958 __func__));
1959 return 1;
1960 }
1961
1962 sas_device->volume_handle = volume_handle;
1963 sas_device->volume_wwid = volume_wwid;
1964 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1965 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1966 ssp_target = 1;
1967 if (sas_device->device_info &
1968 MPI2_SAS_DEVICE_INFO_SEP) {
1969 sdev_printk(KERN_WARNING, sdev,
1970 "set ignore_delay_remove for handle(0x%04x)\n",
1971 sas_device_priv_data->sas_target->handle);
1972 sas_device_priv_data->ignore_delay_remove = 1;
1973 ds = "SES";
1974 } else
1975 ds = "SSP";
1976 } else {
1977 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1978 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1979 ds = "STP";
1980 else if (sas_device->device_info &
1981 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1982 ds = "SATA";
1983 }
1984
1985 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1986 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1987 ds, handle, (unsigned long long)sas_device->sas_address,
1988 sas_device->phy, (unsigned long long)sas_device->device_name);
1989 if (sas_device->enclosure_handle != 0)
1990 sdev_printk(KERN_INFO, sdev,
1991 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1992 ds, (unsigned long long)
1993 sas_device->enclosure_logical_id, sas_device->slot);
1994 if (sas_device->connector_name[0] != '\0')
1995 sdev_printk(KERN_INFO, sdev,
1996 "%s: enclosure level(0x%04x), connector name( %s)\n",
1997 ds, sas_device->enclosure_level,
1998 sas_device->connector_name);
1999
2000 sas_device_put(sas_device);
2001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2002
2003 if (!ssp_target)
2004 _scsih_display_sata_capabilities(ioc, handle, sdev);
2005
2006
2007 scsih_change_queue_depth(sdev, qdepth);
2008
2009 if (ssp_target) {
2010 sas_read_port_mode_page(sdev);
2011 _scsih_enable_tlr(ioc, sdev);
2012 }
2013
2014 return 0;
2015}
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029static int
2030scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2031 sector_t capacity, int params[])
2032{
2033 int heads;
2034 int sectors;
2035 sector_t cylinders;
2036 ulong dummy;
2037
2038 heads = 64;
2039 sectors = 32;
2040
2041 dummy = heads * sectors;
2042 cylinders = capacity;
2043 sector_div(cylinders, dummy);
2044
2045
2046
2047
2048
2049 if ((ulong)capacity >= 0x200000) {
2050 heads = 255;
2051 sectors = 63;
2052 dummy = heads * sectors;
2053 cylinders = capacity;
2054 sector_div(cylinders, dummy);
2055 }
2056
2057
2058 params[0] = heads;
2059 params[1] = sectors;
2060 params[2] = cylinders;
2061
2062 return 0;
2063}
2064
2065
2066
2067
2068
2069
2070
2071
2072static void
2073_scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2074{
2075 char *desc;
2076
2077 switch (response_code) {
2078 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2079 desc = "task management request completed";
2080 break;
2081 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2082 desc = "invalid frame";
2083 break;
2084 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2085 desc = "task management request not supported";
2086 break;
2087 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2088 desc = "task management request failed";
2089 break;
2090 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2091 desc = "task management request succeeded";
2092 break;
2093 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2094 desc = "invalid lun";
2095 break;
2096 case 0xA:
2097 desc = "overlapped tag attempted";
2098 break;
2099 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2100 desc = "task queued, however not sent to target";
2101 break;
2102 default:
2103 desc = "unknown";
2104 break;
2105 }
2106 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2107 ioc->name, response_code, desc);
2108}
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123static u8
2124_scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2125{
2126 MPI2DefaultReply_t *mpi_reply;
2127
2128 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2129 return 1;
2130 if (ioc->tm_cmds.smid != smid)
2131 return 1;
2132 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2133 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2134 if (mpi_reply) {
2135 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2136 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2137 }
2138 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2139 complete(&ioc->tm_cmds.done);
2140 return 1;
2141}
2142
2143
2144
2145
2146
2147
2148
2149
2150void
2151mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2152{
2153 struct MPT3SAS_DEVICE *sas_device_priv_data;
2154 struct scsi_device *sdev;
2155 u8 skip = 0;
2156
2157 shost_for_each_device(sdev, ioc->shost) {
2158 if (skip)
2159 continue;
2160 sas_device_priv_data = sdev->hostdata;
2161 if (!sas_device_priv_data)
2162 continue;
2163 if (sas_device_priv_data->sas_target->handle == handle) {
2164 sas_device_priv_data->sas_target->tm_busy = 1;
2165 skip = 1;
2166 ioc->ignore_loginfos = 1;
2167 }
2168 }
2169}
2170
2171
2172
2173
2174
2175
2176
2177
2178void
2179mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2180{
2181 struct MPT3SAS_DEVICE *sas_device_priv_data;
2182 struct scsi_device *sdev;
2183 u8 skip = 0;
2184
2185 shost_for_each_device(sdev, ioc->shost) {
2186 if (skip)
2187 continue;
2188 sas_device_priv_data = sdev->hostdata;
2189 if (!sas_device_priv_data)
2190 continue;
2191 if (sas_device_priv_data->sas_target->handle == handle) {
2192 sas_device_priv_data->sas_target->tm_busy = 0;
2193 skip = 1;
2194 ioc->ignore_loginfos = 0;
2195 }
2196 }
2197}
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217int
2218mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2219 uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2220{
2221 Mpi2SCSITaskManagementRequest_t *mpi_request;
2222 Mpi2SCSITaskManagementReply_t *mpi_reply;
2223 u16 smid = 0;
2224 u32 ioc_state;
2225 struct scsiio_tracker *scsi_lookup = NULL;
2226 int rc;
2227 u16 msix_task = 0;
2228
2229 lockdep_assert_held(&ioc->tm_cmds.mutex);
2230
2231 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2232 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2233 __func__, ioc->name);
2234 return FAILED;
2235 }
2236
2237 if (ioc->shost_recovery || ioc->remove_host ||
2238 ioc->pci_error_recovery) {
2239 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2240 __func__, ioc->name);
2241 return FAILED;
2242 }
2243
2244 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2245 if (ioc_state & MPI2_DOORBELL_USED) {
2246 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2247 "unexpected doorbell active!\n", ioc->name));
2248 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2249 return (!rc) ? SUCCESS : FAILED;
2250 }
2251
2252 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2253 mpt3sas_base_fault_info(ioc, ioc_state &
2254 MPI2_DOORBELL_DATA_MASK);
2255 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2256 return (!rc) ? SUCCESS : FAILED;
2257 }
2258
2259 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2260 if (!smid) {
2261 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2262 ioc->name, __func__);
2263 return FAILED;
2264 }
2265
2266 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2267 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2268
2269 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2270 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2271 ioc->name, handle, type, smid_task));
2272 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2273 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2274 ioc->tm_cmds.smid = smid;
2275 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2276 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2277 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2278 mpi_request->DevHandle = cpu_to_le16(handle);
2279 mpi_request->TaskType = type;
2280 mpi_request->TaskMID = cpu_to_le16(smid_task);
2281 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2282 mpt3sas_scsih_set_tm_flag(ioc, handle);
2283 init_completion(&ioc->tm_cmds.done);
2284 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2285 (scsi_lookup->msix_io < ioc->reply_queue_count))
2286 msix_task = scsi_lookup->msix_io;
2287 else
2288 msix_task = 0;
2289 ioc->put_smid_hi_priority(ioc, smid, msix_task);
2290 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2291 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2292 pr_err(MPT3SAS_FMT "%s: timeout\n",
2293 ioc->name, __func__);
2294 _debug_dump_mf(mpi_request,
2295 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2296 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2297 rc = mpt3sas_base_hard_reset_handler(ioc,
2298 FORCE_BIG_HAMMER);
2299 rc = (!rc) ? SUCCESS : FAILED;
2300 goto out;
2301 }
2302 }
2303
2304
2305 mpt3sas_base_sync_reply_irqs(ioc);
2306
2307 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2308 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2309 mpi_reply = ioc->tm_cmds.reply;
2310 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2311 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2312 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2313 le32_to_cpu(mpi_reply->IOCLogInfo),
2314 le32_to_cpu(mpi_reply->TerminationCount)));
2315 if (ioc->logging_level & MPT_DEBUG_TM) {
2316 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2317 if (mpi_reply->IOCStatus)
2318 _debug_dump_mf(mpi_request,
2319 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2320 }
2321 }
2322
2323 switch (type) {
2324 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2325 rc = SUCCESS;
2326 if (scsi_lookup->scmd == NULL)
2327 break;
2328 rc = FAILED;
2329 break;
2330
2331 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2332 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2333 rc = FAILED;
2334 else
2335 rc = SUCCESS;
2336 break;
2337 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2338 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2339 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2340 rc = FAILED;
2341 else
2342 rc = SUCCESS;
2343 break;
2344 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2345 rc = SUCCESS;
2346 break;
2347 default:
2348 rc = FAILED;
2349 break;
2350 }
2351
2352out:
2353 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2354 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2355 return rc;
2356}
2357
2358int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2359 uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2360{
2361 int ret;
2362
2363 mutex_lock(&ioc->tm_cmds.mutex);
2364 ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type,
2365 smid_task, timeout);
2366 mutex_unlock(&ioc->tm_cmds.mutex);
2367
2368 return ret;
2369}
2370
2371
2372
2373
2374
2375
2376
2377
2378static void
2379_scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2380{
2381 struct scsi_target *starget = scmd->device->sdev_target;
2382 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2383 struct _sas_device *sas_device = NULL;
2384 unsigned long flags;
2385 char *device_str = NULL;
2386
2387 if (!priv_target)
2388 return;
2389 if (ioc->hide_ir_msg)
2390 device_str = "WarpDrive";
2391 else
2392 device_str = "volume";
2393
2394 scsi_print_command(scmd);
2395 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2396 starget_printk(KERN_INFO, starget,
2397 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2398 device_str, priv_target->handle,
2399 device_str, (unsigned long long)priv_target->sas_address);
2400 } else {
2401 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2402 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2403 if (sas_device) {
2404 if (priv_target->flags &
2405 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2406 starget_printk(KERN_INFO, starget,
2407 "volume handle(0x%04x), "
2408 "volume wwid(0x%016llx)\n",
2409 sas_device->volume_handle,
2410 (unsigned long long)sas_device->volume_wwid);
2411 }
2412 starget_printk(KERN_INFO, starget,
2413 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2414 sas_device->handle,
2415 (unsigned long long)sas_device->sas_address,
2416 sas_device->phy);
2417 if (sas_device->enclosure_handle != 0)
2418 starget_printk(KERN_INFO, starget,
2419 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2420 (unsigned long long)
2421 sas_device->enclosure_logical_id,
2422 sas_device->slot);
2423 if (sas_device->connector_name[0] != '\0')
2424 starget_printk(KERN_INFO, starget,
2425 "enclosure level(0x%04x),connector name(%s)\n",
2426 sas_device->enclosure_level,
2427 sas_device->connector_name);
2428
2429 sas_device_put(sas_device);
2430 }
2431 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2432 }
2433}
2434
2435
2436
2437
2438
2439
2440
2441static int
2442scsih_abort(struct scsi_cmnd *scmd)
2443{
2444 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2445 struct MPT3SAS_DEVICE *sas_device_priv_data;
2446 u16 smid;
2447 u16 handle;
2448 int r;
2449
2450 sdev_printk(KERN_INFO, scmd->device,
2451 "attempting task abort! scmd(%p)\n", scmd);
2452 _scsih_tm_display_info(ioc, scmd);
2453
2454 sas_device_priv_data = scmd->device->hostdata;
2455 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2456 sdev_printk(KERN_INFO, scmd->device,
2457 "device been deleted! scmd(%p)\n", scmd);
2458 scmd->result = DID_NO_CONNECT << 16;
2459 scmd->scsi_done(scmd);
2460 r = SUCCESS;
2461 goto out;
2462 }
2463
2464
2465 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2466 if (!smid) {
2467 scmd->result = DID_RESET << 16;
2468 r = SUCCESS;
2469 goto out;
2470 }
2471
2472
2473 if (sas_device_priv_data->sas_target->flags &
2474 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2475 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2476 scmd->result = DID_RESET << 16;
2477 r = FAILED;
2478 goto out;
2479 }
2480
2481 mpt3sas_halt_firmware(ioc);
2482
2483 handle = sas_device_priv_data->sas_target->handle;
2484 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2485 scmd->device->id, scmd->device->lun,
2486 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
2487
2488 out:
2489 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2490 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2491 return r;
2492}
2493
2494
2495
2496
2497
2498
2499
2500static int
2501scsih_dev_reset(struct scsi_cmnd *scmd)
2502{
2503 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2504 struct MPT3SAS_DEVICE *sas_device_priv_data;
2505 struct _sas_device *sas_device = NULL;
2506 u16 handle;
2507 int r;
2508
2509 struct scsi_target *starget = scmd->device->sdev_target;
2510 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2511
2512 sdev_printk(KERN_INFO, scmd->device,
2513 "attempting device reset! scmd(%p)\n", scmd);
2514 _scsih_tm_display_info(ioc, scmd);
2515
2516 sas_device_priv_data = scmd->device->hostdata;
2517 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2518 sdev_printk(KERN_INFO, scmd->device,
2519 "device been deleted! scmd(%p)\n", scmd);
2520 scmd->result = DID_NO_CONNECT << 16;
2521 scmd->scsi_done(scmd);
2522 r = SUCCESS;
2523 goto out;
2524 }
2525
2526
2527 handle = 0;
2528 if (sas_device_priv_data->sas_target->flags &
2529 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2530 sas_device = mpt3sas_get_sdev_from_target(ioc,
2531 target_priv_data);
2532 if (sas_device)
2533 handle = sas_device->volume_handle;
2534 } else
2535 handle = sas_device_priv_data->sas_target->handle;
2536
2537 if (!handle) {
2538 scmd->result = DID_RESET << 16;
2539 r = FAILED;
2540 goto out;
2541 }
2542
2543 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2544 scmd->device->id, scmd->device->lun,
2545 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
2546
2547 out:
2548 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2549 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2550
2551 if (sas_device)
2552 sas_device_put(sas_device);
2553
2554 return r;
2555}
2556
2557
2558
2559
2560
2561
2562
2563static int
2564scsih_target_reset(struct scsi_cmnd *scmd)
2565{
2566 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2567 struct MPT3SAS_DEVICE *sas_device_priv_data;
2568 struct _sas_device *sas_device = NULL;
2569 u16 handle;
2570 int r;
2571 struct scsi_target *starget = scmd->device->sdev_target;
2572 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2573
2574 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2575 scmd);
2576 _scsih_tm_display_info(ioc, scmd);
2577
2578 sas_device_priv_data = scmd->device->hostdata;
2579 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2580 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2581 scmd);
2582 scmd->result = DID_NO_CONNECT << 16;
2583 scmd->scsi_done(scmd);
2584 r = SUCCESS;
2585 goto out;
2586 }
2587
2588
2589 handle = 0;
2590 if (sas_device_priv_data->sas_target->flags &
2591 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2592 sas_device = mpt3sas_get_sdev_from_target(ioc,
2593 target_priv_data);
2594 if (sas_device)
2595 handle = sas_device->volume_handle;
2596 } else
2597 handle = sas_device_priv_data->sas_target->handle;
2598
2599 if (!handle) {
2600 scmd->result = DID_RESET << 16;
2601 r = FAILED;
2602 goto out;
2603 }
2604
2605 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2606 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2607 30);
2608
2609 out:
2610 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2611 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2612
2613 if (sas_device)
2614 sas_device_put(sas_device);
2615
2616 return r;
2617}
2618
2619
2620
2621
2622
2623
2624
2625
2626static int
2627scsih_host_reset(struct scsi_cmnd *scmd)
2628{
2629 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2630 int r, retval;
2631
2632 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2633 ioc->name, scmd);
2634 scsi_print_command(scmd);
2635
2636 if (ioc->is_driver_loading) {
2637 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2638 ioc->name);
2639 r = FAILED;
2640 goto out;
2641 }
2642
2643 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2644 r = (retval < 0) ? FAILED : SUCCESS;
2645out:
2646 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2647 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2648
2649 return r;
2650}
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663static void
2664_scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2665{
2666 unsigned long flags;
2667
2668 if (ioc->firmware_event_thread == NULL)
2669 return;
2670
2671 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2672 fw_event_work_get(fw_event);
2673 INIT_LIST_HEAD(&fw_event->list);
2674 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2675 INIT_WORK(&fw_event->work, _firmware_event_work);
2676 fw_event_work_get(fw_event);
2677 queue_work(ioc->firmware_event_thread, &fw_event->work);
2678 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2679}
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691static void
2692_scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2693 *fw_event)
2694{
2695 unsigned long flags;
2696
2697 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2698 if (!list_empty(&fw_event->list)) {
2699 list_del_init(&fw_event->list);
2700 fw_event_work_put(fw_event);
2701 }
2702 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2703}
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713void
2714mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2715 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2716{
2717 struct fw_event_work *fw_event;
2718 u16 sz;
2719
2720 if (ioc->is_driver_loading)
2721 return;
2722 sz = sizeof(*event_data);
2723 fw_event = alloc_fw_event_work(sz);
2724 if (!fw_event)
2725 return;
2726 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2727 fw_event->ioc = ioc;
2728 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2729 _scsih_fw_event_add(ioc, fw_event);
2730 fw_event_work_put(fw_event);
2731}
2732
2733
2734
2735
2736
2737
2738
2739static void
2740_scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2741{
2742 struct fw_event_work *fw_event;
2743
2744 if (ioc->is_driver_loading)
2745 return;
2746 fw_event = alloc_fw_event_work(0);
2747 if (!fw_event)
2748 return;
2749 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2750 fw_event->ioc = ioc;
2751 _scsih_fw_event_add(ioc, fw_event);
2752 fw_event_work_put(fw_event);
2753}
2754
2755
2756
2757
2758
2759
2760
2761void
2762mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2763{
2764 struct fw_event_work *fw_event;
2765
2766 fw_event = alloc_fw_event_work(0);
2767 if (!fw_event)
2768 return;
2769 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2770 fw_event->ioc = ioc;
2771 _scsih_fw_event_add(ioc, fw_event);
2772 fw_event_work_put(fw_event);
2773}
2774
2775static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2776{
2777 unsigned long flags;
2778 struct fw_event_work *fw_event = NULL;
2779
2780 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2781 if (!list_empty(&ioc->fw_event_list)) {
2782 fw_event = list_first_entry(&ioc->fw_event_list,
2783 struct fw_event_work, list);
2784 list_del_init(&fw_event->list);
2785 }
2786 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2787
2788 return fw_event;
2789}
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800static void
2801_scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2802{
2803 struct fw_event_work *fw_event;
2804
2805 if (list_empty(&ioc->fw_event_list) ||
2806 !ioc->firmware_event_thread || in_interrupt())
2807 return;
2808
2809 while ((fw_event = dequeue_next_fw_event(ioc))) {
2810
2811
2812
2813
2814
2815
2816
2817
2818 if (cancel_work_sync(&fw_event->work))
2819 fw_event_work_put(fw_event);
2820
2821 fw_event_work_put(fw_event);
2822 }
2823}
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833static void
2834_scsih_internal_device_block(struct scsi_device *sdev,
2835 struct MPT3SAS_DEVICE *sas_device_priv_data)
2836{
2837 int r = 0;
2838
2839 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2840 sas_device_priv_data->sas_target->handle);
2841 sas_device_priv_data->block = 1;
2842
2843 r = scsi_internal_device_block(sdev);
2844 if (r == -EINVAL)
2845 sdev_printk(KERN_WARNING, sdev,
2846 "device_block failed with return(%d) for handle(0x%04x)\n",
2847 r, sas_device_priv_data->sas_target->handle);
2848}
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858static void
2859_scsih_internal_device_unblock(struct scsi_device *sdev,
2860 struct MPT3SAS_DEVICE *sas_device_priv_data)
2861{
2862 int r = 0;
2863
2864 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2865 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2866 sas_device_priv_data->block = 0;
2867 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2868 if (r == -EINVAL) {
2869
2870
2871
2872
2873
2874 sdev_printk(KERN_WARNING, sdev,
2875 "device_unblock failed with return(%d) for handle(0x%04x) "
2876 "performing a block followed by an unblock\n",
2877 r, sas_device_priv_data->sas_target->handle);
2878 sas_device_priv_data->block = 1;
2879 r = scsi_internal_device_block(sdev);
2880 if (r)
2881 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2882 "failed with return(%d) for handle(0x%04x)\n",
2883 r, sas_device_priv_data->sas_target->handle);
2884
2885 sas_device_priv_data->block = 0;
2886 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2887 if (r)
2888 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2889 " failed with return(%d) for handle(0x%04x)\n",
2890 r, sas_device_priv_data->sas_target->handle);
2891 }
2892}
2893
2894
2895
2896
2897
2898
2899
2900static void
2901_scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2902{
2903 struct MPT3SAS_DEVICE *sas_device_priv_data;
2904 struct scsi_device *sdev;
2905
2906 shost_for_each_device(sdev, ioc->shost) {
2907 sas_device_priv_data = sdev->hostdata;
2908 if (!sas_device_priv_data)
2909 continue;
2910 if (!sas_device_priv_data->block)
2911 continue;
2912
2913 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2914 "device_running, handle(0x%04x)\n",
2915 sas_device_priv_data->sas_target->handle));
2916 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2917 }
2918}
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928static void
2929_scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2930{
2931 struct MPT3SAS_DEVICE *sas_device_priv_data;
2932 struct scsi_device *sdev;
2933
2934 shost_for_each_device(sdev, ioc->shost) {
2935 sas_device_priv_data = sdev->hostdata;
2936 if (!sas_device_priv_data)
2937 continue;
2938 if (sas_device_priv_data->sas_target->sas_address
2939 != sas_address)
2940 continue;
2941 if (sas_device_priv_data->block)
2942 _scsih_internal_device_unblock(sdev,
2943 sas_device_priv_data);
2944 }
2945}
2946
2947
2948
2949
2950
2951
2952
2953
2954static void
2955_scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2956{
2957 struct MPT3SAS_DEVICE *sas_device_priv_data;
2958 struct scsi_device *sdev;
2959
2960 shost_for_each_device(sdev, ioc->shost) {
2961 sas_device_priv_data = sdev->hostdata;
2962 if (!sas_device_priv_data)
2963 continue;
2964 if (sas_device_priv_data->block)
2965 continue;
2966 if (sas_device_priv_data->ignore_delay_remove) {
2967 sdev_printk(KERN_INFO, sdev,
2968 "%s skip device_block for SES handle(0x%04x)\n",
2969 __func__, sas_device_priv_data->sas_target->handle);
2970 continue;
2971 }
2972 _scsih_internal_device_block(sdev, sas_device_priv_data);
2973 }
2974}
2975
2976
2977
2978
2979
2980
2981
2982
2983static void
2984_scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2985{
2986 struct MPT3SAS_DEVICE *sas_device_priv_data;
2987 struct scsi_device *sdev;
2988 struct _sas_device *sas_device;
2989
2990 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2991 if (!sas_device)
2992 return;
2993
2994 shost_for_each_device(sdev, ioc->shost) {
2995 sas_device_priv_data = sdev->hostdata;
2996 if (!sas_device_priv_data)
2997 continue;
2998 if (sas_device_priv_data->sas_target->handle != handle)
2999 continue;
3000 if (sas_device_priv_data->block)
3001 continue;
3002 if (sas_device->pend_sas_rphy_add)
3003 continue;
3004 if (sas_device_priv_data->ignore_delay_remove) {
3005 sdev_printk(KERN_INFO, sdev,
3006 "%s skip device_block for SES handle(0x%04x)\n",
3007 __func__, sas_device_priv_data->sas_target->handle);
3008 continue;
3009 }
3010 _scsih_internal_device_block(sdev, sas_device_priv_data);
3011 }
3012
3013 sas_device_put(sas_device);
3014}
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025static void
3026_scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3027 struct _sas_node *sas_expander)
3028{
3029 struct _sas_port *mpt3sas_port;
3030 struct _sas_device *sas_device;
3031 struct _sas_node *expander_sibling;
3032 unsigned long flags;
3033
3034 if (!sas_expander)
3035 return;
3036
3037 list_for_each_entry(mpt3sas_port,
3038 &sas_expander->sas_port_list, port_list) {
3039 if (mpt3sas_port->remote_identify.device_type ==
3040 SAS_END_DEVICE) {
3041 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3042 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3043 mpt3sas_port->remote_identify.sas_address);
3044 if (sas_device) {
3045 set_bit(sas_device->handle,
3046 ioc->blocking_handles);
3047 sas_device_put(sas_device);
3048 }
3049 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3050 }
3051 }
3052
3053 list_for_each_entry(mpt3sas_port,
3054 &sas_expander->sas_port_list, port_list) {
3055
3056 if (mpt3sas_port->remote_identify.device_type ==
3057 SAS_EDGE_EXPANDER_DEVICE ||
3058 mpt3sas_port->remote_identify.device_type ==
3059 SAS_FANOUT_EXPANDER_DEVICE) {
3060 expander_sibling =
3061 mpt3sas_scsih_expander_find_by_sas_address(
3062 ioc, mpt3sas_port->remote_identify.sas_address);
3063 _scsih_block_io_to_children_attached_to_ex(ioc,
3064 expander_sibling);
3065 }
3066 }
3067}
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077static void
3078_scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3079 Mpi2EventDataSasTopologyChangeList_t *event_data)
3080{
3081 int i;
3082 u16 handle;
3083 u16 reason_code;
3084
3085 for (i = 0; i < event_data->NumEntries; i++) {
3086 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3087 if (!handle)
3088 continue;
3089 reason_code = event_data->PHY[i].PhyStatus &
3090 MPI2_EVENT_SAS_TOPO_RC_MASK;
3091 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3092 _scsih_block_io_device(ioc, handle);
3093 }
3094}
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111static void
3112_scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3113{
3114 Mpi2SCSITaskManagementRequest_t *mpi_request;
3115 u16 smid;
3116 struct _sas_device *sas_device = NULL;
3117 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3118 u64 sas_address = 0;
3119 unsigned long flags;
3120 struct _tr_list *delayed_tr;
3121 u32 ioc_state;
3122
3123 if (ioc->remove_host) {
3124 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3125 "%s: host has been removed: handle(0x%04x)\n",
3126 __func__, ioc->name, handle));
3127 return;
3128 } else if (ioc->pci_error_recovery) {
3129 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3130 "%s: host in pci error recovery: handle(0x%04x)\n",
3131 __func__, ioc->name,
3132 handle));
3133 return;
3134 }
3135 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3136 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3137 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3138 "%s: host is not operational: handle(0x%04x)\n",
3139 __func__, ioc->name,
3140 handle));
3141 return;
3142 }
3143
3144
3145 if (test_bit(handle, ioc->pd_handles))
3146 return;
3147
3148 clear_bit(handle, ioc->pend_os_device_add);
3149
3150 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3151 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3152 if (sas_device && sas_device->starget &&
3153 sas_device->starget->hostdata) {
3154 sas_target_priv_data = sas_device->starget->hostdata;
3155 sas_target_priv_data->deleted = 1;
3156 sas_address = sas_device->sas_address;
3157 }
3158 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3159
3160 if (sas_target_priv_data) {
3161 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3162 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3163 ioc->name, handle,
3164 (unsigned long long)sas_address));
3165 if (sas_device->enclosure_handle != 0)
3166 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3167 "setting delete flag:enclosure logical id(0x%016llx),"
3168 " slot(%d)\n", ioc->name, (unsigned long long)
3169 sas_device->enclosure_logical_id,
3170 sas_device->slot));
3171 if (sas_device->connector_name[0] != '\0')
3172 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3173 "setting delete flag: enclosure level(0x%04x),"
3174 " connector name( %s)\n", ioc->name,
3175 sas_device->enclosure_level,
3176 sas_device->connector_name));
3177 _scsih_ublock_io_device(ioc, sas_address);
3178 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3179 }
3180
3181 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3182 if (!smid) {
3183 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3184 if (!delayed_tr)
3185 goto out;
3186 INIT_LIST_HEAD(&delayed_tr->list);
3187 delayed_tr->handle = handle;
3188 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3189 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3190 "DELAYED:tr:handle(0x%04x), (open)\n",
3191 ioc->name, handle));
3192 goto out;
3193 }
3194
3195 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3196 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3197 ioc->name, handle, smid,
3198 ioc->tm_tr_cb_idx));
3199 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3200 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3201 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3202 mpi_request->DevHandle = cpu_to_le16(handle);
3203 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3204 set_bit(handle, ioc->device_remove_in_progress);
3205 ioc->put_smid_hi_priority(ioc, smid, 0);
3206 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3207
3208out:
3209 if (sas_device)
3210 sas_device_put(sas_device);
3211}
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229static u8
3230_scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3231 u32 reply)
3232{
3233 u16 handle;
3234 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3235 Mpi2SCSITaskManagementReply_t *mpi_reply =
3236 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3237 Mpi2SasIoUnitControlRequest_t *mpi_request;
3238 u16 smid_sas_ctrl;
3239 u32 ioc_state;
3240 struct _sc_list *delayed_sc;
3241
3242 if (ioc->remove_host) {
3243 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3244 "%s: host has been removed\n", __func__, ioc->name));
3245 return 1;
3246 } else if (ioc->pci_error_recovery) {
3247 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3248 "%s: host in pci error recovery\n", __func__,
3249 ioc->name));
3250 return 1;
3251 }
3252 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3253 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3254 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3255 "%s: host is not operational\n", __func__, ioc->name));
3256 return 1;
3257 }
3258 if (unlikely(!mpi_reply)) {
3259 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3260 ioc->name, __FILE__, __LINE__, __func__);
3261 return 1;
3262 }
3263 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3264 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3265 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3266 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3267 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3268 ioc->name, handle,
3269 le16_to_cpu(mpi_reply->DevHandle), smid));
3270 return 0;
3271 }
3272
3273 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3274 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3275 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3276 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3277 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3278 le32_to_cpu(mpi_reply->IOCLogInfo),
3279 le32_to_cpu(mpi_reply->TerminationCount)));
3280
3281 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3282 if (!smid_sas_ctrl) {
3283 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3284 if (!delayed_sc)
3285 return _scsih_check_for_pending_tm(ioc, smid);
3286 INIT_LIST_HEAD(&delayed_sc->list);
3287 delayed_sc->handle = mpi_request_tm->DevHandle;
3288 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3289 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3290 "DELAYED:sc:handle(0x%04x), (open)\n",
3291 ioc->name, handle));
3292 return _scsih_check_for_pending_tm(ioc, smid);
3293 }
3294
3295 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3296 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3297 ioc->name, handle, smid_sas_ctrl,
3298 ioc->tm_sas_control_cb_idx));
3299 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3300 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3301 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3302 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3303 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3304 ioc->put_smid_default(ioc, smid_sas_ctrl);
3305
3306 return _scsih_check_for_pending_tm(ioc, smid);
3307}
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325static u8
3326_scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3327 u8 msix_index, u32 reply)
3328{
3329 Mpi2SasIoUnitControlReply_t *mpi_reply =
3330 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3331
3332 if (likely(mpi_reply)) {
3333 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3334 "sc_complete:handle(0x%04x), (open) "
3335 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3336 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3337 le16_to_cpu(mpi_reply->IOCStatus),
3338 le32_to_cpu(mpi_reply->IOCLogInfo)));
3339 if (le16_to_cpu(mpi_reply->IOCStatus) ==
3340 MPI2_IOCSTATUS_SUCCESS) {
3341 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
3342 ioc->device_remove_in_progress);
3343 }
3344 } else {
3345 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3346 ioc->name, __FILE__, __LINE__, __func__);
3347 }
3348 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3349}
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361static void
3362_scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3363{
3364 Mpi2SCSITaskManagementRequest_t *mpi_request;
3365 u16 smid;
3366 struct _tr_list *delayed_tr;
3367
3368 if (ioc->shost_recovery || ioc->remove_host ||
3369 ioc->pci_error_recovery) {
3370 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3371 "%s: host reset in progress!\n",
3372 __func__, ioc->name));
3373 return;
3374 }
3375
3376 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3377 if (!smid) {
3378 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3379 if (!delayed_tr)
3380 return;
3381 INIT_LIST_HEAD(&delayed_tr->list);
3382 delayed_tr->handle = handle;
3383 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3384 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3385 "DELAYED:tr:handle(0x%04x), (open)\n",
3386 ioc->name, handle));
3387 return;
3388 }
3389
3390 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3391 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3392 ioc->name, handle, smid,
3393 ioc->tm_tr_volume_cb_idx));
3394 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3395 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3396 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3397 mpi_request->DevHandle = cpu_to_le16(handle);
3398 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3399 ioc->put_smid_hi_priority(ioc, smid, 0);
3400}
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413static u8
3414_scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3415 u8 msix_index, u32 reply)
3416{
3417 u16 handle;
3418 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3419 Mpi2SCSITaskManagementReply_t *mpi_reply =
3420 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3421
3422 if (ioc->shost_recovery || ioc->remove_host ||
3423 ioc->pci_error_recovery) {
3424 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3425 "%s: host reset in progress!\n",
3426 __func__, ioc->name));
3427 return 1;
3428 }
3429 if (unlikely(!mpi_reply)) {
3430 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3431 ioc->name, __FILE__, __LINE__, __func__);
3432 return 1;
3433 }
3434
3435 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3436 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3437 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3438 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3439 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3440 ioc->name, handle,
3441 le16_to_cpu(mpi_reply->DevHandle), smid));
3442 return 0;
3443 }
3444
3445 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3446 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3447 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3448 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3449 le32_to_cpu(mpi_reply->IOCLogInfo),
3450 le32_to_cpu(mpi_reply->TerminationCount)));
3451
3452 return _scsih_check_for_pending_tm(ioc, smid);
3453}
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464static void
3465_scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event,
3466 u32 event_context)
3467{
3468 Mpi2EventAckRequest_t *ack_request;
3469 int i = smid - ioc->internal_smid;
3470 unsigned long flags;
3471
3472
3473
3474
3475
3476 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3477 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3478 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3479
3480 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3481 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3482 ioc->name, le16_to_cpu(event), smid,
3483 ioc->base_cb_idx));
3484 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3485 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3486 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3487 ack_request->Event = event;
3488 ack_request->EventContext = event_context;
3489 ack_request->VF_ID = 0;
3490 ack_request->VP_ID = 0;
3491 ioc->put_smid_default(ioc, smid);
3492}
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503static void
3504_scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3505 u16 smid, u16 handle)
3506 {
3507 Mpi2SasIoUnitControlRequest_t *mpi_request;
3508 u32 ioc_state;
3509 int i = smid - ioc->internal_smid;
3510 unsigned long flags;
3511
3512 if (ioc->remove_host) {
3513 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3514 "%s: host has been removed\n",
3515 __func__, ioc->name));
3516 return;
3517 } else if (ioc->pci_error_recovery) {
3518 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3519 "%s: host in pci error recovery\n",
3520 __func__, ioc->name));
3521 return;
3522 }
3523 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3524 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3525 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3526 "%s: host is not operational\n",
3527 __func__, ioc->name));
3528 return;
3529 }
3530
3531
3532
3533
3534
3535 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3536 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
3537 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3538
3539 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3540 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3541 ioc->name, le16_to_cpu(handle), smid,
3542 ioc->tm_sas_control_cb_idx));
3543 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3544 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3545 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3546 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3547 mpi_request->DevHandle = handle;
3548 ioc->put_smid_default(ioc, smid);
3549}
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564u8
3565mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3566{
3567 struct _sc_list *delayed_sc;
3568 struct _event_ack_list *delayed_event_ack;
3569
3570 if (!list_empty(&ioc->delayed_event_ack_list)) {
3571 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
3572 struct _event_ack_list, list);
3573 _scsih_issue_delayed_event_ack(ioc, smid,
3574 delayed_event_ack->Event, delayed_event_ack->EventContext);
3575 list_del(&delayed_event_ack->list);
3576 kfree(delayed_event_ack);
3577 return 0;
3578 }
3579
3580 if (!list_empty(&ioc->delayed_sc_list)) {
3581 delayed_sc = list_entry(ioc->delayed_sc_list.next,
3582 struct _sc_list, list);
3583 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
3584 delayed_sc->handle);
3585 list_del(&delayed_sc->list);
3586 kfree(delayed_sc);
3587 return 0;
3588 }
3589 return 1;
3590}
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603static u8
3604_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3605{
3606 struct _tr_list *delayed_tr;
3607
3608 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3609 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3610 struct _tr_list, list);
3611 mpt3sas_base_free_smid(ioc, smid);
3612 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3613 list_del(&delayed_tr->list);
3614 kfree(delayed_tr);
3615 return 0;
3616 }
3617
3618 if (!list_empty(&ioc->delayed_tr_list)) {
3619 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3620 struct _tr_list, list);
3621 mpt3sas_base_free_smid(ioc, smid);
3622 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3623 list_del(&delayed_tr->list);
3624 kfree(delayed_tr);
3625 return 0;
3626 }
3627
3628 return 1;
3629}
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644static void
3645_scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3646 Mpi2EventDataSasTopologyChangeList_t *event_data)
3647{
3648 struct fw_event_work *fw_event;
3649 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3650 u16 expander_handle;
3651 struct _sas_node *sas_expander;
3652 unsigned long flags;
3653 int i, reason_code;
3654 u16 handle;
3655
3656 for (i = 0 ; i < event_data->NumEntries; i++) {
3657 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3658 if (!handle)
3659 continue;
3660 reason_code = event_data->PHY[i].PhyStatus &
3661 MPI2_EVENT_SAS_TOPO_RC_MASK;
3662 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3663 _scsih_tm_tr_send(ioc, handle);
3664 }
3665
3666 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3667 if (expander_handle < ioc->sas_hba.num_phys) {
3668 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3669 return;
3670 }
3671 if (event_data->ExpStatus ==
3672 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3673
3674 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3675 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3676 expander_handle);
3677 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3678 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3679 do {
3680 handle = find_first_bit(ioc->blocking_handles,
3681 ioc->facts.MaxDevHandle);
3682 if (handle < ioc->facts.MaxDevHandle)
3683 _scsih_block_io_device(ioc, handle);
3684 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3685 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3686 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3687
3688 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3689 return;
3690
3691
3692 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3693 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3694 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3695 fw_event->ignore)
3696 continue;
3697 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3698 fw_event->event_data;
3699 if (local_event_data->ExpStatus ==
3700 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3701 local_event_data->ExpStatus ==
3702 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3703 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3704 expander_handle) {
3705 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3706 "setting ignoring flag\n", ioc->name));
3707 fw_event->ignore = 1;
3708 }
3709 }
3710 }
3711 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3712}
3713
3714
3715
3716
3717
3718
3719
3720
3721static void
3722_scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3723{
3724 struct _raid_device *raid_device;
3725 struct MPT3SAS_TARGET *sas_target_priv_data;
3726 unsigned long flags;
3727
3728 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3729 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3730 if (raid_device && raid_device->starget &&
3731 raid_device->starget->hostdata) {
3732 sas_target_priv_data =
3733 raid_device->starget->hostdata;
3734 sas_target_priv_data->deleted = 1;
3735 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3736 "setting delete flag: handle(0x%04x), "
3737 "wwid(0x%016llx)\n", ioc->name, handle,
3738 (unsigned long long) raid_device->wwid));
3739 }
3740 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3741}
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753static void
3754_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3755{
3756 if (!handle || handle == *a || handle == *b)
3757 return;
3758 if (!*a)
3759 *a = handle;
3760 else if (!*b)
3761 *b = handle;
3762}
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778static void
3779_scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3780 Mpi2EventDataIrConfigChangeList_t *event_data)
3781{
3782 Mpi2EventIrConfigElement_t *element;
3783 int i;
3784 u16 handle, volume_handle, a, b;
3785 struct _tr_list *delayed_tr;
3786
3787 a = 0;
3788 b = 0;
3789
3790 if (ioc->is_warpdrive)
3791 return;
3792
3793
3794 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3795 for (i = 0; i < event_data->NumElements; i++, element++) {
3796 if (le32_to_cpu(event_data->Flags) &
3797 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3798 continue;
3799 if (element->ReasonCode ==
3800 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3801 element->ReasonCode ==
3802 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3803 volume_handle = le16_to_cpu(element->VolDevHandle);
3804 _scsih_set_volume_delete_flag(ioc, volume_handle);
3805 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3806 }
3807 }
3808
3809
3810 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3811 for (i = 0; i < event_data->NumElements; i++, element++) {
3812 if (le32_to_cpu(event_data->Flags) &
3813 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3814 continue;
3815 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3816 volume_handle = le16_to_cpu(element->VolDevHandle);
3817 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3818 }
3819 }
3820
3821 if (a)
3822 _scsih_tm_tr_volume_send(ioc, a);
3823 if (b)
3824 _scsih_tm_tr_volume_send(ioc, b);
3825
3826
3827 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3828 for (i = 0; i < event_data->NumElements; i++, element++) {
3829 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3830 continue;
3831 handle = le16_to_cpu(element->PhysDiskDevHandle);
3832 volume_handle = le16_to_cpu(element->VolDevHandle);
3833 clear_bit(handle, ioc->pd_handles);
3834 if (!volume_handle)
3835 _scsih_tm_tr_send(ioc, handle);
3836 else if (volume_handle == a || volume_handle == b) {
3837 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3838 BUG_ON(!delayed_tr);
3839 INIT_LIST_HEAD(&delayed_tr->list);
3840 delayed_tr->handle = handle;
3841 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3842 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3843 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3844 handle));
3845 } else
3846 _scsih_tm_tr_send(ioc, handle);
3847 }
3848}
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863static void
3864_scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3865 Mpi2EventDataIrVolume_t *event_data)
3866{
3867 u32 state;
3868
3869 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3870 return;
3871 state = le32_to_cpu(event_data->NewValue);
3872 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3873 MPI2_RAID_VOL_STATE_FAILED)
3874 _scsih_set_volume_delete_flag(ioc,
3875 le16_to_cpu(event_data->VolDevHandle));
3876}
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886static void
3887_scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3888 Mpi2EventDataTemperature_t *event_data)
3889{
3890 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3891 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3892 " exceeded for Sensor: %d !!!\n", ioc->name,
3893 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3894 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3895 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3896 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3897 event_data->SensorNum);
3898 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3899 ioc->name, event_data->CurrentTemperature);
3900 }
3901}
3902
3903static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
3904{
3905 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
3906
3907 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
3908 return 0;
3909
3910 if (pending)
3911 return test_and_set_bit(0, &priv->ata_command_pending);
3912
3913 clear_bit(0, &priv->ata_command_pending);
3914 return 0;
3915}
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926static void
3927_scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3928{
3929 struct scsi_cmnd *scmd;
3930 u16 smid;
3931 u16 count = 0;
3932
3933 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3934 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3935 if (!scmd)
3936 continue;
3937 count++;
3938 _scsih_set_satl_pending(scmd, false);
3939 mpt3sas_base_free_smid(ioc, smid);
3940 scsi_dma_unmap(scmd);
3941 if (ioc->pci_error_recovery)
3942 scmd->result = DID_NO_CONNECT << 16;
3943 else
3944 scmd->result = DID_RESET << 16;
3945 scmd->scsi_done(scmd);
3946 }
3947 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3948 ioc->name, count));
3949}
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961static void
3962_scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3963 Mpi2SCSIIORequest_t *mpi_request)
3964{
3965 u16 eedp_flags;
3966 unsigned char prot_op = scsi_get_prot_op(scmd);
3967 unsigned char prot_type = scsi_get_prot_type(scmd);
3968 Mpi25SCSIIORequest_t *mpi_request_3v =
3969 (Mpi25SCSIIORequest_t *)mpi_request;
3970
3971 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3972 return;
3973
3974 if (prot_op == SCSI_PROT_READ_STRIP)
3975 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3976 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3977 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3978 else
3979 return;
3980
3981 switch (prot_type) {
3982 case SCSI_PROT_DIF_TYPE1:
3983 case SCSI_PROT_DIF_TYPE2:
3984
3985
3986
3987
3988
3989 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3990 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3991 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3992 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3993 cpu_to_be32(scsi_prot_ref_tag(scmd));
3994 break;
3995
3996 case SCSI_PROT_DIF_TYPE3:
3997
3998
3999
4000
4001 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4002
4003 break;
4004 }
4005
4006 mpi_request_3v->EEDPBlockSize =
4007 cpu_to_le16(scmd->device->sector_size);
4008
4009 if (ioc->is_gen35_ioc)
4010 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
4011 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4012}
4013
4014
4015
4016
4017
4018
4019
4020
4021static void
4022_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4023{
4024 u8 ascq;
4025
4026 switch (ioc_status) {
4027 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4028 ascq = 0x01;
4029 break;
4030 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4031 ascq = 0x02;
4032 break;
4033 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4034 ascq = 0x03;
4035 break;
4036 default:
4037 ascq = 0x00;
4038 break;
4039 }
4040 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4041 ascq);
4042 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4043 SAM_STAT_CHECK_CONDITION;
4044}
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057static int
4058scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4059{
4060 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4061 struct MPT3SAS_DEVICE *sas_device_priv_data;
4062 struct MPT3SAS_TARGET *sas_target_priv_data;
4063 struct _raid_device *raid_device;
4064 struct request *rq = scmd->request;
4065 int class;
4066 Mpi2SCSIIORequest_t *mpi_request;
4067 u32 mpi_control;
4068 u16 smid;
4069 u16 handle;
4070
4071 if (ioc->logging_level & MPT_DEBUG_SCSI)
4072 scsi_print_command(scmd);
4073
4074 sas_device_priv_data = scmd->device->hostdata;
4075 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4076 scmd->result = DID_NO_CONNECT << 16;
4077 scmd->scsi_done(scmd);
4078 return 0;
4079 }
4080
4081 if (ioc->pci_error_recovery || ioc->remove_host) {
4082 scmd->result = DID_NO_CONNECT << 16;
4083 scmd->scsi_done(scmd);
4084 return 0;
4085 }
4086
4087
4088
4089
4090
4091
4092 do {
4093 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
4094 scmd->result = SAM_STAT_BUSY;
4095 scmd->scsi_done(scmd);
4096 return 0;
4097 }
4098 } while (_scsih_set_satl_pending(scmd, true));
4099
4100 sas_target_priv_data = sas_device_priv_data->sas_target;
4101
4102
4103 handle = sas_target_priv_data->handle;
4104 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4105 scmd->result = DID_NO_CONNECT << 16;
4106 scmd->scsi_done(scmd);
4107 return 0;
4108 }
4109
4110
4111
4112 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4113 return SCSI_MLQUEUE_HOST_BUSY;
4114
4115
4116 else if (sas_target_priv_data->deleted) {
4117 scmd->result = DID_NO_CONNECT << 16;
4118 scmd->scsi_done(scmd);
4119 return 0;
4120
4121 } else if (sas_target_priv_data->tm_busy ||
4122 sas_device_priv_data->block)
4123 return SCSI_MLQUEUE_DEVICE_BUSY;
4124
4125 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4126 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4127 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4128 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4129 else
4130 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4131
4132
4133 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4134
4135 if (sas_device_priv_data->ncq_prio_enable) {
4136 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
4137 if (class == IOPRIO_CLASS_RT)
4138 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
4139 }
4140
4141
4142
4143 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
4144 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4145 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4146
4147 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4148 if (!smid) {
4149 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4150 ioc->name, __func__);
4151 goto out;
4152 }
4153 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4154 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4155 _scsih_setup_eedp(ioc, scmd, mpi_request);
4156
4157 if (scmd->cmd_len == 32)
4158 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4159 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4160 if (sas_device_priv_data->sas_target->flags &
4161 MPT_TARGET_FLAGS_RAID_COMPONENT)
4162 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4163 else
4164 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4165 mpi_request->DevHandle = cpu_to_le16(handle);
4166 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4167 mpi_request->Control = cpu_to_le32(mpi_control);
4168 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4169 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4170 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4171 mpi_request->SenseBufferLowAddress =
4172 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4173 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4174 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4175 mpi_request->LUN);
4176 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4177
4178 if (mpi_request->DataLength) {
4179 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
4180 mpt3sas_base_free_smid(ioc, smid);
4181 goto out;
4182 }
4183 } else
4184 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4185
4186 raid_device = sas_target_priv_data->raid_device;
4187 if (raid_device && raid_device->direct_io_enabled)
4188 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4189 smid);
4190
4191 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4192 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4193 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4194 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4195 ioc->put_smid_fast_path(ioc, smid, handle);
4196 } else
4197 ioc->put_smid_scsi_io(ioc, smid,
4198 le16_to_cpu(mpi_request->DevHandle));
4199 } else
4200 ioc->put_smid_default(ioc, smid);
4201 return 0;
4202
4203 out:
4204 return SCSI_MLQUEUE_HOST_BUSY;
4205}
4206
4207
4208
4209
4210
4211
4212
4213
4214static void
4215_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4216{
4217 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4218
4219 data->skey = sense_buffer[1] & 0x0F;
4220 data->asc = sense_buffer[2];
4221 data->ascq = sense_buffer[3];
4222 } else {
4223
4224 data->skey = sense_buffer[2] & 0x0F;
4225 data->asc = sense_buffer[12];
4226 data->ascq = sense_buffer[13];
4227 }
4228}
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242static void
4243_scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4244 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4245{
4246 u32 response_info;
4247 u8 *response_bytes;
4248 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4249 MPI2_IOCSTATUS_MASK;
4250 u8 scsi_state = mpi_reply->SCSIState;
4251 u8 scsi_status = mpi_reply->SCSIStatus;
4252 char *desc_ioc_state = NULL;
4253 char *desc_scsi_status = NULL;
4254 char *desc_scsi_state = ioc->tmp_string;
4255 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4256 struct _sas_device *sas_device = NULL;
4257 struct scsi_target *starget = scmd->device->sdev_target;
4258 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4259 char *device_str = NULL;
4260
4261 if (!priv_target)
4262 return;
4263 if (ioc->hide_ir_msg)
4264 device_str = "WarpDrive";
4265 else
4266 device_str = "volume";
4267
4268 if (log_info == 0x31170000)
4269 return;
4270
4271 switch (ioc_status) {
4272 case MPI2_IOCSTATUS_SUCCESS:
4273 desc_ioc_state = "success";
4274 break;
4275 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4276 desc_ioc_state = "invalid function";
4277 break;
4278 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4279 desc_ioc_state = "scsi recovered error";
4280 break;
4281 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4282 desc_ioc_state = "scsi invalid dev handle";
4283 break;
4284 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4285 desc_ioc_state = "scsi device not there";
4286 break;
4287 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4288 desc_ioc_state = "scsi data overrun";
4289 break;
4290 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4291 desc_ioc_state = "scsi data underrun";
4292 break;
4293 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4294 desc_ioc_state = "scsi io data error";
4295 break;
4296 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4297 desc_ioc_state = "scsi protocol error";
4298 break;
4299 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4300 desc_ioc_state = "scsi task terminated";
4301 break;
4302 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4303 desc_ioc_state = "scsi residual mismatch";
4304 break;
4305 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4306 desc_ioc_state = "scsi task mgmt failed";
4307 break;
4308 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4309 desc_ioc_state = "scsi ioc terminated";
4310 break;
4311 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4312 desc_ioc_state = "scsi ext terminated";
4313 break;
4314 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4315 desc_ioc_state = "eedp guard error";
4316 break;
4317 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4318 desc_ioc_state = "eedp ref tag error";
4319 break;
4320 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4321 desc_ioc_state = "eedp app tag error";
4322 break;
4323 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4324 desc_ioc_state = "insufficient power";
4325 break;
4326 default:
4327 desc_ioc_state = "unknown";
4328 break;
4329 }
4330
4331 switch (scsi_status) {
4332 case MPI2_SCSI_STATUS_GOOD:
4333 desc_scsi_status = "good";
4334 break;
4335 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4336 desc_scsi_status = "check condition";
4337 break;
4338 case MPI2_SCSI_STATUS_CONDITION_MET:
4339 desc_scsi_status = "condition met";
4340 break;
4341 case MPI2_SCSI_STATUS_BUSY:
4342 desc_scsi_status = "busy";
4343 break;
4344 case MPI2_SCSI_STATUS_INTERMEDIATE:
4345 desc_scsi_status = "intermediate";
4346 break;
4347 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4348 desc_scsi_status = "intermediate condmet";
4349 break;
4350 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4351 desc_scsi_status = "reservation conflict";
4352 break;
4353 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4354 desc_scsi_status = "command terminated";
4355 break;
4356 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4357 desc_scsi_status = "task set full";
4358 break;
4359 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4360 desc_scsi_status = "aca active";
4361 break;
4362 case MPI2_SCSI_STATUS_TASK_ABORTED:
4363 desc_scsi_status = "task aborted";
4364 break;
4365 default:
4366 desc_scsi_status = "unknown";
4367 break;
4368 }
4369
4370 desc_scsi_state[0] = '\0';
4371 if (!scsi_state)
4372 desc_scsi_state = " ";
4373 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4374 strcat(desc_scsi_state, "response info ");
4375 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4376 strcat(desc_scsi_state, "state terminated ");
4377 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4378 strcat(desc_scsi_state, "no status ");
4379 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4380 strcat(desc_scsi_state, "autosense failed ");
4381 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4382 strcat(desc_scsi_state, "autosense valid ");
4383
4384 scsi_print_command(scmd);
4385
4386 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4387 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4388 device_str, (unsigned long long)priv_target->sas_address);
4389 } else {
4390 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4391 if (sas_device) {
4392 pr_warn(MPT3SAS_FMT
4393 "\tsas_address(0x%016llx), phy(%d)\n",
4394 ioc->name, (unsigned long long)
4395 sas_device->sas_address, sas_device->phy);
4396 if (sas_device->enclosure_handle != 0)
4397 pr_warn(MPT3SAS_FMT
4398 "\tenclosure_logical_id(0x%016llx),"
4399 "slot(%d)\n", ioc->name,
4400 (unsigned long long)
4401 sas_device->enclosure_logical_id,
4402 sas_device->slot);
4403 if (sas_device->connector_name[0])
4404 pr_warn(MPT3SAS_FMT
4405 "\tenclosure level(0x%04x),"
4406 " connector name( %s)\n", ioc->name,
4407 sas_device->enclosure_level,
4408 sas_device->connector_name);
4409
4410 sas_device_put(sas_device);
4411 }
4412 }
4413
4414 pr_warn(MPT3SAS_FMT
4415 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4416 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4417 desc_ioc_state, ioc_status, smid);
4418 pr_warn(MPT3SAS_FMT
4419 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4420 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4421 scsi_get_resid(scmd));
4422 pr_warn(MPT3SAS_FMT
4423 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4424 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4425 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4426 pr_warn(MPT3SAS_FMT
4427 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4428 ioc->name, desc_scsi_status,
4429 scsi_status, desc_scsi_state, scsi_state);
4430
4431 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4432 struct sense_info data;
4433 _scsih_normalize_sense(scmd->sense_buffer, &data);
4434 pr_warn(MPT3SAS_FMT
4435 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4436 ioc->name, data.skey,
4437 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4438 }
4439
4440 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4441 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4442 response_bytes = (u8 *)&response_info;
4443 _scsih_response_code(ioc, response_bytes[0]);
4444 }
4445}
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455static void
4456_scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4457{
4458 Mpi2SepReply_t mpi_reply;
4459 Mpi2SepRequest_t mpi_request;
4460 struct _sas_device *sas_device;
4461
4462 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4463 if (!sas_device)
4464 return;
4465
4466 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4467 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4468 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4469 mpi_request.SlotStatus =
4470 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4471 mpi_request.DevHandle = cpu_to_le16(handle);
4472 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4473 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4474 &mpi_request)) != 0) {
4475 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4476 __FILE__, __LINE__, __func__);
4477 goto out;
4478 }
4479 sas_device->pfa_led_on = 1;
4480
4481 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4482 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4483 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4484 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4485 le32_to_cpu(mpi_reply.IOCLogInfo)));
4486 goto out;
4487 }
4488out:
4489 sas_device_put(sas_device);
4490}
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500static void
4501_scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4502 struct _sas_device *sas_device)
4503{
4504 Mpi2SepReply_t mpi_reply;
4505 Mpi2SepRequest_t mpi_request;
4506
4507 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4508 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4509 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4510 mpi_request.SlotStatus = 0;
4511 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4512 mpi_request.DevHandle = 0;
4513 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4514 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4515 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4516 &mpi_request)) != 0) {
4517 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4518 __FILE__, __LINE__, __func__);
4519 return;
4520 }
4521
4522 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4523 dewtprintk(ioc, printk(MPT3SAS_FMT
4524 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4525 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4526 le32_to_cpu(mpi_reply.IOCLogInfo)));
4527 return;
4528 }
4529}
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539static void
4540_scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4541{
4542 struct fw_event_work *fw_event;
4543
4544 fw_event = alloc_fw_event_work(0);
4545 if (!fw_event)
4546 return;
4547 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4548 fw_event->device_handle = handle;
4549 fw_event->ioc = ioc;
4550 _scsih_fw_event_add(ioc, fw_event);
4551 fw_event_work_put(fw_event);
4552}
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562static void
4563_scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4564{
4565 struct scsi_target *starget;
4566 struct MPT3SAS_TARGET *sas_target_priv_data;
4567 Mpi2EventNotificationReply_t *event_reply;
4568 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4569 struct _sas_device *sas_device;
4570 ssize_t sz;
4571 unsigned long flags;
4572
4573
4574 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4575 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4576 if (!sas_device)
4577 goto out_unlock;
4578
4579 starget = sas_device->starget;
4580 sas_target_priv_data = starget->hostdata;
4581
4582 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4583 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4584 goto out_unlock;
4585
4586 if (sas_device->enclosure_handle != 0)
4587 starget_printk(KERN_INFO, starget, "predicted fault, "
4588 "enclosure logical id(0x%016llx), slot(%d)\n",
4589 (unsigned long long)sas_device->enclosure_logical_id,
4590 sas_device->slot);
4591 if (sas_device->connector_name[0] != '\0')
4592 starget_printk(KERN_WARNING, starget, "predicted fault, "
4593 "enclosure level(0x%04x), connector name( %s)\n",
4594 sas_device->enclosure_level,
4595 sas_device->connector_name);
4596 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4597
4598 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4599 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4600
4601
4602 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4603 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4604 event_reply = kzalloc(sz, GFP_KERNEL);
4605 if (!event_reply) {
4606 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4607 ioc->name, __FILE__, __LINE__, __func__);
4608 goto out;
4609 }
4610
4611 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4612 event_reply->Event =
4613 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4614 event_reply->MsgLength = sz/4;
4615 event_reply->EventDataLength =
4616 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4617 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4618 event_reply->EventData;
4619 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4620 event_data->ASC = 0x5D;
4621 event_data->DevHandle = cpu_to_le16(handle);
4622 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4623 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4624 kfree(event_reply);
4625out:
4626 if (sas_device)
4627 sas_device_put(sas_device);
4628 return;
4629
4630out_unlock:
4631 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4632 goto out;
4633}
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647static u8
4648_scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4649{
4650 Mpi2SCSIIORequest_t *mpi_request;
4651 Mpi2SCSIIOReply_t *mpi_reply;
4652 struct scsi_cmnd *scmd;
4653 u16 ioc_status;
4654 u32 xfer_cnt;
4655 u8 scsi_state;
4656 u8 scsi_status;
4657 u32 log_info;
4658 struct MPT3SAS_DEVICE *sas_device_priv_data;
4659 u32 response_code = 0;
4660 unsigned long flags;
4661 unsigned int sector_sz;
4662
4663 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4664 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4665 if (scmd == NULL)
4666 return 1;
4667
4668 _scsih_set_satl_pending(scmd, false);
4669
4670 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4671
4672 if (mpi_reply == NULL) {
4673 scmd->result = DID_OK << 16;
4674 goto out;
4675 }
4676
4677 sas_device_priv_data = scmd->device->hostdata;
4678 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4679 sas_device_priv_data->sas_target->deleted) {
4680 scmd->result = DID_NO_CONNECT << 16;
4681 goto out;
4682 }
4683 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4684
4685
4686
4687
4688
4689 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4690 ((ioc_status & MPI2_IOCSTATUS_MASK)
4691 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4692 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4693 ioc->scsi_lookup[smid - 1].scmd = scmd;
4694 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4695 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4696 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4697 mpi_request->DevHandle =
4698 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4699 ioc->put_smid_scsi_io(ioc, smid,
4700 sas_device_priv_data->sas_target->handle);
4701 return 0;
4702 }
4703
4704 scsi_state = mpi_reply->SCSIState;
4705 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4706 response_code =
4707 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4708 if (!sas_device_priv_data->tlr_snoop_check) {
4709 sas_device_priv_data->tlr_snoop_check++;
4710 if (!ioc->is_warpdrive &&
4711 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4712 sas_is_tlr_enabled(scmd->device) &&
4713 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4714 sas_disable_tlr(scmd->device);
4715 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4716 }
4717 }
4718
4719 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4720
4721
4722
4723
4724
4725 sector_sz = scmd->device->sector_size;
4726 if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
4727 xfer_cnt % sector_sz)) {
4728 sdev_printk(KERN_INFO, scmd->device,
4729 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4730 xfer_cnt, sector_sz);
4731 xfer_cnt = round_down(xfer_cnt, sector_sz);
4732 }
4733
4734 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4735 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4736 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4737 else
4738 log_info = 0;
4739 ioc_status &= MPI2_IOCSTATUS_MASK;
4740 scsi_status = mpi_reply->SCSIStatus;
4741
4742 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4743 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4744 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4745 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4746 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4747 }
4748
4749 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4750 struct sense_info data;
4751 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4752 smid);
4753 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4754 le32_to_cpu(mpi_reply->SenseCount));
4755 memcpy(scmd->sense_buffer, sense_data, sz);
4756 _scsih_normalize_sense(scmd->sense_buffer, &data);
4757
4758 if (data.asc == 0x5D)
4759 _scsih_smart_predicted_fault(ioc,
4760 le16_to_cpu(mpi_reply->DevHandle));
4761 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4762
4763 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4764 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4765 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4766 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4767 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4768 }
4769 switch (ioc_status) {
4770 case MPI2_IOCSTATUS_BUSY:
4771 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4772 scmd->result = SAM_STAT_BUSY;
4773 break;
4774
4775 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4776 scmd->result = DID_NO_CONNECT << 16;
4777 break;
4778
4779 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4780 if (sas_device_priv_data->block) {
4781 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4782 goto out;
4783 }
4784 if (log_info == 0x31110630) {
4785 if (scmd->retries > 2) {
4786 scmd->result = DID_NO_CONNECT << 16;
4787 scsi_device_set_state(scmd->device,
4788 SDEV_OFFLINE);
4789 } else {
4790 scmd->result = DID_SOFT_ERROR << 16;
4791 scmd->device->expecting_cc_ua = 1;
4792 }
4793 break;
4794 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4795 scmd->result = DID_RESET << 16;
4796 break;
4797 }
4798 scmd->result = DID_SOFT_ERROR << 16;
4799 break;
4800 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4801 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4802 scmd->result = DID_RESET << 16;
4803 break;
4804
4805 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4806 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4807 scmd->result = DID_SOFT_ERROR << 16;
4808 else
4809 scmd->result = (DID_OK << 16) | scsi_status;
4810 break;
4811
4812 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4813 scmd->result = (DID_OK << 16) | scsi_status;
4814
4815 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4816 break;
4817
4818 if (xfer_cnt < scmd->underflow) {
4819 if (scsi_status == SAM_STAT_BUSY)
4820 scmd->result = SAM_STAT_BUSY;
4821 else
4822 scmd->result = DID_SOFT_ERROR << 16;
4823 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4824 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4825 scmd->result = DID_SOFT_ERROR << 16;
4826 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4827 scmd->result = DID_RESET << 16;
4828 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4829 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4830 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4831 scmd->result = (DRIVER_SENSE << 24) |
4832 SAM_STAT_CHECK_CONDITION;
4833 scmd->sense_buffer[0] = 0x70;
4834 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4835 scmd->sense_buffer[12] = 0x20;
4836 scmd->sense_buffer[13] = 0;
4837 }
4838 break;
4839
4840 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4841 scsi_set_resid(scmd, 0);
4842 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4843 case MPI2_IOCSTATUS_SUCCESS:
4844 scmd->result = (DID_OK << 16) | scsi_status;
4845 if (response_code ==
4846 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4847 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4848 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4849 scmd->result = DID_SOFT_ERROR << 16;
4850 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4851 scmd->result = DID_RESET << 16;
4852 break;
4853
4854 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4855 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4856 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4857 _scsih_eedp_error_handling(scmd, ioc_status);
4858 break;
4859
4860 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4861 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4862 case MPI2_IOCSTATUS_INVALID_SGL:
4863 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4864 case MPI2_IOCSTATUS_INVALID_FIELD:
4865 case MPI2_IOCSTATUS_INVALID_STATE:
4866 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4867 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4868 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4869 default:
4870 scmd->result = DID_SOFT_ERROR << 16;
4871 break;
4872
4873 }
4874
4875 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4876 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4877
4878 out:
4879
4880 scsi_dma_unmap(scmd);
4881
4882 scmd->scsi_done(scmd);
4883 return 1;
4884}
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897static void
4898_scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4899{
4900 u16 sz;
4901 u16 ioc_status;
4902 int i;
4903 Mpi2ConfigReply_t mpi_reply;
4904 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4905 u16 attached_handle;
4906 u8 link_rate;
4907
4908 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4909 "updating handles for sas_host(0x%016llx)\n",
4910 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4911
4912 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4913 * sizeof(Mpi2SasIOUnit0PhyData_t));
4914 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4915 if (!sas_iounit_pg0) {
4916 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4917 ioc->name, __FILE__, __LINE__, __func__);
4918 return;
4919 }
4920
4921 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4922 sas_iounit_pg0, sz)) != 0)
4923 goto out;
4924 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4925 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4926 goto out;
4927 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4928 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4929 if (i == 0)
4930 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4931 PhyData[0].ControllerDevHandle);
4932 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4933 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4934 AttachedDevHandle);
4935 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4936 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4937 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4938 attached_handle, i, link_rate);
4939 }
4940 out:
4941 kfree(sas_iounit_pg0);
4942}
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952static void
4953_scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4954{
4955 int i;
4956 Mpi2ConfigReply_t mpi_reply;
4957 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4958 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4959 Mpi2SasPhyPage0_t phy_pg0;
4960 Mpi2SasDevicePage0_t sas_device_pg0;
4961 Mpi2SasEnclosurePage0_t enclosure_pg0;
4962 u16 ioc_status;
4963 u16 sz;
4964 u8 device_missing_delay;
4965 u8 num_phys;
4966
4967 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
4968 if (!num_phys) {
4969 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4970 ioc->name, __FILE__, __LINE__, __func__);
4971 return;
4972 }
4973 ioc->sas_hba.phy = kcalloc(num_phys,
4974 sizeof(struct _sas_phy), GFP_KERNEL);
4975 if (!ioc->sas_hba.phy) {
4976 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4977 ioc->name, __FILE__, __LINE__, __func__);
4978 goto out;
4979 }
4980 ioc->sas_hba.num_phys = num_phys;
4981
4982
4983 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4984 sizeof(Mpi2SasIOUnit0PhyData_t));
4985 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4986 if (!sas_iounit_pg0) {
4987 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4988 ioc->name, __FILE__, __LINE__, __func__);
4989 return;
4990 }
4991 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4992 sas_iounit_pg0, sz))) {
4993 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4994 ioc->name, __FILE__, __LINE__, __func__);
4995 goto out;
4996 }
4997 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4998 MPI2_IOCSTATUS_MASK;
4999 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5000 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5001 ioc->name, __FILE__, __LINE__, __func__);
5002 goto out;
5003 }
5004
5005
5006 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
5007 sizeof(Mpi2SasIOUnit1PhyData_t));
5008 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
5009 if (!sas_iounit_pg1) {
5010 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5011 ioc->name, __FILE__, __LINE__, __func__);
5012 goto out;
5013 }
5014 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
5015 sas_iounit_pg1, sz))) {
5016 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5017 ioc->name, __FILE__, __LINE__, __func__);
5018 goto out;
5019 }
5020 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5021 MPI2_IOCSTATUS_MASK;
5022 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5023 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5024 ioc->name, __FILE__, __LINE__, __func__);
5025 goto out;
5026 }
5027
5028 ioc->io_missing_delay =
5029 sas_iounit_pg1->IODeviceMissingDelay;
5030 device_missing_delay =
5031 sas_iounit_pg1->ReportDeviceMissingDelay;
5032 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5033 ioc->device_missing_delay = (device_missing_delay &
5034 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5035 else
5036 ioc->device_missing_delay = device_missing_delay &
5037 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5038
5039 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5040 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5041 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5042 i))) {
5043 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5044 ioc->name, __FILE__, __LINE__, __func__);
5045 goto out;
5046 }
5047 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5048 MPI2_IOCSTATUS_MASK;
5049 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5050 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5051 ioc->name, __FILE__, __LINE__, __func__);
5052 goto out;
5053 }
5054
5055 if (i == 0)
5056 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5057 PhyData[0].ControllerDevHandle);
5058 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5059 ioc->sas_hba.phy[i].phy_id = i;
5060 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5061 phy_pg0, ioc->sas_hba.parent_dev);
5062 }
5063 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5064 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5065 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5066 ioc->name, __FILE__, __LINE__, __func__);
5067 goto out;
5068 }
5069 ioc->sas_hba.enclosure_handle =
5070 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5071 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5072 pr_info(MPT3SAS_FMT
5073 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5074 ioc->name, ioc->sas_hba.handle,
5075 (unsigned long long) ioc->sas_hba.sas_address,
5076 ioc->sas_hba.num_phys) ;
5077
5078 if (ioc->sas_hba.enclosure_handle) {
5079 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5080 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5081 ioc->sas_hba.enclosure_handle)))
5082 ioc->sas_hba.enclosure_logical_id =
5083 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5084 }
5085
5086 out:
5087 kfree(sas_iounit_pg1);
5088 kfree(sas_iounit_pg0);
5089}
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100static int
5101_scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5102{
5103 struct _sas_node *sas_expander;
5104 Mpi2ConfigReply_t mpi_reply;
5105 Mpi2ExpanderPage0_t expander_pg0;
5106 Mpi2ExpanderPage1_t expander_pg1;
5107 Mpi2SasEnclosurePage0_t enclosure_pg0;
5108 u32 ioc_status;
5109 u16 parent_handle;
5110 u64 sas_address, sas_address_parent = 0;
5111 int i;
5112 unsigned long flags;
5113 struct _sas_port *mpt3sas_port = NULL;
5114
5115 int rc = 0;
5116
5117 if (!handle)
5118 return -1;
5119
5120 if (ioc->shost_recovery || ioc->pci_error_recovery)
5121 return -1;
5122
5123 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5124 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5125 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5126 ioc->name, __FILE__, __LINE__, __func__);
5127 return -1;
5128 }
5129
5130 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5131 MPI2_IOCSTATUS_MASK;
5132 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5133 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5134 ioc->name, __FILE__, __LINE__, __func__);
5135 return -1;
5136 }
5137
5138
5139 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5140 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5141 != 0) {
5142 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5143 ioc->name, __FILE__, __LINE__, __func__);
5144 return -1;
5145 }
5146 if (sas_address_parent != ioc->sas_hba.sas_address) {
5147 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5148 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5149 sas_address_parent);
5150 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5151 if (!sas_expander) {
5152 rc = _scsih_expander_add(ioc, parent_handle);
5153 if (rc != 0)
5154 return rc;
5155 }
5156 }
5157
5158 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5159 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5160 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5161 sas_address);
5162 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5163
5164 if (sas_expander)
5165 return 0;
5166
5167 sas_expander = kzalloc(sizeof(struct _sas_node),
5168 GFP_KERNEL);
5169 if (!sas_expander) {
5170 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5171 ioc->name, __FILE__, __LINE__, __func__);
5172 return -1;
5173 }
5174
5175 sas_expander->handle = handle;
5176 sas_expander->num_phys = expander_pg0.NumPhys;
5177 sas_expander->sas_address_parent = sas_address_parent;
5178 sas_expander->sas_address = sas_address;
5179
5180 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5181 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5182 handle, parent_handle, (unsigned long long)
5183 sas_expander->sas_address, sas_expander->num_phys);
5184
5185 if (!sas_expander->num_phys)
5186 goto out_fail;
5187 sas_expander->phy = kcalloc(sas_expander->num_phys,
5188 sizeof(struct _sas_phy), GFP_KERNEL);
5189 if (!sas_expander->phy) {
5190 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5191 ioc->name, __FILE__, __LINE__, __func__);
5192 rc = -1;
5193 goto out_fail;
5194 }
5195
5196 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5197 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5198 sas_address_parent);
5199 if (!mpt3sas_port) {
5200 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5201 ioc->name, __FILE__, __LINE__, __func__);
5202 rc = -1;
5203 goto out_fail;
5204 }
5205 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5206
5207 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5208 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5209 &expander_pg1, i, handle))) {
5210 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5211 ioc->name, __FILE__, __LINE__, __func__);
5212 rc = -1;
5213 goto out_fail;
5214 }
5215 sas_expander->phy[i].handle = handle;
5216 sas_expander->phy[i].phy_id = i;
5217
5218 if ((mpt3sas_transport_add_expander_phy(ioc,
5219 &sas_expander->phy[i], expander_pg1,
5220 sas_expander->parent_dev))) {
5221 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5222 ioc->name, __FILE__, __LINE__, __func__);
5223 rc = -1;
5224 goto out_fail;
5225 }
5226 }
5227
5228 if (sas_expander->enclosure_handle) {
5229 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5230 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5231 sas_expander->enclosure_handle)))
5232 sas_expander->enclosure_logical_id =
5233 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5234 }
5235
5236 _scsih_expander_node_add(ioc, sas_expander);
5237 return 0;
5238
5239 out_fail:
5240
5241 if (mpt3sas_port)
5242 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5243 sas_address_parent);
5244 kfree(sas_expander);
5245 return rc;
5246}
5247
5248
5249
5250
5251
5252
5253
5254
5255void
5256mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5257{
5258 struct _sas_node *sas_expander;
5259 unsigned long flags;
5260
5261 if (ioc->shost_recovery)
5262 return;
5263
5264 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5265 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5266 sas_address);
5267 if (sas_expander)
5268 list_del(&sas_expander->list);
5269 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5270 if (sas_expander)
5271 _scsih_expander_node_remove(ioc, sas_expander);
5272}
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287static u8
5288_scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5289{
5290 MPI2DefaultReply_t *mpi_reply;
5291
5292 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5293 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5294 return 1;
5295 if (ioc->scsih_cmds.smid != smid)
5296 return 1;
5297 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5298 if (mpi_reply) {
5299 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5300 mpi_reply->MsgLength*4);
5301 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5302 }
5303 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5304 complete(&ioc->scsih_cmds.done);
5305 return 1;
5306}
5307
5308
5309
5310
5311#define MPT3_MAX_LUNS (255)
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323static u8
5324_scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5325 u16 handle, u8 access_status)
5326{
5327 u8 rc = 1;
5328 char *desc = NULL;
5329
5330 switch (access_status) {
5331 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5332 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5333 rc = 0;
5334 break;
5335 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5336 desc = "sata capability failed";
5337 break;
5338 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5339 desc = "sata affiliation conflict";
5340 break;
5341 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5342 desc = "route not addressable";
5343 break;
5344 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5345 desc = "smp error not addressable";
5346 break;
5347 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5348 desc = "device blocked";
5349 break;
5350 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5351 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5352 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5353 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5354 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5355 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5356 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5357 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5358 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5359 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5360 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5361 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5362 desc = "sata initialization failed";
5363 break;
5364 default:
5365 desc = "unknown";
5366 break;
5367 }
5368
5369 if (!rc)
5370 return 0;
5371
5372 pr_err(MPT3SAS_FMT
5373 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5374 ioc->name, desc, (unsigned long long)sas_address, handle);
5375 return rc;
5376}
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388static void
5389_scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5390 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5391{
5392 Mpi2ConfigReply_t mpi_reply;
5393 Mpi2SasDevicePage0_t sas_device_pg0;
5394 struct _sas_device *sas_device;
5395 u32 ioc_status;
5396 unsigned long flags;
5397 u64 sas_address;
5398 struct scsi_target *starget;
5399 struct MPT3SAS_TARGET *sas_target_priv_data;
5400 u32 device_info;
5401
5402
5403 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5405 return;
5406
5407 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5408 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5409 return;
5410
5411
5412
5413
5414 if (phy_number != sas_device_pg0.PhyNum)
5415 return;
5416
5417
5418 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5419 if (!(_scsih_is_end_device(device_info)))
5420 return;
5421
5422 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5423 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5424 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5425 sas_address);
5426
5427 if (!sas_device)
5428 goto out_unlock;
5429
5430 if (unlikely(sas_device->handle != handle)) {
5431 starget = sas_device->starget;
5432 sas_target_priv_data = starget->hostdata;
5433 starget_printk(KERN_INFO, starget,
5434 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5435 sas_device->handle, handle);
5436 sas_target_priv_data->handle = handle;
5437 sas_device->handle = handle;
5438 if (le16_to_cpu(sas_device_pg0.Flags) &
5439 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5440 sas_device->enclosure_level =
5441 sas_device_pg0.EnclosureLevel;
5442 memcpy(sas_device->connector_name,
5443 sas_device_pg0.ConnectorName, 4);
5444 sas_device->connector_name[4] = '\0';
5445 } else {
5446 sas_device->enclosure_level = 0;
5447 sas_device->connector_name[0] = '\0';
5448 }
5449 }
5450
5451
5452 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5453 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5454 pr_err(MPT3SAS_FMT
5455 "device is not present handle(0x%04x), flags!!!\n",
5456 ioc->name, handle);
5457 goto out_unlock;
5458 }
5459
5460
5461 if (_scsih_check_access_status(ioc, sas_address, handle,
5462 sas_device_pg0.AccessStatus))
5463 goto out_unlock;
5464
5465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5466 _scsih_ublock_io_device(ioc, sas_address);
5467
5468 if (sas_device)
5469 sas_device_put(sas_device);
5470 return;
5471
5472out_unlock:
5473 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5474 if (sas_device)
5475 sas_device_put(sas_device);
5476}
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489static int
5490_scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5491 u8 is_pd)
5492{
5493 Mpi2ConfigReply_t mpi_reply;
5494 Mpi2SasDevicePage0_t sas_device_pg0;
5495 Mpi2SasEnclosurePage0_t enclosure_pg0;
5496 struct _sas_device *sas_device;
5497 u32 ioc_status;
5498 u64 sas_address;
5499 u32 device_info;
5500
5501 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5502 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5503 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5504 ioc->name, __FILE__, __LINE__, __func__);
5505 return -1;
5506 }
5507
5508 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5509 MPI2_IOCSTATUS_MASK;
5510 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5511 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5512 ioc->name, __FILE__, __LINE__, __func__);
5513 return -1;
5514 }
5515
5516
5517 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5518 if (!(_scsih_is_end_device(device_info)))
5519 return -1;
5520 set_bit(handle, ioc->pend_os_device_add);
5521 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5522
5523
5524 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5525 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5526 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5527 ioc->name, handle);
5528 return -1;
5529 }
5530
5531
5532 if (_scsih_check_access_status(ioc, sas_address, handle,
5533 sas_device_pg0.AccessStatus))
5534 return -1;
5535
5536 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5537 sas_address);
5538 if (sas_device) {
5539 clear_bit(handle, ioc->pend_os_device_add);
5540 sas_device_put(sas_device);
5541 return -1;
5542 }
5543
5544 sas_device = kzalloc(sizeof(struct _sas_device),
5545 GFP_KERNEL);
5546 if (!sas_device) {
5547 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5548 ioc->name, __FILE__, __LINE__, __func__);
5549 return 0;
5550 }
5551
5552 kref_init(&sas_device->refcount);
5553 sas_device->handle = handle;
5554 if (_scsih_get_sas_address(ioc,
5555 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5556 &sas_device->sas_address_parent) != 0)
5557 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5558 ioc->name, __FILE__, __LINE__, __func__);
5559 sas_device->enclosure_handle =
5560 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5561 if (sas_device->enclosure_handle != 0)
5562 sas_device->slot =
5563 le16_to_cpu(sas_device_pg0.Slot);
5564 sas_device->device_info = device_info;
5565 sas_device->sas_address = sas_address;
5566 sas_device->phy = sas_device_pg0.PhyNum;
5567 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5568 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5569
5570 if (le16_to_cpu(sas_device_pg0.Flags)
5571 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5572 sas_device->enclosure_level =
5573 sas_device_pg0.EnclosureLevel;
5574 memcpy(sas_device->connector_name,
5575 sas_device_pg0.ConnectorName, 4);
5576 sas_device->connector_name[4] = '\0';
5577 } else {
5578 sas_device->enclosure_level = 0;
5579 sas_device->connector_name[0] = '\0';
5580 }
5581
5582 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5583 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5584 sas_device->enclosure_handle)))
5585 sas_device->enclosure_logical_id =
5586 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5587
5588
5589 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5590
5591 if (ioc->wait_for_discovery_to_complete)
5592 _scsih_sas_device_init_add(ioc, sas_device);
5593 else
5594 _scsih_sas_device_add(ioc, sas_device);
5595
5596 sas_device_put(sas_device);
5597 return 0;
5598}
5599
5600
5601
5602
5603
5604
5605
5606
5607static void
5608_scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5609 struct _sas_device *sas_device)
5610{
5611 struct MPT3SAS_TARGET *sas_target_priv_data;
5612
5613 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5614 (sas_device->pfa_led_on)) {
5615 _scsih_turn_off_pfa_led(ioc, sas_device);
5616 sas_device->pfa_led_on = 0;
5617 }
5618 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5619 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5620 ioc->name, __func__,
5621 sas_device->handle, (unsigned long long)
5622 sas_device->sas_address));
5623 if (sas_device->enclosure_handle != 0)
5624 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5625 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5626 ioc->name, __func__,
5627 (unsigned long long)sas_device->enclosure_logical_id,
5628 sas_device->slot));
5629 if (sas_device->connector_name[0] != '\0')
5630 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5631 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5632 ioc->name, __func__,
5633 sas_device->enclosure_level,
5634 sas_device->connector_name));
5635
5636 if (sas_device->starget && sas_device->starget->hostdata) {
5637 sas_target_priv_data = sas_device->starget->hostdata;
5638 sas_target_priv_data->deleted = 1;
5639 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5640 sas_target_priv_data->handle =
5641 MPT3SAS_INVALID_DEVICE_HANDLE;
5642 }
5643
5644 if (!ioc->hide_drives)
5645 mpt3sas_transport_port_remove(ioc,
5646 sas_device->sas_address,
5647 sas_device->sas_address_parent);
5648
5649 pr_info(MPT3SAS_FMT
5650 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5651 ioc->name, sas_device->handle,
5652 (unsigned long long) sas_device->sas_address);
5653 if (sas_device->enclosure_handle != 0)
5654 pr_info(MPT3SAS_FMT
5655 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5656 ioc->name,
5657 (unsigned long long)sas_device->enclosure_logical_id,
5658 sas_device->slot);
5659 if (sas_device->connector_name[0] != '\0')
5660 pr_info(MPT3SAS_FMT
5661 "removing enclosure level(0x%04x), connector name( %s)\n",
5662 ioc->name, sas_device->enclosure_level,
5663 sas_device->connector_name);
5664
5665 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5666 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5667 ioc->name, __func__,
5668 sas_device->handle, (unsigned long long)
5669 sas_device->sas_address));
5670 if (sas_device->enclosure_handle != 0)
5671 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5672 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5673 ioc->name, __func__,
5674 (unsigned long long)sas_device->enclosure_logical_id,
5675 sas_device->slot));
5676 if (sas_device->connector_name[0] != '\0')
5677 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5678 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5679 ioc->name, __func__, sas_device->enclosure_level,
5680 sas_device->connector_name));
5681}
5682
5683
5684
5685
5686
5687
5688
5689static void
5690_scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5691 Mpi2EventDataSasTopologyChangeList_t *event_data)
5692{
5693 int i;
5694 u16 handle;
5695 u16 reason_code;
5696 u8 phy_number;
5697 char *status_str = NULL;
5698 u8 link_rate, prev_link_rate;
5699
5700 switch (event_data->ExpStatus) {
5701 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5702 status_str = "add";
5703 break;
5704 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5705 status_str = "remove";
5706 break;
5707 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5708 case 0:
5709 status_str = "responding";
5710 break;
5711 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5712 status_str = "remove delay";
5713 break;
5714 default:
5715 status_str = "unknown status";
5716 break;
5717 }
5718 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5719 ioc->name, status_str);
5720 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5721 "start_phy(%02d), count(%d)\n",
5722 le16_to_cpu(event_data->ExpanderDevHandle),
5723 le16_to_cpu(event_data->EnclosureHandle),
5724 event_data->StartPhyNum, event_data->NumEntries);
5725 for (i = 0; i < event_data->NumEntries; i++) {
5726 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5727 if (!handle)
5728 continue;
5729 phy_number = event_data->StartPhyNum + i;
5730 reason_code = event_data->PHY[i].PhyStatus &
5731 MPI2_EVENT_SAS_TOPO_RC_MASK;
5732 switch (reason_code) {
5733 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5734 status_str = "target add";
5735 break;
5736 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5737 status_str = "target remove";
5738 break;
5739 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5740 status_str = "delay target remove";
5741 break;
5742 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5743 status_str = "link rate change";
5744 break;
5745 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5746 status_str = "target responding";
5747 break;
5748 default:
5749 status_str = "unknown";
5750 break;
5751 }
5752 link_rate = event_data->PHY[i].LinkRate >> 4;
5753 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5754 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5755 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5756 handle, status_str, link_rate, prev_link_rate);
5757
5758 }
5759}
5760
5761
5762
5763
5764
5765
5766
5767
5768static int
5769_scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5770 struct fw_event_work *fw_event)
5771{
5772 int i;
5773 u16 parent_handle, handle;
5774 u16 reason_code;
5775 u8 phy_number, max_phys;
5776 struct _sas_node *sas_expander;
5777 u64 sas_address;
5778 unsigned long flags;
5779 u8 link_rate, prev_link_rate;
5780 Mpi2EventDataSasTopologyChangeList_t *event_data =
5781 (Mpi2EventDataSasTopologyChangeList_t *)
5782 fw_event->event_data;
5783
5784 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5785 _scsih_sas_topology_change_event_debug(ioc, event_data);
5786
5787 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5788 return 0;
5789
5790 if (!ioc->sas_hba.num_phys)
5791 _scsih_sas_host_add(ioc);
5792 else
5793 _scsih_sas_host_refresh(ioc);
5794
5795 if (fw_event->ignore) {
5796 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5797 "ignoring expander event\n", ioc->name));
5798 return 0;
5799 }
5800
5801 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5802
5803
5804 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5805 if (_scsih_expander_add(ioc, parent_handle) != 0)
5806 return 0;
5807
5808 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5809 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5810 parent_handle);
5811 if (sas_expander) {
5812 sas_address = sas_expander->sas_address;
5813 max_phys = sas_expander->num_phys;
5814 } else if (parent_handle < ioc->sas_hba.num_phys) {
5815 sas_address = ioc->sas_hba.sas_address;
5816 max_phys = ioc->sas_hba.num_phys;
5817 } else {
5818 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5819 return 0;
5820 }
5821 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5822
5823
5824 for (i = 0; i < event_data->NumEntries; i++) {
5825 if (fw_event->ignore) {
5826 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5827 "ignoring expander event\n", ioc->name));
5828 return 0;
5829 }
5830 if (ioc->remove_host || ioc->pci_error_recovery)
5831 return 0;
5832 phy_number = event_data->StartPhyNum + i;
5833 if (phy_number >= max_phys)
5834 continue;
5835 reason_code = event_data->PHY[i].PhyStatus &
5836 MPI2_EVENT_SAS_TOPO_RC_MASK;
5837 if ((event_data->PHY[i].PhyStatus &
5838 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5839 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5840 continue;
5841 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5842 if (!handle)
5843 continue;
5844 link_rate = event_data->PHY[i].LinkRate >> 4;
5845 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5846 switch (reason_code) {
5847 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5848
5849 if (ioc->shost_recovery)
5850 break;
5851
5852 if (link_rate == prev_link_rate)
5853 break;
5854
5855 mpt3sas_transport_update_links(ioc, sas_address,
5856 handle, phy_number, link_rate);
5857
5858 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5859 break;
5860
5861 _scsih_check_device(ioc, sas_address, handle,
5862 phy_number, link_rate);
5863
5864 if (!test_bit(handle, ioc->pend_os_device_add))
5865 break;
5866
5867
5868 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5869
5870 if (ioc->shost_recovery)
5871 break;
5872
5873 mpt3sas_transport_update_links(ioc, sas_address,
5874 handle, phy_number, link_rate);
5875
5876 _scsih_add_device(ioc, handle, phy_number, 0);
5877
5878 break;
5879 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5880
5881 _scsih_device_remove_by_handle(ioc, handle);
5882 break;
5883 }
5884 }
5885
5886
5887 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5888 sas_expander)
5889 mpt3sas_expander_remove(ioc, sas_address);
5890
5891 return 0;
5892}
5893
5894
5895
5896
5897
5898
5899
5900
5901static void
5902_scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5903 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5904{
5905 char *reason_str = NULL;
5906
5907 switch (event_data->ReasonCode) {
5908 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5909 reason_str = "smart data";
5910 break;
5911 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5912 reason_str = "unsupported device discovered";
5913 break;
5914 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5915 reason_str = "internal device reset";
5916 break;
5917 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5918 reason_str = "internal task abort";
5919 break;
5920 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5921 reason_str = "internal task abort set";
5922 break;
5923 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5924 reason_str = "internal clear task set";
5925 break;
5926 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5927 reason_str = "internal query task";
5928 break;
5929 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5930 reason_str = "sata init failure";
5931 break;
5932 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5933 reason_str = "internal device reset complete";
5934 break;
5935 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5936 reason_str = "internal task abort complete";
5937 break;
5938 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5939 reason_str = "internal async notification";
5940 break;
5941 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5942 reason_str = "expander reduced functionality";
5943 break;
5944 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5945 reason_str = "expander reduced functionality complete";
5946 break;
5947 default:
5948 reason_str = "unknown reason";
5949 break;
5950 }
5951 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5952 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5953 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5954 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5955 le16_to_cpu(event_data->TaskTag));
5956 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5957 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5958 event_data->ASC, event_data->ASCQ);
5959 pr_info("\n");
5960}
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970static void
5971_scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5972 struct fw_event_work *fw_event)
5973{
5974 struct MPT3SAS_TARGET *target_priv_data;
5975 struct _sas_device *sas_device;
5976 u64 sas_address;
5977 unsigned long flags;
5978 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5979 (Mpi2EventDataSasDeviceStatusChange_t *)
5980 fw_event->event_data;
5981
5982 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5983 _scsih_sas_device_status_change_event_debug(ioc,
5984 event_data);
5985
5986
5987
5988
5989 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5990 return;
5991
5992 if (event_data->ReasonCode !=
5993 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5994 event_data->ReasonCode !=
5995 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5996 return;
5997
5998 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5999 sas_address = le64_to_cpu(event_data->SASAddress);
6000 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
6001 sas_address);
6002
6003 if (!sas_device || !sas_device->starget)
6004 goto out;
6005
6006 target_priv_data = sas_device->starget->hostdata;
6007 if (!target_priv_data)
6008 goto out;
6009
6010 if (event_data->ReasonCode ==
6011 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
6012 target_priv_data->tm_busy = 1;
6013 else
6014 target_priv_data->tm_busy = 0;
6015
6016out:
6017 if (sas_device)
6018 sas_device_put(sas_device);
6019
6020 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6021
6022}
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033static void
6034_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6035 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
6036{
6037 char *reason_str = NULL;
6038
6039 switch (event_data->ReasonCode) {
6040 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
6041 reason_str = "enclosure add";
6042 break;
6043 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
6044 reason_str = "enclosure remove";
6045 break;
6046 default:
6047 reason_str = "unknown reason";
6048 break;
6049 }
6050
6051 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
6052 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6053 " number slots(%d)\n", ioc->name, reason_str,
6054 le16_to_cpu(event_data->EnclosureHandle),
6055 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
6056 le16_to_cpu(event_data->StartSlot));
6057}
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067static void
6068_scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6069 struct fw_event_work *fw_event)
6070{
6071 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6072 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
6073 (Mpi2EventDataSasEnclDevStatusChange_t *)
6074 fw_event->event_data);
6075}
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085static void
6086_scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
6087 struct fw_event_work *fw_event)
6088{
6089 struct scsi_cmnd *scmd;
6090 struct scsi_device *sdev;
6091 u16 smid, handle;
6092 u32 lun;
6093 struct MPT3SAS_DEVICE *sas_device_priv_data;
6094 u32 termination_count;
6095 u32 query_count;
6096 Mpi2SCSITaskManagementReply_t *mpi_reply;
6097 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6098 (Mpi2EventDataSasBroadcastPrimitive_t *)
6099 fw_event->event_data;
6100 u16 ioc_status;
6101 unsigned long flags;
6102 int r;
6103 u8 max_retries = 0;
6104 u8 task_abort_retries;
6105
6106 mutex_lock(&ioc->tm_cmds.mutex);
6107 pr_info(MPT3SAS_FMT
6108 "%s: enter: phy number(%d), width(%d)\n",
6109 ioc->name, __func__, event_data->PhyNum,
6110 event_data->PortWidth);
6111
6112 _scsih_block_io_all_device(ioc);
6113
6114 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6115 mpi_reply = ioc->tm_cmds.reply;
6116 broadcast_aen_retry:
6117
6118
6119 if (max_retries++ == 5) {
6120 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
6121 ioc->name, __func__));
6122 goto out;
6123 } else if (max_retries > 1)
6124 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
6125 ioc->name, __func__, max_retries - 1));
6126
6127 termination_count = 0;
6128 query_count = 0;
6129 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6130 if (ioc->shost_recovery)
6131 goto out;
6132 scmd = _scsih_scsi_lookup_get(ioc, smid);
6133 if (!scmd)
6134 continue;
6135 sdev = scmd->device;
6136 sas_device_priv_data = sdev->hostdata;
6137 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6138 continue;
6139
6140 if (sas_device_priv_data->sas_target->flags &
6141 MPT_TARGET_FLAGS_RAID_COMPONENT)
6142 continue;
6143
6144 if (sas_device_priv_data->sas_target->flags &
6145 MPT_TARGET_FLAGS_VOLUME)
6146 continue;
6147
6148 handle = sas_device_priv_data->sas_target->handle;
6149 lun = sas_device_priv_data->lun;
6150 query_count++;
6151
6152 if (ioc->shost_recovery)
6153 goto out;
6154
6155 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6156 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6157 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
6158 if (r == FAILED) {
6159 sdev_printk(KERN_WARNING, sdev,
6160 "mpt3sas_scsih_issue_tm: FAILED when sending "
6161 "QUERY_TASK: scmd(%p)\n", scmd);
6162 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6163 goto broadcast_aen_retry;
6164 }
6165 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6166 & MPI2_IOCSTATUS_MASK;
6167 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6168 sdev_printk(KERN_WARNING, sdev,
6169 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6170 ioc_status, scmd);
6171 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6172 goto broadcast_aen_retry;
6173 }
6174
6175
6176 if (mpi_reply->ResponseCode ==
6177 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6178 mpi_reply->ResponseCode ==
6179 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6180 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6181 continue;
6182 }
6183 task_abort_retries = 0;
6184 tm_retry:
6185 if (task_abort_retries++ == 60) {
6186 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6187 "%s: ABORT_TASK: giving up\n", ioc->name,
6188 __func__));
6189 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6190 goto broadcast_aen_retry;
6191 }
6192
6193 if (ioc->shost_recovery)
6194 goto out_no_lock;
6195
6196 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6197 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
6198 30);
6199 if (r == FAILED) {
6200 sdev_printk(KERN_WARNING, sdev,
6201 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6202 "scmd(%p)\n", scmd);
6203 goto tm_retry;
6204 }
6205
6206 if (task_abort_retries > 1)
6207 sdev_printk(KERN_WARNING, sdev,
6208 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6209 " scmd(%p)\n",
6210 task_abort_retries - 1, scmd);
6211
6212 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6213 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6214 }
6215
6216 if (ioc->broadcast_aen_pending) {
6217 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6218 "%s: loop back due to pending AEN\n",
6219 ioc->name, __func__));
6220 ioc->broadcast_aen_pending = 0;
6221 goto broadcast_aen_retry;
6222 }
6223
6224 out:
6225 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6226 out_no_lock:
6227
6228 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6229 "%s - exit, query_count = %d termination_count = %d\n",
6230 ioc->name, __func__, query_count, termination_count));
6231
6232 ioc->broadcast_aen_busy = 0;
6233 if (!ioc->shost_recovery)
6234 _scsih_ublock_io_all_device(ioc);
6235 mutex_unlock(&ioc->tm_cmds.mutex);
6236}
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246static void
6247_scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6248 struct fw_event_work *fw_event)
6249{
6250 Mpi2EventDataSasDiscovery_t *event_data =
6251 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6252
6253 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6254 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6255 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6256 "start" : "stop");
6257 if (event_data->DiscoveryStatus)
6258 pr_info("discovery_status(0x%08x)",
6259 le32_to_cpu(event_data->DiscoveryStatus));
6260 pr_info("\n");
6261 }
6262
6263 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6264 !ioc->sas_hba.num_phys) {
6265 if (disable_discovery > 0 && ioc->shost_recovery) {
6266
6267 while (ioc->shost_recovery)
6268 ssleep(1);
6269 }
6270 _scsih_sas_host_add(ioc);
6271 }
6272}
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282static int
6283_scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6284{
6285 Mpi2RaidActionRequest_t *mpi_request;
6286 Mpi2RaidActionReply_t *mpi_reply;
6287 u16 smid;
6288 u8 issue_reset = 0;
6289 int rc = 0;
6290 u16 ioc_status;
6291 u32 log_info;
6292
6293 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6294 return rc;
6295
6296 mutex_lock(&ioc->scsih_cmds.mutex);
6297
6298 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6299 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6300 ioc->name, __func__);
6301 rc = -EAGAIN;
6302 goto out;
6303 }
6304 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6305
6306 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6307 if (!smid) {
6308 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6309 ioc->name, __func__);
6310 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6311 rc = -EAGAIN;
6312 goto out;
6313 }
6314
6315 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6316 ioc->scsih_cmds.smid = smid;
6317 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6318
6319 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6320 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6321 mpi_request->PhysDiskNum = phys_disk_num;
6322
6323 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6324 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6325 handle, phys_disk_num));
6326
6327 init_completion(&ioc->scsih_cmds.done);
6328 ioc->put_smid_default(ioc, smid);
6329 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6330
6331 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6332 pr_err(MPT3SAS_FMT "%s: timeout\n",
6333 ioc->name, __func__);
6334 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6335 issue_reset = 1;
6336 rc = -EFAULT;
6337 goto out;
6338 }
6339
6340 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6341
6342 mpi_reply = ioc->scsih_cmds.reply;
6343 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6344 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6345 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6346 else
6347 log_info = 0;
6348 ioc_status &= MPI2_IOCSTATUS_MASK;
6349 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6350 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6351 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6352 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6353 log_info));
6354 rc = -EFAULT;
6355 } else
6356 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6357 "IR RAID_ACTION: completed successfully\n",
6358 ioc->name));
6359 }
6360
6361 out:
6362 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6363 mutex_unlock(&ioc->scsih_cmds.mutex);
6364
6365 if (issue_reset)
6366 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
6367 return rc;
6368}
6369
6370
6371
6372
6373
6374
6375
6376static void
6377_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6378{
6379 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6380 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6381 sdev->no_uld_attach ? "hiding" : "exposing");
6382 WARN_ON(scsi_device_reprobe(sdev));
6383}
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393static void
6394_scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6395 Mpi2EventIrConfigElement_t *element)
6396{
6397 struct _raid_device *raid_device;
6398 unsigned long flags;
6399 u64 wwid;
6400 u16 handle = le16_to_cpu(element->VolDevHandle);
6401 int rc;
6402
6403 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6404 if (!wwid) {
6405 pr_err(MPT3SAS_FMT
6406 "failure at %s:%d/%s()!\n", ioc->name,
6407 __FILE__, __LINE__, __func__);
6408 return;
6409 }
6410
6411 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6412 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6413 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6414
6415 if (raid_device)
6416 return;
6417
6418 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6419 if (!raid_device) {
6420 pr_err(MPT3SAS_FMT
6421 "failure at %s:%d/%s()!\n", ioc->name,
6422 __FILE__, __LINE__, __func__);
6423 return;
6424 }
6425
6426 raid_device->id = ioc->sas_id++;
6427 raid_device->channel = RAID_CHANNEL;
6428 raid_device->handle = handle;
6429 raid_device->wwid = wwid;
6430 _scsih_raid_device_add(ioc, raid_device);
6431 if (!ioc->wait_for_discovery_to_complete) {
6432 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6433 raid_device->id, 0);
6434 if (rc)
6435 _scsih_raid_device_remove(ioc, raid_device);
6436 } else {
6437 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6438 _scsih_determine_boot_device(ioc, raid_device, 1);
6439 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6440 }
6441}
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451static void
6452_scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6453{
6454 struct _raid_device *raid_device;
6455 unsigned long flags;
6456 struct MPT3SAS_TARGET *sas_target_priv_data;
6457 struct scsi_target *starget = NULL;
6458
6459 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6460 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6461 if (raid_device) {
6462 if (raid_device->starget) {
6463 starget = raid_device->starget;
6464 sas_target_priv_data = starget->hostdata;
6465 sas_target_priv_data->deleted = 1;
6466 }
6467 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6468 ioc->name, raid_device->handle,
6469 (unsigned long long) raid_device->wwid);
6470 list_del(&raid_device->list);
6471 kfree(raid_device);
6472 }
6473 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6474 if (starget)
6475 scsi_remove_target(&starget->dev);
6476}
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486static void
6487_scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6488 Mpi2EventIrConfigElement_t *element)
6489{
6490 struct _sas_device *sas_device;
6491 struct scsi_target *starget = NULL;
6492 struct MPT3SAS_TARGET *sas_target_priv_data;
6493 unsigned long flags;
6494 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6495
6496 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6497 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6498 if (sas_device) {
6499 sas_device->volume_handle = 0;
6500 sas_device->volume_wwid = 0;
6501 clear_bit(handle, ioc->pd_handles);
6502 if (sas_device->starget && sas_device->starget->hostdata) {
6503 starget = sas_device->starget;
6504 sas_target_priv_data = starget->hostdata;
6505 sas_target_priv_data->flags &=
6506 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6507 }
6508 }
6509 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6510 if (!sas_device)
6511 return;
6512
6513
6514 if (starget)
6515 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6516
6517 sas_device_put(sas_device);
6518}
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528static void
6529_scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6530 Mpi2EventIrConfigElement_t *element)
6531{
6532 struct _sas_device *sas_device;
6533 struct scsi_target *starget = NULL;
6534 struct MPT3SAS_TARGET *sas_target_priv_data;
6535 unsigned long flags;
6536 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6537 u16 volume_handle = 0;
6538 u64 volume_wwid = 0;
6539
6540 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6541 if (volume_handle)
6542 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6543 &volume_wwid);
6544
6545 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6546 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6547 if (sas_device) {
6548 set_bit(handle, ioc->pd_handles);
6549 if (sas_device->starget && sas_device->starget->hostdata) {
6550 starget = sas_device->starget;
6551 sas_target_priv_data = starget->hostdata;
6552 sas_target_priv_data->flags |=
6553 MPT_TARGET_FLAGS_RAID_COMPONENT;
6554 sas_device->volume_handle = volume_handle;
6555 sas_device->volume_wwid = volume_wwid;
6556 }
6557 }
6558 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6559 if (!sas_device)
6560 return;
6561
6562
6563 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6564
6565 if (starget)
6566 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6567
6568 sas_device_put(sas_device);
6569}
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579static void
6580_scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6581 Mpi2EventIrConfigElement_t *element)
6582{
6583 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6584
6585 _scsih_device_remove_by_handle(ioc, handle);
6586}
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596static void
6597_scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6598 Mpi2EventIrConfigElement_t *element)
6599{
6600 struct _sas_device *sas_device;
6601 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6602 Mpi2ConfigReply_t mpi_reply;
6603 Mpi2SasDevicePage0_t sas_device_pg0;
6604 u32 ioc_status;
6605 u64 sas_address;
6606 u16 parent_handle;
6607
6608 set_bit(handle, ioc->pd_handles);
6609
6610 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6611 if (sas_device) {
6612 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6613 sas_device_put(sas_device);
6614 return;
6615 }
6616
6617 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6618 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6619 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6620 ioc->name, __FILE__, __LINE__, __func__);
6621 return;
6622 }
6623
6624 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6625 MPI2_IOCSTATUS_MASK;
6626 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6627 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6628 ioc->name, __FILE__, __LINE__, __func__);
6629 return;
6630 }
6631
6632 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6633 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6634 mpt3sas_transport_update_links(ioc, sas_address, handle,
6635 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6636
6637 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6638 _scsih_add_device(ioc, handle, 0, 1);
6639}
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649static void
6650_scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6651 Mpi2EventDataIrConfigChangeList_t *event_data)
6652{
6653 Mpi2EventIrConfigElement_t *element;
6654 u8 element_type;
6655 int i;
6656 char *reason_str = NULL, *element_str = NULL;
6657
6658 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6659
6660 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6661 ioc->name, (le32_to_cpu(event_data->Flags) &
6662 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6663 "foreign" : "native", event_data->NumElements);
6664 for (i = 0; i < event_data->NumElements; i++, element++) {
6665 switch (element->ReasonCode) {
6666 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6667 reason_str = "add";
6668 break;
6669 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6670 reason_str = "remove";
6671 break;
6672 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6673 reason_str = "no change";
6674 break;
6675 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6676 reason_str = "hide";
6677 break;
6678 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6679 reason_str = "unhide";
6680 break;
6681 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6682 reason_str = "volume_created";
6683 break;
6684 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6685 reason_str = "volume_deleted";
6686 break;
6687 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6688 reason_str = "pd_created";
6689 break;
6690 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6691 reason_str = "pd_deleted";
6692 break;
6693 default:
6694 reason_str = "unknown reason";
6695 break;
6696 }
6697 element_type = le16_to_cpu(element->ElementFlags) &
6698 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6699 switch (element_type) {
6700 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6701 element_str = "volume";
6702 break;
6703 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6704 element_str = "phys disk";
6705 break;
6706 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6707 element_str = "hot spare";
6708 break;
6709 default:
6710 element_str = "unknown element";
6711 break;
6712 }
6713 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6714 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6715 reason_str, le16_to_cpu(element->VolDevHandle),
6716 le16_to_cpu(element->PhysDiskDevHandle),
6717 element->PhysDiskNum);
6718 }
6719}
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729static void
6730_scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6731 struct fw_event_work *fw_event)
6732{
6733 Mpi2EventIrConfigElement_t *element;
6734 int i;
6735 u8 foreign_config;
6736 Mpi2EventDataIrConfigChangeList_t *event_data =
6737 (Mpi2EventDataIrConfigChangeList_t *)
6738 fw_event->event_data;
6739
6740 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6741 (!ioc->hide_ir_msg))
6742 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6743
6744 foreign_config = (le32_to_cpu(event_data->Flags) &
6745 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6746
6747 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6748 if (ioc->shost_recovery &&
6749 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6750 for (i = 0; i < event_data->NumElements; i++, element++) {
6751 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6752 _scsih_ir_fastpath(ioc,
6753 le16_to_cpu(element->PhysDiskDevHandle),
6754 element->PhysDiskNum);
6755 }
6756 return;
6757 }
6758
6759 for (i = 0; i < event_data->NumElements; i++, element++) {
6760
6761 switch (element->ReasonCode) {
6762 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6763 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6764 if (!foreign_config)
6765 _scsih_sas_volume_add(ioc, element);
6766 break;
6767 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6768 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6769 if (!foreign_config)
6770 _scsih_sas_volume_delete(ioc,
6771 le16_to_cpu(element->VolDevHandle));
6772 break;
6773 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6774 if (!ioc->is_warpdrive)
6775 _scsih_sas_pd_hide(ioc, element);
6776 break;
6777 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6778 if (!ioc->is_warpdrive)
6779 _scsih_sas_pd_expose(ioc, element);
6780 break;
6781 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6782 if (!ioc->is_warpdrive)
6783 _scsih_sas_pd_add(ioc, element);
6784 break;
6785 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6786 if (!ioc->is_warpdrive)
6787 _scsih_sas_pd_delete(ioc, element);
6788 break;
6789 }
6790 }
6791}
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801static void
6802_scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6803 struct fw_event_work *fw_event)
6804{
6805 u64 wwid;
6806 unsigned long flags;
6807 struct _raid_device *raid_device;
6808 u16 handle;
6809 u32 state;
6810 int rc;
6811 Mpi2EventDataIrVolume_t *event_data =
6812 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6813
6814 if (ioc->shost_recovery)
6815 return;
6816
6817 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6818 return;
6819
6820 handle = le16_to_cpu(event_data->VolDevHandle);
6821 state = le32_to_cpu(event_data->NewValue);
6822 if (!ioc->hide_ir_msg)
6823 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6824 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6825 ioc->name, __func__, handle,
6826 le32_to_cpu(event_data->PreviousValue), state));
6827 switch (state) {
6828 case MPI2_RAID_VOL_STATE_MISSING:
6829 case MPI2_RAID_VOL_STATE_FAILED:
6830 _scsih_sas_volume_delete(ioc, handle);
6831 break;
6832
6833 case MPI2_RAID_VOL_STATE_ONLINE:
6834 case MPI2_RAID_VOL_STATE_DEGRADED:
6835 case MPI2_RAID_VOL_STATE_OPTIMAL:
6836
6837 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6838 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6839 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6840
6841 if (raid_device)
6842 break;
6843
6844 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6845 if (!wwid) {
6846 pr_err(MPT3SAS_FMT
6847 "failure at %s:%d/%s()!\n", ioc->name,
6848 __FILE__, __LINE__, __func__);
6849 break;
6850 }
6851
6852 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6853 if (!raid_device) {
6854 pr_err(MPT3SAS_FMT
6855 "failure at %s:%d/%s()!\n", ioc->name,
6856 __FILE__, __LINE__, __func__);
6857 break;
6858 }
6859
6860 raid_device->id = ioc->sas_id++;
6861 raid_device->channel = RAID_CHANNEL;
6862 raid_device->handle = handle;
6863 raid_device->wwid = wwid;
6864 _scsih_raid_device_add(ioc, raid_device);
6865 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6866 raid_device->id, 0);
6867 if (rc)
6868 _scsih_raid_device_remove(ioc, raid_device);
6869 break;
6870
6871 case MPI2_RAID_VOL_STATE_INITIALIZING:
6872 default:
6873 break;
6874 }
6875}
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885static void
6886_scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6887 struct fw_event_work *fw_event)
6888{
6889 u16 handle, parent_handle;
6890 u32 state;
6891 struct _sas_device *sas_device;
6892 Mpi2ConfigReply_t mpi_reply;
6893 Mpi2SasDevicePage0_t sas_device_pg0;
6894 u32 ioc_status;
6895 Mpi2EventDataIrPhysicalDisk_t *event_data =
6896 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6897 u64 sas_address;
6898
6899 if (ioc->shost_recovery)
6900 return;
6901
6902 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6903 return;
6904
6905 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6906 state = le32_to_cpu(event_data->NewValue);
6907
6908 if (!ioc->hide_ir_msg)
6909 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6910 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6911 ioc->name, __func__, handle,
6912 le32_to_cpu(event_data->PreviousValue), state));
6913
6914 switch (state) {
6915 case MPI2_RAID_PD_STATE_ONLINE:
6916 case MPI2_RAID_PD_STATE_DEGRADED:
6917 case MPI2_RAID_PD_STATE_REBUILDING:
6918 case MPI2_RAID_PD_STATE_OPTIMAL:
6919 case MPI2_RAID_PD_STATE_HOT_SPARE:
6920
6921 if (!ioc->is_warpdrive)
6922 set_bit(handle, ioc->pd_handles);
6923
6924 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6925 if (sas_device) {
6926 sas_device_put(sas_device);
6927 return;
6928 }
6929
6930 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6931 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6932 handle))) {
6933 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6934 ioc->name, __FILE__, __LINE__, __func__);
6935 return;
6936 }
6937
6938 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6939 MPI2_IOCSTATUS_MASK;
6940 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6941 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6942 ioc->name, __FILE__, __LINE__, __func__);
6943 return;
6944 }
6945
6946 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6947 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6948 mpt3sas_transport_update_links(ioc, sas_address, handle,
6949 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6950
6951 _scsih_add_device(ioc, handle, 0, 1);
6952
6953 break;
6954
6955 case MPI2_RAID_PD_STATE_OFFLINE:
6956 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6957 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6958 default:
6959 break;
6960 }
6961}
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971static void
6972_scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6973 Mpi2EventDataIrOperationStatus_t *event_data)
6974{
6975 char *reason_str = NULL;
6976
6977 switch (event_data->RAIDOperation) {
6978 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6979 reason_str = "resync";
6980 break;
6981 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6982 reason_str = "online capacity expansion";
6983 break;
6984 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6985 reason_str = "consistency check";
6986 break;
6987 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6988 reason_str = "background init";
6989 break;
6990 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6991 reason_str = "make data consistent";
6992 break;
6993 }
6994
6995 if (!reason_str)
6996 return;
6997
6998 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6999 "\thandle(0x%04x), percent complete(%d)\n",
7000 ioc->name, reason_str,
7001 le16_to_cpu(event_data->VolDevHandle),
7002 event_data->PercentComplete);
7003}
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013static void
7014_scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
7015 struct fw_event_work *fw_event)
7016{
7017 Mpi2EventDataIrOperationStatus_t *event_data =
7018 (Mpi2EventDataIrOperationStatus_t *)
7019 fw_event->event_data;
7020 static struct _raid_device *raid_device;
7021 unsigned long flags;
7022 u16 handle;
7023
7024 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
7025 (!ioc->hide_ir_msg))
7026 _scsih_sas_ir_operation_status_event_debug(ioc,
7027 event_data);
7028
7029
7030 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
7031
7032 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7033 handle = le16_to_cpu(event_data->VolDevHandle);
7034 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7035 if (raid_device)
7036 raid_device->percent_complete =
7037 event_data->PercentComplete;
7038 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7039 }
7040}
7041
7042
7043
7044
7045
7046
7047
7048
7049static void
7050_scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
7051{
7052 struct MPT3SAS_DEVICE *sas_device_priv_data;
7053 struct scsi_device *sdev;
7054
7055 shost_for_each_device(sdev, ioc->shost) {
7056 sas_device_priv_data = sdev->hostdata;
7057 if (sas_device_priv_data && sas_device_priv_data->sas_target)
7058 sas_device_priv_data->sas_target->deleted = 1;
7059 }
7060}
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072static void
7073_scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
7074Mpi2SasDevicePage0_t *sas_device_pg0)
7075{
7076 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7077 struct scsi_target *starget;
7078 struct _sas_device *sas_device;
7079 unsigned long flags;
7080
7081 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7082 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
7083 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
7084 (sas_device->slot == sas_device_pg0->Slot)) {
7085 sas_device->responding = 1;
7086 starget = sas_device->starget;
7087 if (starget && starget->hostdata) {
7088 sas_target_priv_data = starget->hostdata;
7089 sas_target_priv_data->tm_busy = 0;
7090 sas_target_priv_data->deleted = 0;
7091 } else
7092 sas_target_priv_data = NULL;
7093 if (starget) {
7094 starget_printk(KERN_INFO, starget,
7095 "handle(0x%04x), sas_addr(0x%016llx)\n",
7096 sas_device_pg0->DevHandle,
7097 (unsigned long long)
7098 sas_device->sas_address);
7099
7100 if (sas_device->enclosure_handle != 0)
7101 starget_printk(KERN_INFO, starget,
7102 "enclosure logical id(0x%016llx),"
7103 " slot(%d)\n",
7104 (unsigned long long)
7105 sas_device->enclosure_logical_id,
7106 sas_device->slot);
7107 }
7108 if (sas_device_pg0->Flags &
7109 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7110 sas_device->enclosure_level =
7111 sas_device_pg0->EnclosureLevel;
7112 memcpy(&sas_device->connector_name[0],
7113 &sas_device_pg0->ConnectorName[0], 4);
7114 } else {
7115 sas_device->enclosure_level = 0;
7116 sas_device->connector_name[0] = '\0';
7117 }
7118
7119 if (sas_device->handle == sas_device_pg0->DevHandle)
7120 goto out;
7121 pr_info("\thandle changed from(0x%04x)!!!\n",
7122 sas_device->handle);
7123 sas_device->handle = sas_device_pg0->DevHandle;
7124 if (sas_target_priv_data)
7125 sas_target_priv_data->handle =
7126 sas_device_pg0->DevHandle;
7127 goto out;
7128 }
7129 }
7130 out:
7131 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7132}
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143static void
7144_scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7145{
7146 Mpi2SasDevicePage0_t sas_device_pg0;
7147 Mpi2ConfigReply_t mpi_reply;
7148 u16 ioc_status;
7149 u16 handle;
7150 u32 device_info;
7151
7152 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
7153
7154 if (list_empty(&ioc->sas_device_list))
7155 goto out;
7156
7157 handle = 0xFFFF;
7158 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7159 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7160 handle))) {
7161 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7162 MPI2_IOCSTATUS_MASK;
7163 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7164 break;
7165 handle = sas_device_pg0.DevHandle =
7166 le16_to_cpu(sas_device_pg0.DevHandle);
7167 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7168 if (!(_scsih_is_end_device(device_info)))
7169 continue;
7170 sas_device_pg0.SASAddress =
7171 le64_to_cpu(sas_device_pg0.SASAddress);
7172 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
7173 sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags);
7174 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
7175 }
7176
7177 out:
7178 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
7179 ioc->name);
7180}
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193static void
7194_scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7195 u16 handle)
7196{
7197 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7198 struct scsi_target *starget;
7199 struct _raid_device *raid_device;
7200 unsigned long flags;
7201
7202 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7203 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7204 if (raid_device->wwid == wwid && raid_device->starget) {
7205 starget = raid_device->starget;
7206 if (starget && starget->hostdata) {
7207 sas_target_priv_data = starget->hostdata;
7208 sas_target_priv_data->deleted = 0;
7209 } else
7210 sas_target_priv_data = NULL;
7211 raid_device->responding = 1;
7212 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7213 starget_printk(KERN_INFO, raid_device->starget,
7214 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7215 (unsigned long long)raid_device->wwid);
7216
7217
7218
7219
7220
7221
7222 mpt3sas_init_warpdrive_properties(ioc, raid_device);
7223 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7224 if (raid_device->handle == handle) {
7225 spin_unlock_irqrestore(&ioc->raid_device_lock,
7226 flags);
7227 return;
7228 }
7229 pr_info("\thandle changed from(0x%04x)!!!\n",
7230 raid_device->handle);
7231 raid_device->handle = handle;
7232 if (sas_target_priv_data)
7233 sas_target_priv_data->handle = handle;
7234 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7235 return;
7236 }
7237 }
7238 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7239}
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250static void
7251_scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7252{
7253 Mpi2RaidVolPage1_t volume_pg1;
7254 Mpi2RaidVolPage0_t volume_pg0;
7255 Mpi2RaidPhysDiskPage0_t pd_pg0;
7256 Mpi2ConfigReply_t mpi_reply;
7257 u16 ioc_status;
7258 u16 handle;
7259 u8 phys_disk_num;
7260
7261 if (!ioc->ir_firmware)
7262 return;
7263
7264 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7265 ioc->name);
7266
7267 if (list_empty(&ioc->raid_device_list))
7268 goto out;
7269
7270 handle = 0xFFFF;
7271 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7272 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7273 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7274 MPI2_IOCSTATUS_MASK;
7275 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7276 break;
7277 handle = le16_to_cpu(volume_pg1.DevHandle);
7278
7279 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7280 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7281 sizeof(Mpi2RaidVolPage0_t)))
7282 continue;
7283
7284 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7285 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7286 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7287 _scsih_mark_responding_raid_device(ioc,
7288 le64_to_cpu(volume_pg1.WWID), handle);
7289 }
7290
7291
7292 if (!ioc->is_warpdrive) {
7293 phys_disk_num = 0xFF;
7294 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7295 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7296 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7297 phys_disk_num))) {
7298 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7299 MPI2_IOCSTATUS_MASK;
7300 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7301 break;
7302 phys_disk_num = pd_pg0.PhysDiskNum;
7303 handle = le16_to_cpu(pd_pg0.DevHandle);
7304 set_bit(handle, ioc->pd_handles);
7305 }
7306 }
7307 out:
7308 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7309 ioc->name);
7310}
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323static void
7324_scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7325 u16 handle)
7326{
7327 struct _sas_node *sas_expander;
7328 unsigned long flags;
7329 int i;
7330
7331 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7332 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7333 if (sas_expander->sas_address != sas_address)
7334 continue;
7335 sas_expander->responding = 1;
7336 if (sas_expander->handle == handle)
7337 goto out;
7338 pr_info("\texpander(0x%016llx): handle changed" \
7339 " from(0x%04x) to (0x%04x)!!!\n",
7340 (unsigned long long)sas_expander->sas_address,
7341 sas_expander->handle, handle);
7342 sas_expander->handle = handle;
7343 for (i = 0 ; i < sas_expander->num_phys ; i++)
7344 sas_expander->phy[i].handle = handle;
7345 goto out;
7346 }
7347 out:
7348 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7349}
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360static void
7361_scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7362{
7363 Mpi2ExpanderPage0_t expander_pg0;
7364 Mpi2ConfigReply_t mpi_reply;
7365 u16 ioc_status;
7366 u64 sas_address;
7367 u16 handle;
7368
7369 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7370
7371 if (list_empty(&ioc->sas_expander_list))
7372 goto out;
7373
7374 handle = 0xFFFF;
7375 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7376 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7377
7378 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7379 MPI2_IOCSTATUS_MASK;
7380 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7381 break;
7382
7383 handle = le16_to_cpu(expander_pg0.DevHandle);
7384 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7385 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7386 handle,
7387 (unsigned long long)sas_address);
7388 _scsih_mark_responding_expander(ioc, sas_address, handle);
7389 }
7390
7391 out:
7392 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7393}
7394
7395
7396
7397
7398
7399
7400
7401static void
7402_scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7403{
7404 struct _sas_device *sas_device, *sas_device_next;
7405 struct _sas_node *sas_expander, *sas_expander_next;
7406 struct _raid_device *raid_device, *raid_device_next;
7407 struct list_head tmp_list;
7408 unsigned long flags;
7409 LIST_HEAD(head);
7410
7411 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7412 ioc->name);
7413
7414
7415 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7416 ioc->name);
7417
7418
7419
7420
7421 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7422 list_for_each_entry_safe(sas_device, sas_device_next,
7423 &ioc->sas_device_list, list) {
7424 if (!sas_device->responding)
7425 list_move_tail(&sas_device->list, &head);
7426 else
7427 sas_device->responding = 0;
7428 }
7429 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7430
7431
7432
7433
7434 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7435 _scsih_remove_device(ioc, sas_device);
7436 list_del_init(&sas_device->list);
7437 sas_device_put(sas_device);
7438 }
7439
7440
7441 if (ioc->ir_firmware) {
7442 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7443 ioc->name);
7444 list_for_each_entry_safe(raid_device, raid_device_next,
7445 &ioc->raid_device_list, list) {
7446 if (!raid_device->responding)
7447 _scsih_sas_volume_delete(ioc,
7448 raid_device->handle);
7449 else
7450 raid_device->responding = 0;
7451 }
7452 }
7453
7454
7455 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7456 ioc->name);
7457 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7458 INIT_LIST_HEAD(&tmp_list);
7459 list_for_each_entry_safe(sas_expander, sas_expander_next,
7460 &ioc->sas_expander_list, list) {
7461 if (!sas_expander->responding)
7462 list_move_tail(&sas_expander->list, &tmp_list);
7463 else
7464 sas_expander->responding = 0;
7465 }
7466 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7467 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7468 list) {
7469 list_del(&sas_expander->list);
7470 _scsih_expander_node_remove(ioc, sas_expander);
7471 }
7472
7473 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7474 ioc->name);
7475
7476
7477 _scsih_ublock_io_all_device(ioc);
7478}
7479
7480static void
7481_scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7482 struct _sas_node *sas_expander, u16 handle)
7483{
7484 Mpi2ExpanderPage1_t expander_pg1;
7485 Mpi2ConfigReply_t mpi_reply;
7486 int i;
7487
7488 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7489 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7490 &expander_pg1, i, handle))) {
7491 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7492 ioc->name, __FILE__, __LINE__, __func__);
7493 return;
7494 }
7495
7496 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7497 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7498 expander_pg1.NegotiatedLinkRate >> 4);
7499 }
7500}
7501
7502
7503
7504
7505
7506
7507
7508static void
7509_scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7510{
7511 Mpi2ExpanderPage0_t expander_pg0;
7512 Mpi2SasDevicePage0_t sas_device_pg0;
7513 Mpi2RaidVolPage1_t volume_pg1;
7514 Mpi2RaidVolPage0_t volume_pg0;
7515 Mpi2RaidPhysDiskPage0_t pd_pg0;
7516 Mpi2EventIrConfigElement_t element;
7517 Mpi2ConfigReply_t mpi_reply;
7518 u8 phys_disk_num;
7519 u16 ioc_status;
7520 u16 handle, parent_handle;
7521 u64 sas_address;
7522 struct _sas_device *sas_device;
7523 struct _sas_node *expander_device;
7524 static struct _raid_device *raid_device;
7525 u8 retry_count;
7526 unsigned long flags;
7527
7528 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7529
7530 _scsih_sas_host_refresh(ioc);
7531
7532 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7533
7534
7535 handle = 0xFFFF;
7536 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7537 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7538 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7539 MPI2_IOCSTATUS_MASK;
7540 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7541 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7542 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7543 ioc->name, ioc_status,
7544 le32_to_cpu(mpi_reply.IOCLogInfo));
7545 break;
7546 }
7547 handle = le16_to_cpu(expander_pg0.DevHandle);
7548 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7549 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7550 ioc, le64_to_cpu(expander_pg0.SASAddress));
7551 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7552 if (expander_device)
7553 _scsih_refresh_expander_links(ioc, expander_device,
7554 handle);
7555 else {
7556 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7557 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7558 handle, (unsigned long long)
7559 le64_to_cpu(expander_pg0.SASAddress));
7560 _scsih_expander_add(ioc, handle);
7561 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7562 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7563 handle, (unsigned long long)
7564 le64_to_cpu(expander_pg0.SASAddress));
7565 }
7566 }
7567
7568 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7569 ioc->name);
7570
7571 if (!ioc->ir_firmware)
7572 goto skip_to_sas;
7573
7574 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7575
7576
7577 phys_disk_num = 0xFF;
7578 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7579 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7580 phys_disk_num))) {
7581 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7582 MPI2_IOCSTATUS_MASK;
7583 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7584 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7585 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7586 ioc->name, ioc_status,
7587 le32_to_cpu(mpi_reply.IOCLogInfo));
7588 break;
7589 }
7590 phys_disk_num = pd_pg0.PhysDiskNum;
7591 handle = le16_to_cpu(pd_pg0.DevHandle);
7592 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7593 if (sas_device) {
7594 sas_device_put(sas_device);
7595 continue;
7596 }
7597 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7598 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7599 handle) != 0)
7600 continue;
7601 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7602 MPI2_IOCSTATUS_MASK;
7603 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7604 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7605 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7606 ioc->name, ioc_status,
7607 le32_to_cpu(mpi_reply.IOCLogInfo));
7608 break;
7609 }
7610 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7611 if (!_scsih_get_sas_address(ioc, parent_handle,
7612 &sas_address)) {
7613 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7614 " handle (0x%04x), sas_addr(0x%016llx)\n",
7615 ioc->name, handle, (unsigned long long)
7616 le64_to_cpu(sas_device_pg0.SASAddress));
7617 mpt3sas_transport_update_links(ioc, sas_address,
7618 handle, sas_device_pg0.PhyNum,
7619 MPI2_SAS_NEG_LINK_RATE_1_5);
7620 set_bit(handle, ioc->pd_handles);
7621 retry_count = 0;
7622
7623
7624
7625
7626 while (_scsih_add_device(ioc, handle, retry_count++,
7627 1)) {
7628 ssleep(1);
7629 }
7630 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7631 " handle (0x%04x), sas_addr(0x%016llx)\n",
7632 ioc->name, handle, (unsigned long long)
7633 le64_to_cpu(sas_device_pg0.SASAddress));
7634 }
7635 }
7636
7637 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7638 ioc->name);
7639
7640 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7641
7642
7643 handle = 0xFFFF;
7644 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7645 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7646 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7647 MPI2_IOCSTATUS_MASK;
7648 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7649 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7650 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7651 ioc->name, ioc_status,
7652 le32_to_cpu(mpi_reply.IOCLogInfo));
7653 break;
7654 }
7655 handle = le16_to_cpu(volume_pg1.DevHandle);
7656 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7657 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7658 le64_to_cpu(volume_pg1.WWID));
7659 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7660 if (raid_device)
7661 continue;
7662 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7663 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7664 sizeof(Mpi2RaidVolPage0_t)))
7665 continue;
7666 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7667 MPI2_IOCSTATUS_MASK;
7668 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7669 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7670 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7671 ioc->name, ioc_status,
7672 le32_to_cpu(mpi_reply.IOCLogInfo));
7673 break;
7674 }
7675 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7676 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7677 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7678 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7679 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7680 element.VolDevHandle = volume_pg1.DevHandle;
7681 pr_info(MPT3SAS_FMT
7682 "\tBEFORE adding volume: handle (0x%04x)\n",
7683 ioc->name, volume_pg1.DevHandle);
7684 _scsih_sas_volume_add(ioc, &element);
7685 pr_info(MPT3SAS_FMT
7686 "\tAFTER adding volume: handle (0x%04x)\n",
7687 ioc->name, volume_pg1.DevHandle);
7688 }
7689 }
7690
7691 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7692 ioc->name);
7693
7694 skip_to_sas:
7695
7696 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7697 ioc->name);
7698
7699
7700 handle = 0xFFFF;
7701 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7702 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7703 handle))) {
7704 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7705 MPI2_IOCSTATUS_MASK;
7706 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7707 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7708 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7709 ioc->name, ioc_status,
7710 le32_to_cpu(mpi_reply.IOCLogInfo));
7711 break;
7712 }
7713 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7714 if (!(_scsih_is_end_device(
7715 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7716 continue;
7717 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7718 le64_to_cpu(sas_device_pg0.SASAddress));
7719 if (sas_device) {
7720 sas_device_put(sas_device);
7721 continue;
7722 }
7723 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7724 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7725 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7726 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7727 handle, (unsigned long long)
7728 le64_to_cpu(sas_device_pg0.SASAddress));
7729 mpt3sas_transport_update_links(ioc, sas_address, handle,
7730 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7731 retry_count = 0;
7732
7733
7734
7735
7736 while (_scsih_add_device(ioc, handle, retry_count++,
7737 0)) {
7738 ssleep(1);
7739 }
7740 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7741 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7742 handle, (unsigned long long)
7743 le64_to_cpu(sas_device_pg0.SASAddress));
7744 }
7745 }
7746 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7747 ioc->name);
7748
7749 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7750}
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763void
7764mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7765{
7766 switch (reset_phase) {
7767 case MPT3_IOC_PRE_RESET:
7768 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7769 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7770 break;
7771 case MPT3_IOC_AFTER_RESET:
7772 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7773 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7774 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7775 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7776 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7777 complete(&ioc->scsih_cmds.done);
7778 }
7779 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7780 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7781 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7782 complete(&ioc->tm_cmds.done);
7783 }
7784
7785 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
7786 memset(ioc->device_remove_in_progress, 0,
7787 ioc->device_remove_in_progress_sz);
7788 _scsih_fw_event_cleanup_queue(ioc);
7789 _scsih_flush_running_cmds(ioc);
7790 break;
7791 case MPT3_IOC_DONE_RESET:
7792 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7793 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7794 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7795 !ioc->sas_hba.num_phys)) {
7796 _scsih_prep_device_scan(ioc);
7797 _scsih_search_responding_sas_devices(ioc);
7798 _scsih_search_responding_raid_devices(ioc);
7799 _scsih_search_responding_expanders(ioc);
7800 _scsih_error_recovery_delete_devices(ioc);
7801 }
7802 break;
7803 }
7804}
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814static void
7815_mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7816{
7817 _scsih_fw_event_del_from_list(ioc, fw_event);
7818
7819
7820 if (ioc->remove_host || ioc->pci_error_recovery) {
7821 fw_event_work_put(fw_event);
7822 return;
7823 }
7824
7825 switch (fw_event->event) {
7826 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7827 mpt3sas_process_trigger_data(ioc,
7828 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7829 fw_event->event_data);
7830 break;
7831 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7832 while (scsi_host_in_recovery(ioc->shost) ||
7833 ioc->shost_recovery) {
7834
7835
7836
7837
7838 if (ioc->remove_host)
7839 goto out;
7840 ssleep(1);
7841 }
7842 _scsih_remove_unresponding_sas_devices(ioc);
7843 _scsih_scan_for_devices_after_reset(ioc);
7844 break;
7845 case MPT3SAS_PORT_ENABLE_COMPLETE:
7846 ioc->start_scan = 0;
7847 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7848 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7849 missing_delay[1]);
7850 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7851 "port enable: complete from worker thread\n",
7852 ioc->name));
7853 break;
7854 case MPT3SAS_TURN_ON_PFA_LED:
7855 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7856 break;
7857 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7858 _scsih_sas_topology_change_event(ioc, fw_event);
7859 break;
7860 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7861 _scsih_sas_device_status_change_event(ioc, fw_event);
7862 break;
7863 case MPI2_EVENT_SAS_DISCOVERY:
7864 _scsih_sas_discovery_event(ioc, fw_event);
7865 break;
7866 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7867 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7868 break;
7869 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7870 _scsih_sas_enclosure_dev_status_change_event(ioc,
7871 fw_event);
7872 break;
7873 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7874 _scsih_sas_ir_config_change_event(ioc, fw_event);
7875 break;
7876 case MPI2_EVENT_IR_VOLUME:
7877 _scsih_sas_ir_volume_event(ioc, fw_event);
7878 break;
7879 case MPI2_EVENT_IR_PHYSICAL_DISK:
7880 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7881 break;
7882 case MPI2_EVENT_IR_OPERATION_STATUS:
7883 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7884 break;
7885 }
7886out:
7887 fw_event_work_put(fw_event);
7888}
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901static void
7902_firmware_event_work(struct work_struct *work)
7903{
7904 struct fw_event_work *fw_event = container_of(work,
7905 struct fw_event_work, work);
7906
7907 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7908}
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923u8
7924mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7925 u32 reply)
7926{
7927 struct fw_event_work *fw_event;
7928 Mpi2EventNotificationReply_t *mpi_reply;
7929 u16 event;
7930 u16 sz;
7931 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
7932
7933
7934 if (ioc->remove_host || ioc->pci_error_recovery)
7935 return 1;
7936
7937 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7938
7939 if (unlikely(!mpi_reply)) {
7940 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7941 ioc->name, __FILE__, __LINE__, __func__);
7942 return 1;
7943 }
7944
7945 event = le16_to_cpu(mpi_reply->Event);
7946
7947 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7948 mpt3sas_trigger_event(ioc, event, 0);
7949
7950 switch (event) {
7951
7952 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7953 {
7954 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7955 (Mpi2EventDataSasBroadcastPrimitive_t *)
7956 mpi_reply->EventData;
7957
7958 if (baen_data->Primitive !=
7959 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7960 return 1;
7961
7962 if (ioc->broadcast_aen_busy) {
7963 ioc->broadcast_aen_pending++;
7964 return 1;
7965 } else
7966 ioc->broadcast_aen_busy = 1;
7967 break;
7968 }
7969
7970 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7971 _scsih_check_topo_delete_events(ioc,
7972 (Mpi2EventDataSasTopologyChangeList_t *)
7973 mpi_reply->EventData);
7974 break;
7975 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7976 _scsih_check_ir_config_unhide_events(ioc,
7977 (Mpi2EventDataIrConfigChangeList_t *)
7978 mpi_reply->EventData);
7979 break;
7980 case MPI2_EVENT_IR_VOLUME:
7981 _scsih_check_volume_delete_events(ioc,
7982 (Mpi2EventDataIrVolume_t *)
7983 mpi_reply->EventData);
7984 break;
7985 case MPI2_EVENT_LOG_ENTRY_ADDED:
7986 {
7987 Mpi2EventDataLogEntryAdded_t *log_entry;
7988 u32 *log_code;
7989
7990 if (!ioc->is_warpdrive)
7991 break;
7992
7993 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7994 mpi_reply->EventData;
7995 log_code = (u32 *)log_entry->LogData;
7996
7997 if (le16_to_cpu(log_entry->LogEntryQualifier)
7998 != MPT2_WARPDRIVE_LOGENTRY)
7999 break;
8000
8001 switch (le32_to_cpu(*log_code)) {
8002 case MPT2_WARPDRIVE_LC_SSDT:
8003 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
8004 "IO Throttling has occurred in the WarpDrive "
8005 "subsystem. Check WarpDrive documentation for "
8006 "additional details.\n", ioc->name);
8007 break;
8008 case MPT2_WARPDRIVE_LC_SSDLW:
8009 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
8010 "Program/Erase Cycles for the WarpDrive subsystem "
8011 "in degraded range. Check WarpDrive documentation "
8012 "for additional details.\n", ioc->name);
8013 break;
8014 case MPT2_WARPDRIVE_LC_SSDLF:
8015 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
8016 "There are no Program/Erase Cycles for the "
8017 "WarpDrive subsystem. The storage device will be "
8018 "in read-only mode. Check WarpDrive documentation "
8019 "for additional details.\n", ioc->name);
8020 break;
8021 case MPT2_WARPDRIVE_LC_BRMF:
8022 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
8023 "The Backup Rail Monitor has failed on the "
8024 "WarpDrive subsystem. Check WarpDrive "
8025 "documentation for additional details.\n",
8026 ioc->name);
8027 break;
8028 }
8029
8030 break;
8031 }
8032 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
8033 case MPI2_EVENT_IR_OPERATION_STATUS:
8034 case MPI2_EVENT_SAS_DISCOVERY:
8035 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
8036 case MPI2_EVENT_IR_PHYSICAL_DISK:
8037 break;
8038
8039 case MPI2_EVENT_TEMP_THRESHOLD:
8040 _scsih_temp_threshold_events(ioc,
8041 (Mpi2EventDataTemperature_t *)
8042 mpi_reply->EventData);
8043 break;
8044 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
8045 ActiveCableEventData =
8046 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
8047 if (ActiveCableEventData->ReasonCode ==
8048 MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER) {
8049 pr_info(MPT3SAS_FMT "Currently an active cable with ReceptacleID %d",
8050 ioc->name, ActiveCableEventData->ReceptacleID);
8051 pr_info("cannot be powered and devices connected to this active cable");
8052 pr_info("will not be seen. This active cable");
8053 pr_info("requires %d mW of power",
8054 ActiveCableEventData->ActiveCablePowerRequirement);
8055 }
8056 break;
8057
8058 default:
8059 return 1;
8060 }
8061
8062 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
8063 fw_event = alloc_fw_event_work(sz);
8064 if (!fw_event) {
8065 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8066 ioc->name, __FILE__, __LINE__, __func__);
8067 return 1;
8068 }
8069
8070 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
8071 fw_event->ioc = ioc;
8072 fw_event->VF_ID = mpi_reply->VF_ID;
8073 fw_event->VP_ID = mpi_reply->VP_ID;
8074 fw_event->event = event;
8075 _scsih_fw_event_add(ioc, fw_event);
8076 fw_event_work_put(fw_event);
8077 return 1;
8078}
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091static void
8092_scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
8093 struct _sas_node *sas_expander)
8094{
8095 struct _sas_port *mpt3sas_port, *next;
8096
8097
8098 list_for_each_entry_safe(mpt3sas_port, next,
8099 &sas_expander->sas_port_list, port_list) {
8100 if (ioc->shost_recovery)
8101 return;
8102 if (mpt3sas_port->remote_identify.device_type ==
8103 SAS_END_DEVICE)
8104 mpt3sas_device_remove_by_sas_address(ioc,
8105 mpt3sas_port->remote_identify.sas_address);
8106 else if (mpt3sas_port->remote_identify.device_type ==
8107 SAS_EDGE_EXPANDER_DEVICE ||
8108 mpt3sas_port->remote_identify.device_type ==
8109 SAS_FANOUT_EXPANDER_DEVICE)
8110 mpt3sas_expander_remove(ioc,
8111 mpt3sas_port->remote_identify.sas_address);
8112 }
8113
8114 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
8115 sas_expander->sas_address_parent);
8116
8117 pr_info(MPT3SAS_FMT
8118 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8119 ioc->name,
8120 sas_expander->handle, (unsigned long long)
8121 sas_expander->sas_address);
8122
8123 kfree(sas_expander->phy);
8124 kfree(sas_expander);
8125}
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136static void
8137_scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
8138{
8139 Mpi2RaidActionRequest_t *mpi_request;
8140 Mpi2RaidActionReply_t *mpi_reply;
8141 u16 smid;
8142
8143
8144 if (!ioc->ir_firmware)
8145 return;
8146
8147
8148 if (list_empty(&ioc->raid_device_list))
8149 return;
8150
8151 mutex_lock(&ioc->scsih_cmds.mutex);
8152
8153 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
8154 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
8155 ioc->name, __func__);
8156 goto out;
8157 }
8158 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
8159
8160 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
8161 if (!smid) {
8162 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
8163 ioc->name, __func__);
8164 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8165 goto out;
8166 }
8167
8168 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
8169 ioc->scsih_cmds.smid = smid;
8170 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
8171
8172 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
8173 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
8174
8175 if (!ioc->hide_ir_msg)
8176 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
8177 init_completion(&ioc->scsih_cmds.done);
8178 ioc->put_smid_default(ioc, smid);
8179 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
8180
8181 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
8182 pr_err(MPT3SAS_FMT "%s: timeout\n",
8183 ioc->name, __func__);
8184 goto out;
8185 }
8186
8187 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
8188 mpi_reply = ioc->scsih_cmds.reply;
8189 if (!ioc->hide_ir_msg)
8190 pr_info(MPT3SAS_FMT "IR shutdown "
8191 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8192 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
8193 le32_to_cpu(mpi_reply->IOCLogInfo));
8194 }
8195
8196 out:
8197 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8198 mutex_unlock(&ioc->scsih_cmds.mutex);
8199}
8200
8201
8202
8203
8204
8205
8206
8207
8208static void scsih_remove(struct pci_dev *pdev)
8209{
8210 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8211 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8212 struct _sas_port *mpt3sas_port, *next_port;
8213 struct _raid_device *raid_device, *next;
8214 struct MPT3SAS_TARGET *sas_target_priv_data;
8215 struct workqueue_struct *wq;
8216 unsigned long flags;
8217
8218 ioc->remove_host = 1;
8219 _scsih_fw_event_cleanup_queue(ioc);
8220
8221 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8222 wq = ioc->firmware_event_thread;
8223 ioc->firmware_event_thread = NULL;
8224 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8225 if (wq)
8226 destroy_workqueue(wq);
8227
8228
8229 _scsih_ir_shutdown(ioc);
8230 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8231 list) {
8232 if (raid_device->starget) {
8233 sas_target_priv_data =
8234 raid_device->starget->hostdata;
8235 sas_target_priv_data->deleted = 1;
8236 scsi_remove_target(&raid_device->starget->dev);
8237 }
8238 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
8239 ioc->name, raid_device->handle,
8240 (unsigned long long) raid_device->wwid);
8241 _scsih_raid_device_remove(ioc, raid_device);
8242 }
8243
8244
8245 list_for_each_entry_safe(mpt3sas_port, next_port,
8246 &ioc->sas_hba.sas_port_list, port_list) {
8247 if (mpt3sas_port->remote_identify.device_type ==
8248 SAS_END_DEVICE)
8249 mpt3sas_device_remove_by_sas_address(ioc,
8250 mpt3sas_port->remote_identify.sas_address);
8251 else if (mpt3sas_port->remote_identify.device_type ==
8252 SAS_EDGE_EXPANDER_DEVICE ||
8253 mpt3sas_port->remote_identify.device_type ==
8254 SAS_FANOUT_EXPANDER_DEVICE)
8255 mpt3sas_expander_remove(ioc,
8256 mpt3sas_port->remote_identify.sas_address);
8257 }
8258
8259
8260 if (ioc->sas_hba.num_phys) {
8261 kfree(ioc->sas_hba.phy);
8262 ioc->sas_hba.phy = NULL;
8263 ioc->sas_hba.num_phys = 0;
8264 }
8265
8266 sas_remove_host(shost);
8267 scsi_remove_host(shost);
8268 mpt3sas_base_detach(ioc);
8269 spin_lock(&gioc_lock);
8270 list_del(&ioc->list);
8271 spin_unlock(&gioc_lock);
8272 scsi_host_put(shost);
8273}
8274
8275
8276
8277
8278
8279
8280
8281static void
8282scsih_shutdown(struct pci_dev *pdev)
8283{
8284 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8285 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8286 struct workqueue_struct *wq;
8287 unsigned long flags;
8288
8289 ioc->remove_host = 1;
8290 _scsih_fw_event_cleanup_queue(ioc);
8291
8292 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8293 wq = ioc->firmware_event_thread;
8294 ioc->firmware_event_thread = NULL;
8295 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8296 if (wq)
8297 destroy_workqueue(wq);
8298
8299 _scsih_ir_shutdown(ioc);
8300 mpt3sas_base_detach(ioc);
8301}
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312static void
8313_scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8314{
8315 u8 is_raid;
8316 void *device;
8317 struct _sas_device *sas_device;
8318 struct _raid_device *raid_device;
8319 u16 handle;
8320 u64 sas_address_parent;
8321 u64 sas_address;
8322 unsigned long flags;
8323 int rc;
8324
8325
8326 if (!ioc->bios_pg3.BiosVersion)
8327 return;
8328
8329 device = NULL;
8330 is_raid = 0;
8331 if (ioc->req_boot_device.device) {
8332 device = ioc->req_boot_device.device;
8333 is_raid = ioc->req_boot_device.is_raid;
8334 } else if (ioc->req_alt_boot_device.device) {
8335 device = ioc->req_alt_boot_device.device;
8336 is_raid = ioc->req_alt_boot_device.is_raid;
8337 } else if (ioc->current_boot_device.device) {
8338 device = ioc->current_boot_device.device;
8339 is_raid = ioc->current_boot_device.is_raid;
8340 }
8341
8342 if (!device)
8343 return;
8344
8345 if (is_raid) {
8346 raid_device = device;
8347 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8348 raid_device->id, 0);
8349 if (rc)
8350 _scsih_raid_device_remove(ioc, raid_device);
8351 } else {
8352 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8353 sas_device = device;
8354 handle = sas_device->handle;
8355 sas_address_parent = sas_device->sas_address_parent;
8356 sas_address = sas_device->sas_address;
8357 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8358 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8359
8360 if (ioc->hide_drives)
8361 return;
8362 if (!mpt3sas_transport_port_add(ioc, handle,
8363 sas_address_parent)) {
8364 _scsih_sas_device_remove(ioc, sas_device);
8365 } else if (!sas_device->starget) {
8366 if (!ioc->is_driver_loading) {
8367 mpt3sas_transport_port_remove(ioc,
8368 sas_address,
8369 sas_address_parent);
8370 _scsih_sas_device_remove(ioc, sas_device);
8371 }
8372 }
8373 }
8374}
8375
8376
8377
8378
8379
8380
8381
8382static void
8383_scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8384{
8385 struct _raid_device *raid_device, *raid_next;
8386 int rc;
8387
8388 list_for_each_entry_safe(raid_device, raid_next,
8389 &ioc->raid_device_list, list) {
8390 if (raid_device->starget)
8391 continue;
8392 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8393 raid_device->id, 0);
8394 if (rc)
8395 _scsih_raid_device_remove(ioc, raid_device);
8396 }
8397}
8398
8399static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8400{
8401 struct _sas_device *sas_device = NULL;
8402 unsigned long flags;
8403
8404 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8405 if (!list_empty(&ioc->sas_device_init_list)) {
8406 sas_device = list_first_entry(&ioc->sas_device_init_list,
8407 struct _sas_device, list);
8408 sas_device_get(sas_device);
8409 }
8410 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8411
8412 return sas_device;
8413}
8414
8415static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8416 struct _sas_device *sas_device)
8417{
8418 unsigned long flags;
8419
8420 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430 if (!list_empty(&sas_device->list)) {
8431 list_del_init(&sas_device->list);
8432 sas_device_put(sas_device);
8433 }
8434
8435 sas_device_get(sas_device);
8436 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8437
8438 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8439}
8440
8441
8442
8443
8444
8445
8446
8447static void
8448_scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8449{
8450 struct _sas_device *sas_device;
8451
8452 if (ioc->hide_drives)
8453 return;
8454
8455 while ((sas_device = get_next_sas_device(ioc))) {
8456 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8457 sas_device->sas_address_parent)) {
8458 _scsih_sas_device_remove(ioc, sas_device);
8459 sas_device_put(sas_device);
8460 continue;
8461 } else if (!sas_device->starget) {
8462
8463
8464
8465
8466
8467
8468 if (!ioc->is_driver_loading) {
8469 mpt3sas_transport_port_remove(ioc,
8470 sas_device->sas_address,
8471 sas_device->sas_address_parent);
8472 _scsih_sas_device_remove(ioc, sas_device);
8473 sas_device_put(sas_device);
8474 continue;
8475 }
8476 }
8477 sas_device_make_active(ioc, sas_device);
8478 sas_device_put(sas_device);
8479 }
8480}
8481
8482
8483
8484
8485
8486
8487
8488static void
8489_scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8490{
8491 u16 volume_mapping_flags;
8492
8493 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8494 return;
8495
8496 _scsih_probe_boot_devices(ioc);
8497
8498 if (ioc->ir_firmware) {
8499 volume_mapping_flags =
8500 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8501 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8502 if (volume_mapping_flags ==
8503 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8504 _scsih_probe_raid(ioc);
8505 _scsih_probe_sas(ioc);
8506 } else {
8507 _scsih_probe_sas(ioc);
8508 _scsih_probe_raid(ioc);
8509 }
8510 } else
8511 _scsih_probe_sas(ioc);
8512}
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522static void
8523scsih_scan_start(struct Scsi_Host *shost)
8524{
8525 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8526 int rc;
8527 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8528 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8529
8530 if (disable_discovery > 0)
8531 return;
8532
8533 ioc->start_scan = 1;
8534 rc = mpt3sas_port_enable(ioc);
8535
8536 if (rc != 0)
8537 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8538}
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549static int
8550scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8551{
8552 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8553
8554 if (disable_discovery > 0) {
8555 ioc->is_driver_loading = 0;
8556 ioc->wait_for_discovery_to_complete = 0;
8557 return 1;
8558 }
8559
8560 if (time >= (300 * HZ)) {
8561 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8562 pr_info(MPT3SAS_FMT
8563 "port enable: FAILED with timeout (timeout=300s)\n",
8564 ioc->name);
8565 ioc->is_driver_loading = 0;
8566 return 1;
8567 }
8568
8569 if (ioc->start_scan)
8570 return 0;
8571
8572 if (ioc->start_scan_failed) {
8573 pr_info(MPT3SAS_FMT
8574 "port enable: FAILED with (ioc_status=0x%08x)\n",
8575 ioc->name, ioc->start_scan_failed);
8576 ioc->is_driver_loading = 0;
8577 ioc->wait_for_discovery_to_complete = 0;
8578 ioc->remove_host = 1;
8579 return 1;
8580 }
8581
8582 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8583 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8584
8585 if (ioc->wait_for_discovery_to_complete) {
8586 ioc->wait_for_discovery_to_complete = 0;
8587 _scsih_probe_devices(ioc);
8588 }
8589 mpt3sas_base_start_watchdog(ioc);
8590 ioc->is_driver_loading = 0;
8591 return 1;
8592}
8593
8594
8595static struct scsi_host_template mpt2sas_driver_template = {
8596 .module = THIS_MODULE,
8597 .name = "Fusion MPT SAS Host",
8598 .proc_name = MPT2SAS_DRIVER_NAME,
8599 .queuecommand = scsih_qcmd,
8600 .target_alloc = scsih_target_alloc,
8601 .slave_alloc = scsih_slave_alloc,
8602 .slave_configure = scsih_slave_configure,
8603 .target_destroy = scsih_target_destroy,
8604 .slave_destroy = scsih_slave_destroy,
8605 .scan_finished = scsih_scan_finished,
8606 .scan_start = scsih_scan_start,
8607 .change_queue_depth = scsih_change_queue_depth,
8608 .eh_abort_handler = scsih_abort,
8609 .eh_device_reset_handler = scsih_dev_reset,
8610 .eh_target_reset_handler = scsih_target_reset,
8611 .eh_host_reset_handler = scsih_host_reset,
8612 .bios_param = scsih_bios_param,
8613 .can_queue = 1,
8614 .this_id = -1,
8615 .sg_tablesize = MPT2SAS_SG_DEPTH,
8616 .max_sectors = 32767,
8617 .cmd_per_lun = 7,
8618 .use_clustering = ENABLE_CLUSTERING,
8619 .shost_attrs = mpt3sas_host_attrs,
8620 .sdev_attrs = mpt3sas_dev_attrs,
8621 .track_queue_depth = 1,
8622};
8623
8624
8625static struct raid_function_template mpt2sas_raid_functions = {
8626 .cookie = &mpt2sas_driver_template,
8627 .is_raid = scsih_is_raid,
8628 .get_resync = scsih_get_resync,
8629 .get_state = scsih_get_state,
8630};
8631
8632
8633static struct scsi_host_template mpt3sas_driver_template = {
8634 .module = THIS_MODULE,
8635 .name = "Fusion MPT SAS Host",
8636 .proc_name = MPT3SAS_DRIVER_NAME,
8637 .queuecommand = scsih_qcmd,
8638 .target_alloc = scsih_target_alloc,
8639 .slave_alloc = scsih_slave_alloc,
8640 .slave_configure = scsih_slave_configure,
8641 .target_destroy = scsih_target_destroy,
8642 .slave_destroy = scsih_slave_destroy,
8643 .scan_finished = scsih_scan_finished,
8644 .scan_start = scsih_scan_start,
8645 .change_queue_depth = scsih_change_queue_depth,
8646 .eh_abort_handler = scsih_abort,
8647 .eh_device_reset_handler = scsih_dev_reset,
8648 .eh_target_reset_handler = scsih_target_reset,
8649 .eh_host_reset_handler = scsih_host_reset,
8650 .bios_param = scsih_bios_param,
8651 .can_queue = 1,
8652 .this_id = -1,
8653 .sg_tablesize = MPT3SAS_SG_DEPTH,
8654 .max_sectors = 32767,
8655 .cmd_per_lun = 7,
8656 .use_clustering = ENABLE_CLUSTERING,
8657 .shost_attrs = mpt3sas_host_attrs,
8658 .sdev_attrs = mpt3sas_dev_attrs,
8659 .track_queue_depth = 1,
8660};
8661
8662
8663static struct raid_function_template mpt3sas_raid_functions = {
8664 .cookie = &mpt3sas_driver_template,
8665 .is_raid = scsih_is_raid,
8666 .get_resync = scsih_get_resync,
8667 .get_state = scsih_get_state,
8668};
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679static u16
8680_scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8681{
8682
8683 switch (pdev->device) {
8684 case MPI2_MFGPAGE_DEVID_SSS6200:
8685 case MPI2_MFGPAGE_DEVID_SAS2004:
8686 case MPI2_MFGPAGE_DEVID_SAS2008:
8687 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8688 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8689 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8690 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8691 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8692 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8693 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8694 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8695 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8696 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8697 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8698 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8699 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8700 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8701 return MPI2_VERSION;
8702 case MPI25_MFGPAGE_DEVID_SAS3004:
8703 case MPI25_MFGPAGE_DEVID_SAS3008:
8704 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8705 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8706 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8707 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8708 return MPI25_VERSION;
8709 case MPI26_MFGPAGE_DEVID_SAS3216:
8710 case MPI26_MFGPAGE_DEVID_SAS3224:
8711 case MPI26_MFGPAGE_DEVID_SAS3316_1:
8712 case MPI26_MFGPAGE_DEVID_SAS3316_2:
8713 case MPI26_MFGPAGE_DEVID_SAS3316_3:
8714 case MPI26_MFGPAGE_DEVID_SAS3316_4:
8715 case MPI26_MFGPAGE_DEVID_SAS3324_1:
8716 case MPI26_MFGPAGE_DEVID_SAS3324_2:
8717 case MPI26_MFGPAGE_DEVID_SAS3324_3:
8718 case MPI26_MFGPAGE_DEVID_SAS3324_4:
8719 case MPI26_MFGPAGE_DEVID_SAS3508:
8720 case MPI26_MFGPAGE_DEVID_SAS3508_1:
8721 case MPI26_MFGPAGE_DEVID_SAS3408:
8722 case MPI26_MFGPAGE_DEVID_SAS3516:
8723 case MPI26_MFGPAGE_DEVID_SAS3516_1:
8724 case MPI26_MFGPAGE_DEVID_SAS3416:
8725 return MPI26_VERSION;
8726 }
8727 return 0;
8728}
8729
8730
8731
8732
8733
8734
8735
8736
8737static int
8738_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8739{
8740 struct MPT3SAS_ADAPTER *ioc;
8741 struct Scsi_Host *shost = NULL;
8742 int rv;
8743 u16 hba_mpi_version;
8744
8745
8746 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8747 if (hba_mpi_version == 0)
8748 return -ENODEV;
8749
8750
8751
8752
8753 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8754 return -ENODEV;
8755
8756
8757
8758
8759 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
8760 || hba_mpi_version == MPI26_VERSION)))
8761 return -ENODEV;
8762
8763 switch (hba_mpi_version) {
8764 case MPI2_VERSION:
8765 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
8766 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
8767
8768 shost = scsi_host_alloc(&mpt2sas_driver_template,
8769 sizeof(struct MPT3SAS_ADAPTER));
8770 if (!shost)
8771 return -ENODEV;
8772 ioc = shost_priv(shost);
8773 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8774 ioc->hba_mpi_version_belonged = hba_mpi_version;
8775 ioc->id = mpt2_ids++;
8776 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8777 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8778 ioc->is_warpdrive = 1;
8779 ioc->hide_ir_msg = 1;
8780 } else
8781 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8782 break;
8783 case MPI25_VERSION:
8784 case MPI26_VERSION:
8785
8786 shost = scsi_host_alloc(&mpt3sas_driver_template,
8787 sizeof(struct MPT3SAS_ADAPTER));
8788 if (!shost)
8789 return -ENODEV;
8790 ioc = shost_priv(shost);
8791 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8792 ioc->hba_mpi_version_belonged = hba_mpi_version;
8793 ioc->id = mpt3_ids++;
8794 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8795 switch (pdev->device) {
8796 case MPI26_MFGPAGE_DEVID_SAS3508:
8797 case MPI26_MFGPAGE_DEVID_SAS3508_1:
8798 case MPI26_MFGPAGE_DEVID_SAS3408:
8799 case MPI26_MFGPAGE_DEVID_SAS3516:
8800 case MPI26_MFGPAGE_DEVID_SAS3516_1:
8801 case MPI26_MFGPAGE_DEVID_SAS3416:
8802 ioc->is_gen35_ioc = 1;
8803 break;
8804 default:
8805 ioc->is_gen35_ioc = 0;
8806 }
8807 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
8808 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
8809 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
8810 ioc->combined_reply_queue = 1;
8811 if (ioc->is_gen35_ioc)
8812 ioc->combined_reply_index_count =
8813 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
8814 else
8815 ioc->combined_reply_index_count =
8816 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
8817 }
8818 break;
8819 default:
8820 return -ENODEV;
8821 }
8822
8823 INIT_LIST_HEAD(&ioc->list);
8824 spin_lock(&gioc_lock);
8825 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8826 spin_unlock(&gioc_lock);
8827 ioc->shost = shost;
8828 ioc->pdev = pdev;
8829 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8830 ioc->tm_cb_idx = tm_cb_idx;
8831 ioc->ctl_cb_idx = ctl_cb_idx;
8832 ioc->base_cb_idx = base_cb_idx;
8833 ioc->port_enable_cb_idx = port_enable_cb_idx;
8834 ioc->transport_cb_idx = transport_cb_idx;
8835 ioc->scsih_cb_idx = scsih_cb_idx;
8836 ioc->config_cb_idx = config_cb_idx;
8837 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8838 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8839 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8840 ioc->logging_level = logging_level;
8841 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8842
8843 mutex_init(&ioc->reset_in_progress_mutex);
8844
8845 mutex_init(&ioc->pci_access_mutex);
8846 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8847 spin_lock_init(&ioc->scsi_lookup_lock);
8848 spin_lock_init(&ioc->sas_device_lock);
8849 spin_lock_init(&ioc->sas_node_lock);
8850 spin_lock_init(&ioc->fw_event_lock);
8851 spin_lock_init(&ioc->raid_device_lock);
8852 spin_lock_init(&ioc->diag_trigger_lock);
8853
8854 INIT_LIST_HEAD(&ioc->sas_device_list);
8855 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8856 INIT_LIST_HEAD(&ioc->sas_expander_list);
8857 INIT_LIST_HEAD(&ioc->fw_event_list);
8858 INIT_LIST_HEAD(&ioc->raid_device_list);
8859 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8860 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8861 INIT_LIST_HEAD(&ioc->delayed_sc_list);
8862 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
8863 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8864 INIT_LIST_HEAD(&ioc->reply_queue_list);
8865
8866 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8867
8868
8869 shost->max_cmd_len = 32;
8870 shost->max_lun = max_lun;
8871 shost->transportt = mpt3sas_transport_template;
8872 shost->unique_id = ioc->id;
8873
8874 if (max_sectors != 0xFFFF) {
8875 if (max_sectors < 64) {
8876 shost->max_sectors = 64;
8877 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8878 "for max_sectors, range is 64 to 32767. Assigning "
8879 "value of 64.\n", ioc->name, max_sectors);
8880 } else if (max_sectors > 32767) {
8881 shost->max_sectors = 32767;
8882 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8883 "for max_sectors, range is 64 to 32767. Assigning "
8884 "default value of 32767.\n", ioc->name,
8885 max_sectors);
8886 } else {
8887 shost->max_sectors = max_sectors & 0xFFFE;
8888 pr_info(MPT3SAS_FMT
8889 "The max_sectors value is set to %d\n",
8890 ioc->name, shost->max_sectors);
8891 }
8892 }
8893
8894
8895 if (prot_mask > 0)
8896 scsi_host_set_prot(shost, prot_mask);
8897 else
8898 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8899 | SHOST_DIF_TYPE2_PROTECTION
8900 | SHOST_DIF_TYPE3_PROTECTION);
8901
8902 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8903
8904
8905 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8906 "fw_event_%s%d", ioc->driver_name, ioc->id);
8907 ioc->firmware_event_thread = alloc_ordered_workqueue(
8908 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8909 if (!ioc->firmware_event_thread) {
8910 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8911 ioc->name, __FILE__, __LINE__, __func__);
8912 rv = -ENODEV;
8913 goto out_thread_fail;
8914 }
8915
8916 ioc->is_driver_loading = 1;
8917 if ((mpt3sas_base_attach(ioc))) {
8918 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8919 ioc->name, __FILE__, __LINE__, __func__);
8920 rv = -ENODEV;
8921 goto out_attach_fail;
8922 }
8923
8924 if (ioc->is_warpdrive) {
8925 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8926 ioc->hide_drives = 0;
8927 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8928 ioc->hide_drives = 1;
8929 else {
8930 if (mpt3sas_get_num_volumes(ioc))
8931 ioc->hide_drives = 1;
8932 else
8933 ioc->hide_drives = 0;
8934 }
8935 } else
8936 ioc->hide_drives = 0;
8937
8938 rv = scsi_add_host(shost, &pdev->dev);
8939 if (rv) {
8940 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8941 ioc->name, __FILE__, __LINE__, __func__);
8942 goto out_add_shost_fail;
8943 }
8944
8945 scsi_scan_host(shost);
8946 return 0;
8947out_add_shost_fail:
8948 mpt3sas_base_detach(ioc);
8949 out_attach_fail:
8950 destroy_workqueue(ioc->firmware_event_thread);
8951 out_thread_fail:
8952 spin_lock(&gioc_lock);
8953 list_del(&ioc->list);
8954 spin_unlock(&gioc_lock);
8955 scsi_host_put(shost);
8956 return rv;
8957}
8958
8959#ifdef CONFIG_PM
8960
8961
8962
8963
8964
8965
8966
8967static int
8968scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8969{
8970 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8971 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8972 pci_power_t device_state;
8973
8974 mpt3sas_base_stop_watchdog(ioc);
8975 flush_scheduled_work();
8976 scsi_block_requests(shost);
8977 device_state = pci_choose_state(pdev, state);
8978 pr_info(MPT3SAS_FMT
8979 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8980 ioc->name, pdev, pci_name(pdev), device_state);
8981
8982 pci_save_state(pdev);
8983 mpt3sas_base_free_resources(ioc);
8984 pci_set_power_state(pdev, device_state);
8985 return 0;
8986}
8987
8988
8989
8990
8991
8992
8993
8994static int
8995scsih_resume(struct pci_dev *pdev)
8996{
8997 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8998 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8999 pci_power_t device_state = pdev->current_state;
9000 int r;
9001
9002 pr_info(MPT3SAS_FMT
9003 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
9004 ioc->name, pdev, pci_name(pdev), device_state);
9005
9006 pci_set_power_state(pdev, PCI_D0);
9007 pci_enable_wake(pdev, PCI_D0, 0);
9008 pci_restore_state(pdev);
9009 ioc->pdev = pdev;
9010 r = mpt3sas_base_map_resources(ioc);
9011 if (r)
9012 return r;
9013
9014 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
9015 scsi_unblock_requests(shost);
9016 mpt3sas_base_start_watchdog(ioc);
9017 return 0;
9018}
9019#endif
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031static pci_ers_result_t
9032scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9033{
9034 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9035 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9036
9037 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
9038 ioc->name, state);
9039
9040 switch (state) {
9041 case pci_channel_io_normal:
9042 return PCI_ERS_RESULT_CAN_RECOVER;
9043 case pci_channel_io_frozen:
9044
9045 ioc->pci_error_recovery = 1;
9046 scsi_block_requests(ioc->shost);
9047 mpt3sas_base_stop_watchdog(ioc);
9048 mpt3sas_base_free_resources(ioc);
9049 return PCI_ERS_RESULT_NEED_RESET;
9050 case pci_channel_io_perm_failure:
9051
9052 ioc->pci_error_recovery = 1;
9053 mpt3sas_base_stop_watchdog(ioc);
9054 _scsih_flush_running_cmds(ioc);
9055 return PCI_ERS_RESULT_DISCONNECT;
9056 }
9057 return PCI_ERS_RESULT_NEED_RESET;
9058}
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068static pci_ers_result_t
9069scsih_pci_slot_reset(struct pci_dev *pdev)
9070{
9071 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9072 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9073 int rc;
9074
9075 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
9076 ioc->name);
9077
9078 ioc->pci_error_recovery = 0;
9079 ioc->pdev = pdev;
9080 pci_restore_state(pdev);
9081 rc = mpt3sas_base_map_resources(ioc);
9082 if (rc)
9083 return PCI_ERS_RESULT_DISCONNECT;
9084
9085 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
9086
9087 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
9088 (rc == 0) ? "success" : "failed");
9089
9090 if (!rc)
9091 return PCI_ERS_RESULT_RECOVERED;
9092 else
9093 return PCI_ERS_RESULT_DISCONNECT;
9094}
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104static void
9105scsih_pci_resume(struct pci_dev *pdev)
9106{
9107 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9108 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9109
9110 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
9111
9112 pci_cleanup_aer_uncorrect_error_status(pdev);
9113 mpt3sas_base_start_watchdog(ioc);
9114 scsi_unblock_requests(ioc->shost);
9115}
9116
9117
9118
9119
9120
9121static pci_ers_result_t
9122scsih_pci_mmio_enabled(struct pci_dev *pdev)
9123{
9124 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9125 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9126
9127 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
9128 ioc->name);
9129
9130
9131
9132
9133
9134
9135
9136 return PCI_ERS_RESULT_RECOVERED;
9137}
9138
9139
9140
9141
9142
9143
9144
9145
9146bool scsih_ncq_prio_supp(struct scsi_device *sdev)
9147{
9148 unsigned char *buf;
9149 bool ncq_prio_supp = false;
9150
9151 if (!scsi_device_supports_vpd(sdev))
9152 return ncq_prio_supp;
9153
9154 buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
9155 if (!buf)
9156 return ncq_prio_supp;
9157
9158 if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
9159 ncq_prio_supp = (buf[213] >> 4) & 1;
9160
9161 kfree(buf);
9162 return ncq_prio_supp;
9163}
9164
9165
9166
9167static const struct pci_device_id mpt3sas_pci_table[] = {
9168
9169 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
9170 PCI_ANY_ID, PCI_ANY_ID },
9171
9172 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
9173 PCI_ANY_ID, PCI_ANY_ID },
9174
9175 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
9176 PCI_ANY_ID, PCI_ANY_ID },
9177 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
9178 PCI_ANY_ID, PCI_ANY_ID },
9179 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
9180 PCI_ANY_ID, PCI_ANY_ID },
9181
9182 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
9183 PCI_ANY_ID, PCI_ANY_ID },
9184 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
9185 PCI_ANY_ID, PCI_ANY_ID },
9186
9187 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
9188 PCI_ANY_ID, PCI_ANY_ID },
9189 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
9190 PCI_ANY_ID, PCI_ANY_ID },
9191 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
9192 PCI_ANY_ID, PCI_ANY_ID },
9193 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
9194 PCI_ANY_ID, PCI_ANY_ID },
9195 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
9196 PCI_ANY_ID, PCI_ANY_ID },
9197 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
9198 PCI_ANY_ID, PCI_ANY_ID },
9199
9200 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
9201 PCI_ANY_ID, PCI_ANY_ID },
9202 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
9203 PCI_ANY_ID, PCI_ANY_ID },
9204 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
9205 PCI_ANY_ID, PCI_ANY_ID },
9206
9207 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
9208 PCI_ANY_ID, PCI_ANY_ID },
9209
9210 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
9211 PCI_ANY_ID, PCI_ANY_ID },
9212 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
9213 PCI_ANY_ID, PCI_ANY_ID },
9214
9215 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
9216 PCI_ANY_ID, PCI_ANY_ID },
9217 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
9218 PCI_ANY_ID, PCI_ANY_ID },
9219 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
9220 PCI_ANY_ID, PCI_ANY_ID },
9221 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
9222 PCI_ANY_ID, PCI_ANY_ID },
9223
9224 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
9225 PCI_ANY_ID, PCI_ANY_ID },
9226 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
9227 PCI_ANY_ID, PCI_ANY_ID },
9228
9229 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
9230 PCI_ANY_ID, PCI_ANY_ID },
9231 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
9232 PCI_ANY_ID, PCI_ANY_ID },
9233 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
9234 PCI_ANY_ID, PCI_ANY_ID },
9235 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
9236 PCI_ANY_ID, PCI_ANY_ID },
9237 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
9238 PCI_ANY_ID, PCI_ANY_ID },
9239 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
9240 PCI_ANY_ID, PCI_ANY_ID },
9241 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
9242 PCI_ANY_ID, PCI_ANY_ID },
9243 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
9244 PCI_ANY_ID, PCI_ANY_ID },
9245
9246 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
9247 PCI_ANY_ID, PCI_ANY_ID },
9248 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
9249 PCI_ANY_ID, PCI_ANY_ID },
9250 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
9251 PCI_ANY_ID, PCI_ANY_ID },
9252 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
9253 PCI_ANY_ID, PCI_ANY_ID },
9254 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
9255 PCI_ANY_ID, PCI_ANY_ID },
9256 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
9257 PCI_ANY_ID, PCI_ANY_ID },
9258 {0}
9259};
9260MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
9261
9262static struct pci_error_handlers _mpt3sas_err_handler = {
9263 .error_detected = scsih_pci_error_detected,
9264 .mmio_enabled = scsih_pci_mmio_enabled,
9265 .slot_reset = scsih_pci_slot_reset,
9266 .resume = scsih_pci_resume,
9267};
9268
9269static struct pci_driver mpt3sas_driver = {
9270 .name = MPT3SAS_DRIVER_NAME,
9271 .id_table = mpt3sas_pci_table,
9272 .probe = _scsih_probe,
9273 .remove = scsih_remove,
9274 .shutdown = scsih_shutdown,
9275 .err_handler = &_mpt3sas_err_handler,
9276#ifdef CONFIG_PM
9277 .suspend = scsih_suspend,
9278 .resume = scsih_resume,
9279#endif
9280};
9281
9282
9283
9284
9285
9286
9287static int
9288scsih_init(void)
9289{
9290 mpt2_ids = 0;
9291 mpt3_ids = 0;
9292
9293 mpt3sas_base_initialize_callback_handler();
9294
9295
9296 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
9297
9298
9299 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
9300
9301
9302 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
9303 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
9304 mpt3sas_port_enable_done);
9305
9306
9307 transport_cb_idx = mpt3sas_base_register_callback_handler(
9308 mpt3sas_transport_done);
9309
9310
9311 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
9312
9313
9314 config_cb_idx = mpt3sas_base_register_callback_handler(
9315 mpt3sas_config_done);
9316
9317
9318 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
9319
9320 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
9321 _scsih_tm_tr_complete);
9322
9323 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
9324 _scsih_tm_volume_tr_complete);
9325
9326 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
9327 _scsih_sas_control_complete);
9328
9329 return 0;
9330}
9331
9332
9333
9334
9335
9336
9337static void
9338scsih_exit(void)
9339{
9340
9341 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
9342 mpt3sas_base_release_callback_handler(tm_cb_idx);
9343 mpt3sas_base_release_callback_handler(base_cb_idx);
9344 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
9345 mpt3sas_base_release_callback_handler(transport_cb_idx);
9346 mpt3sas_base_release_callback_handler(scsih_cb_idx);
9347 mpt3sas_base_release_callback_handler(config_cb_idx);
9348 mpt3sas_base_release_callback_handler(ctl_cb_idx);
9349
9350 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
9351 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
9352 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
9353
9354
9355 if (hbas_to_enumerate != 1)
9356 raid_class_release(mpt3sas_raid_template);
9357 if (hbas_to_enumerate != 2)
9358 raid_class_release(mpt2sas_raid_template);
9359 sas_release_transport(mpt3sas_transport_template);
9360}
9361
9362
9363
9364
9365
9366
9367static int __init
9368_mpt3sas_init(void)
9369{
9370 int error;
9371
9372 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9373 MPT3SAS_DRIVER_VERSION);
9374
9375 mpt3sas_transport_template =
9376 sas_attach_transport(&mpt3sas_transport_functions);
9377 if (!mpt3sas_transport_template)
9378 return -ENODEV;
9379
9380
9381
9382
9383 if (hbas_to_enumerate != 1) {
9384 mpt3sas_raid_template =
9385 raid_class_attach(&mpt3sas_raid_functions);
9386 if (!mpt3sas_raid_template) {
9387 sas_release_transport(mpt3sas_transport_template);
9388 return -ENODEV;
9389 }
9390 }
9391
9392
9393
9394
9395 if (hbas_to_enumerate != 2) {
9396 mpt2sas_raid_template =
9397 raid_class_attach(&mpt2sas_raid_functions);
9398 if (!mpt2sas_raid_template) {
9399 sas_release_transport(mpt3sas_transport_template);
9400 return -ENODEV;
9401 }
9402 }
9403
9404 error = scsih_init();
9405 if (error) {
9406 scsih_exit();
9407 return error;
9408 }
9409
9410 mpt3sas_ctl_init(hbas_to_enumerate);
9411
9412 error = pci_register_driver(&mpt3sas_driver);
9413 if (error)
9414 scsih_exit();
9415
9416 return error;
9417}
9418
9419
9420
9421
9422
9423static void __exit
9424_mpt3sas_exit(void)
9425{
9426 pr_info("mpt3sas version %s unloading\n",
9427 MPT3SAS_DRIVER_VERSION);
9428
9429 pci_unregister_driver(&mpt3sas_driver);
9430
9431 mpt3sas_ctl_exit(hbas_to_enumerate);
9432
9433 scsih_exit();
9434}
9435
9436module_init(_mpt3sas_init);
9437module_exit(_mpt3sas_exit);
9438