Lines Matching full:a

15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
38 * You should have received a copy of the GNU General Public License
46 static bool esas2r_initmem_alloc(struct esas2r_adapter *a, in esas2r_initmem_alloc() argument
53 mem_desc->esas2r_data = dma_alloc_coherent(&a->pcid->dev, in esas2r_initmem_alloc()
75 static void esas2r_initmem_free(struct esas2r_adapter *a, in esas2r_initmem_free() argument
92 dma_free_coherent(&a->pcid->dev, in esas2r_initmem_free()
103 static bool alloc_vda_req(struct esas2r_adapter *a, in alloc_vda_req() argument
117 if (!esas2r_initmem_alloc(a, memdesc, 256)) { in alloc_vda_req()
123 a->num_vrqs++; in alloc_vda_req()
124 list_add(&memdesc->next_desc, &a->vrq_mds_head); in alloc_vda_req()
128 rq->vrq->scsi.handle = a->num_vrqs; in alloc_vda_req()
133 static void esas2r_unmap_regions(struct esas2r_adapter *a) in esas2r_unmap_regions() argument
135 if (a->regs) in esas2r_unmap_regions()
136 iounmap((void __iomem *)a->regs); in esas2r_unmap_regions()
138 a->regs = NULL; in esas2r_unmap_regions()
140 pci_release_region(a->pcid, 2); in esas2r_unmap_regions()
142 if (a->data_window) in esas2r_unmap_regions()
143 iounmap((void __iomem *)a->data_window); in esas2r_unmap_regions()
145 a->data_window = NULL; in esas2r_unmap_regions()
147 pci_release_region(a->pcid, 0); in esas2r_unmap_regions()
150 static int esas2r_map_regions(struct esas2r_adapter *a) in esas2r_map_regions() argument
154 a->regs = NULL; in esas2r_map_regions()
155 a->data_window = NULL; in esas2r_map_regions()
157 error = pci_request_region(a->pcid, 2, a->name); in esas2r_map_regions()
166 a->regs = (void __force *)ioremap(pci_resource_start(a->pcid, 2), in esas2r_map_regions()
167 pci_resource_len(a->pcid, 2)); in esas2r_map_regions()
168 if (a->regs == NULL) { in esas2r_map_regions()
171 pci_release_region(a->pcid, 2); in esas2r_map_regions()
175 error = pci_request_region(a->pcid, 0, a->name); in esas2r_map_regions()
180 esas2r_unmap_regions(a); in esas2r_map_regions()
184 a->data_window = (void __force *)ioremap(pci_resource_start(a->pcid, in esas2r_map_regions()
186 pci_resource_len(a->pcid, 0)); in esas2r_map_regions()
187 if (a->data_window == NULL) { in esas2r_map_regions()
190 esas2r_unmap_regions(a); in esas2r_map_regions()
197 static void esas2r_setup_interrupts(struct esas2r_adapter *a, int intr_mode) in esas2r_setup_interrupts() argument
205 a->intr_mode = INTR_MODE_LEGACY; in esas2r_setup_interrupts()
209 i = pci_enable_msi(a->pcid); in esas2r_setup_interrupts()
214 "(err=%d)", a->index, in esas2r_setup_interrupts()
218 a->intr_mode = INTR_MODE_MSI; in esas2r_setup_interrupts()
219 set_bit(AF2_MSI_ENABLED, &a->flags2); in esas2r_setup_interrupts()
232 static void esas2r_claim_interrupts(struct esas2r_adapter *a) in esas2r_claim_interrupts() argument
236 if (a->intr_mode == INTR_MODE_LEGACY) in esas2r_claim_interrupts()
241 a->pcid->irq, a, a->name, flags); in esas2r_claim_interrupts()
243 if (request_irq(a->pcid->irq, in esas2r_claim_interrupts()
244 (a->intr_mode == in esas2r_claim_interrupts()
248 a->name, in esas2r_claim_interrupts()
249 a)) { in esas2r_claim_interrupts()
251 a->pcid->irq); in esas2r_claim_interrupts()
255 set_bit(AF2_IRQ_CLAIMED, &a->flags2); in esas2r_claim_interrupts()
258 a->pcid->irq, flags); in esas2r_claim_interrupts()
264 struct esas2r_adapter *a; in esas2r_init_adapter() local
285 a = (struct esas2r_adapter *)host->hostdata; in esas2r_init_adapter()
286 memset(a, 0, sizeof(struct esas2r_adapter)); in esas2r_init_adapter()
287 a->pcid = pcid; in esas2r_init_adapter()
288 a->host = host; in esas2r_init_adapter()
304 esas2r_adapters[index] = a; in esas2r_init_adapter()
305 sprintf(a->name, ESAS2R_DRVR_NAME "_%02d", index); in esas2r_init_adapter()
306 esas2r_debug("new adapter %p, name %s", a, a->name); in esas2r_init_adapter()
307 spin_lock_init(&a->request_lock); in esas2r_init_adapter()
308 spin_lock_init(&a->fw_event_lock); in esas2r_init_adapter()
309 mutex_init(&a->fm_api_mutex); in esas2r_init_adapter()
310 mutex_init(&a->fs_api_mutex); in esas2r_init_adapter()
311 sema_init(&a->nvram_semaphore, 1); in esas2r_init_adapter()
313 esas2r_fw_event_off(a); in esas2r_init_adapter()
314 snprintf(a->fw_event_q_name, ESAS2R_KOBJ_NAME_LEN, "esas2r/%d", in esas2r_init_adapter()
315 a->index); in esas2r_init_adapter()
316 a->fw_event_q = create_singlethread_workqueue(a->fw_event_q_name); in esas2r_init_adapter()
318 init_waitqueue_head(&a->buffered_ioctl_waiter); in esas2r_init_adapter()
319 init_waitqueue_head(&a->nvram_waiter); in esas2r_init_adapter()
320 init_waitqueue_head(&a->fm_api_waiter); in esas2r_init_adapter()
321 init_waitqueue_head(&a->fs_api_waiter); in esas2r_init_adapter()
322 init_waitqueue_head(&a->vda_waiter); in esas2r_init_adapter()
324 INIT_LIST_HEAD(&a->general_req.req_list); in esas2r_init_adapter()
325 INIT_LIST_HEAD(&a->active_list); in esas2r_init_adapter()
326 INIT_LIST_HEAD(&a->defer_list); in esas2r_init_adapter()
327 INIT_LIST_HEAD(&a->free_sg_list_head); in esas2r_init_adapter()
328 INIT_LIST_HEAD(&a->avail_request); in esas2r_init_adapter()
329 INIT_LIST_HEAD(&a->vrq_mds_head); in esas2r_init_adapter()
330 INIT_LIST_HEAD(&a->fw_event_list); in esas2r_init_adapter()
332 first_request = (struct esas2r_request *)((u8 *)(a + 1)); in esas2r_init_adapter()
337 list_add_tail(&last_request->comp_list, &a->avail_request); in esas2r_init_adapter()
338 if (!alloc_vda_req(a, last_request)) { in esas2r_init_adapter()
340 "failed to allocate a VDA request!"); in esas2r_init_adapter()
351 if (esas2r_map_regions(a) != 0) { in esas2r_init_adapter()
357 a->index = index; in esas2r_init_adapter()
360 atomic_inc(&a->dis_ints_cnt); in esas2r_init_adapter()
361 atomic_inc(&a->disable_cnt); in esas2r_init_adapter()
362 set_bit(AF_CHPRST_PENDING, &a->flags); in esas2r_init_adapter()
363 set_bit(AF_DISC_PENDING, &a->flags); in esas2r_init_adapter()
364 set_bit(AF_FIRST_INIT, &a->flags); in esas2r_init_adapter()
365 set_bit(AF_LEGACY_SGE_MODE, &a->flags); in esas2r_init_adapter()
367 a->init_msg = ESAS2R_INIT_MSG_START; in esas2r_init_adapter()
368 a->max_vdareq_size = 128; in esas2r_init_adapter()
369 a->build_sgl = esas2r_build_sg_list_sge; in esas2r_init_adapter()
371 esas2r_setup_interrupts(a, interrupt_mode); in esas2r_init_adapter()
373 a->uncached_size = esas2r_get_uncached_size(a); in esas2r_init_adapter()
374 a->uncached = dma_alloc_coherent(&pcid->dev, in esas2r_init_adapter()
375 (size_t)a->uncached_size, in esas2r_init_adapter()
378 if (a->uncached == NULL) { in esas2r_init_adapter()
381 a->uncached_size); in esas2r_init_adapter()
386 a->uncached_phys = bus_addr; in esas2r_init_adapter()
389 a->uncached_size, in esas2r_init_adapter()
390 a->uncached, in esas2r_init_adapter()
393 memset(a->uncached, 0, a->uncached_size); in esas2r_init_adapter()
394 next_uncached = a->uncached; in esas2r_init_adapter()
396 if (!esas2r_init_adapter_struct(a, in esas2r_init_adapter()
404 tasklet_init(&a->tasklet, in esas2r_init_adapter()
406 (unsigned long)a); in esas2r_init_adapter()
412 esas2r_disable_chip_interrupts(a); in esas2r_init_adapter()
413 esas2r_check_adapter(a); in esas2r_init_adapter()
415 if (!esas2r_init_adapter_hw(a, true)) in esas2r_init_adapter()
420 esas2r_claim_interrupts(a); in esas2r_init_adapter()
422 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2)) in esas2r_init_adapter()
423 esas2r_enable_chip_interrupts(a); in esas2r_init_adapter()
425 set_bit(AF2_INIT_DONE, &a->flags2); in esas2r_init_adapter()
426 if (!test_bit(AF_DEGRADED_MODE, &a->flags)) in esas2r_init_adapter()
427 esas2r_kickoff_timer(a); in esas2r_init_adapter()
429 a, a->disable_cnt); in esas2r_init_adapter()
434 static void esas2r_adapter_power_down(struct esas2r_adapter *a, in esas2r_adapter_power_down() argument
439 if ((test_bit(AF2_INIT_DONE, &a->flags2)) in esas2r_adapter_power_down()
440 && (!test_bit(AF_DEGRADED_MODE, &a->flags))) { in esas2r_adapter_power_down()
442 del_timer_sync(&a->timer); in esas2r_adapter_power_down()
443 tasklet_kill(&a->tasklet); in esas2r_adapter_power_down()
445 esas2r_power_down(a); in esas2r_adapter_power_down()
457 if (a->sysfs_fw_created) { in esas2r_adapter_power_down()
458 sysfs_remove_bin_file(&a->host->shost_dev.kobj, &bin_attr_fw); in esas2r_adapter_power_down()
459 a->sysfs_fw_created = 0; in esas2r_adapter_power_down()
462 if (a->sysfs_fs_created) { in esas2r_adapter_power_down()
463 sysfs_remove_bin_file(&a->host->shost_dev.kobj, &bin_attr_fs); in esas2r_adapter_power_down()
464 a->sysfs_fs_created = 0; in esas2r_adapter_power_down()
467 if (a->sysfs_vda_created) { in esas2r_adapter_power_down()
468 sysfs_remove_bin_file(&a->host->shost_dev.kobj, &bin_attr_vda); in esas2r_adapter_power_down()
469 a->sysfs_vda_created = 0; in esas2r_adapter_power_down()
472 if (a->sysfs_hw_created) { in esas2r_adapter_power_down()
473 sysfs_remove_bin_file(&a->host->shost_dev.kobj, &bin_attr_hw); in esas2r_adapter_power_down()
474 a->sysfs_hw_created = 0; in esas2r_adapter_power_down()
477 if (a->sysfs_live_nvram_created) { in esas2r_adapter_power_down()
478 sysfs_remove_bin_file(&a->host->shost_dev.kobj, in esas2r_adapter_power_down()
480 a->sysfs_live_nvram_created = 0; in esas2r_adapter_power_down()
483 if (a->sysfs_default_nvram_created) { in esas2r_adapter_power_down()
484 sysfs_remove_bin_file(&a->host->shost_dev.kobj, in esas2r_adapter_power_down()
486 a->sysfs_default_nvram_created = 0; in esas2r_adapter_power_down()
490 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2)) { in esas2r_adapter_power_down()
492 &(a->pcid->dev), in esas2r_adapter_power_down()
493 "free_irq(%d) called", a->pcid->irq); in esas2r_adapter_power_down()
495 free_irq(a->pcid->irq, a); in esas2r_adapter_power_down()
497 clear_bit(AF2_IRQ_CLAIMED, &a->flags2); in esas2r_adapter_power_down()
500 if (test_bit(AF2_MSI_ENABLED, &a->flags2)) { in esas2r_adapter_power_down()
501 pci_disable_msi(a->pcid); in esas2r_adapter_power_down()
502 clear_bit(AF2_MSI_ENABLED, &a->flags2); in esas2r_adapter_power_down()
506 if (a->inbound_list_md.virt_addr) in esas2r_adapter_power_down()
507 esas2r_initmem_free(a, &a->inbound_list_md); in esas2r_adapter_power_down()
509 if (a->outbound_list_md.virt_addr) in esas2r_adapter_power_down()
510 esas2r_initmem_free(a, &a->outbound_list_md); in esas2r_adapter_power_down()
512 list_for_each_entry_safe(memdesc, next, &a->free_sg_list_head, in esas2r_adapter_power_down()
514 esas2r_initmem_free(a, memdesc); in esas2r_adapter_power_down()
518 list_for_each_entry_safe(memdesc, next, &a->vrq_mds_head, next_desc) { in esas2r_adapter_power_down()
519 esas2r_initmem_free(a, memdesc); in esas2r_adapter_power_down()
524 kfree(a->first_ae_req); in esas2r_adapter_power_down()
525 a->first_ae_req = NULL; in esas2r_adapter_power_down()
527 kfree(a->sg_list_mds); in esas2r_adapter_power_down()
528 a->sg_list_mds = NULL; in esas2r_adapter_power_down()
530 kfree(a->req_table); in esas2r_adapter_power_down()
531 a->req_table = NULL; in esas2r_adapter_power_down()
533 if (a->regs) { in esas2r_adapter_power_down()
534 esas2r_unmap_regions(a); in esas2r_adapter_power_down()
535 a->regs = NULL; in esas2r_adapter_power_down()
536 a->data_window = NULL; in esas2r_adapter_power_down()
544 struct esas2r_adapter *a = esas2r_adapters[i]; in esas2r_kill_adapter() local
546 if (a) { in esas2r_kill_adapter()
549 esas2r_debug("killing adapter %p [%d] ", a, i); in esas2r_kill_adapter()
550 esas2r_fw_event_off(a); in esas2r_kill_adapter()
551 esas2r_adapter_power_down(a, 0); in esas2r_kill_adapter()
553 (a->pcid == esas2r_buffered_ioctl_pcid)) { in esas2r_kill_adapter()
554 dma_free_coherent(&a->pcid->dev, in esas2r_kill_adapter()
561 if (a->vda_buffer) { in esas2r_kill_adapter()
562 dma_free_coherent(&a->pcid->dev, in esas2r_kill_adapter()
564 a->vda_buffer, in esas2r_kill_adapter()
565 (dma_addr_t)a->ppvda_buffer); in esas2r_kill_adapter()
566 a->vda_buffer = NULL; in esas2r_kill_adapter()
568 if (a->fs_api_buffer) { in esas2r_kill_adapter()
569 dma_free_coherent(&a->pcid->dev, in esas2r_kill_adapter()
570 (size_t)a->fs_api_buffer_size, in esas2r_kill_adapter()
571 a->fs_api_buffer, in esas2r_kill_adapter()
572 (dma_addr_t)a->ppfs_api_buffer); in esas2r_kill_adapter()
573 a->fs_api_buffer = NULL; in esas2r_kill_adapter()
576 kfree(a->local_atto_ioctl); in esas2r_kill_adapter()
577 a->local_atto_ioctl = NULL; in esas2r_kill_adapter()
579 spin_lock_irqsave(&a->fw_event_lock, flags); in esas2r_kill_adapter()
580 wq = a->fw_event_q; in esas2r_kill_adapter()
581 a->fw_event_q = NULL; in esas2r_kill_adapter()
582 spin_unlock_irqrestore(&a->fw_event_lock, flags); in esas2r_kill_adapter()
586 if (a->uncached) { in esas2r_kill_adapter()
587 dma_free_coherent(&a->pcid->dev, in esas2r_kill_adapter()
588 (size_t)a->uncached_size, in esas2r_kill_adapter()
589 a->uncached, in esas2r_kill_adapter()
590 (dma_addr_t)a->uncached_phys); in esas2r_kill_adapter()
591 a->uncached = NULL; in esas2r_kill_adapter()
596 &(a->pcid->dev), in esas2r_kill_adapter()
599 a->pcid->msix_enabled, in esas2r_kill_adapter()
600 a->pcid->msi_enabled, in esas2r_kill_adapter()
601 a->pcid->irq, in esas2r_kill_adapter()
602 a->pcid->pin); in esas2r_kill_adapter()
605 &(a->pcid->dev), in esas2r_kill_adapter()
607 a->pcid->enable_cnt.counter); in esas2r_kill_adapter()
609 pci_disable_device(a->pcid); in esas2r_kill_adapter()
611 &(a->pcid->dev), in esas2r_kill_adapter()
613 a->pcid->enable_cnt.counter); in esas2r_kill_adapter()
616 &(a->pcid->dev), in esas2r_kill_adapter()
618 a->pcid); in esas2r_kill_adapter()
620 pci_set_drvdata(a->pcid, NULL); in esas2r_kill_adapter()
623 if (test_bit(AF2_INIT_DONE, &a->flags2)) { in esas2r_kill_adapter()
624 clear_bit(AF2_INIT_DONE, &a->flags2); in esas2r_kill_adapter()
626 set_bit(AF_DEGRADED_MODE, &a->flags); in esas2r_kill_adapter()
629 &(a->host->shost_gendev), in esas2r_kill_adapter()
632 scsi_remove_host(a->host); in esas2r_kill_adapter()
635 &(a->host->shost_gendev), in esas2r_kill_adapter()
638 scsi_host_put(a->host); in esas2r_kill_adapter()
647 struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata; in esas2r_suspend() local
650 if (!a) in esas2r_suspend()
653 esas2r_adapter_power_down(a, 1); in esas2r_suspend()
671 struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata; in esas2r_resume() local
691 if (!a) { in esas2r_resume()
696 if (esas2r_map_regions(a) != 0) { in esas2r_resume()
703 esas2r_setup_interrupts(a, a->intr_mode); in esas2r_resume()
709 esas2r_disable_chip_interrupts(a); in esas2r_resume()
710 if (!esas2r_power_up(a, true)) { in esas2r_resume()
716 esas2r_claim_interrupts(a); in esas2r_resume()
718 if (test_bit(AF2_IRQ_CLAIMED, &a->flags2)) { in esas2r_resume()
723 esas2r_enable_chip_interrupts(a); in esas2r_resume()
724 esas2r_kickoff_timer(a); in esas2r_resume()
738 bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str) in esas2r_set_degraded_mode() argument
740 set_bit(AF_DEGRADED_MODE, &a->flags); in esas2r_set_degraded_mode()
746 u32 esas2r_get_uncached_size(struct esas2r_adapter *a) in esas2r_get_uncached_size() argument
763 static void esas2r_init_pci_cfg_space(struct esas2r_adapter *a) in esas2r_init_pci_cfg_space() argument
765 if (pci_is_pcie(a->pcid)) { in esas2r_init_pci_cfg_space()
768 pcie_capability_read_word(a->pcid, PCI_EXP_DEVCTL, &devcontrol); in esas2r_init_pci_cfg_space()
777 pcie_capability_write_word(a->pcid, PCI_EXP_DEVCTL, in esas2r_init_pci_cfg_space()
787 bool esas2r_init_adapter_struct(struct esas2r_adapter *a, in esas2r_init_adapter_struct() argument
796 spin_lock_init(&a->sg_list_lock); in esas2r_init_adapter_struct()
797 spin_lock_init(&a->mem_lock); in esas2r_init_adapter_struct()
798 spin_lock_init(&a->queue_lock); in esas2r_init_adapter_struct()
800 a->targetdb_end = &a->targetdb[ESAS2R_MAX_TARGETS]; in esas2r_init_adapter_struct()
802 if (!alloc_vda_req(a, &a->general_req)) { in esas2r_init_adapter_struct()
804 "failed to allocate a VDA request for the general req!"); in esas2r_init_adapter_struct()
809 a->first_ae_req = in esas2r_init_adapter_struct()
813 if (a->first_ae_req == NULL) { in esas2r_init_adapter_struct()
820 a->sg_list_mds = kcalloc(num_sg_lists, sizeof(struct esas2r_mem_desc), in esas2r_init_adapter_struct()
823 if (a->sg_list_mds == NULL) { in esas2r_init_adapter_struct()
830 a->req_table = in esas2r_init_adapter_struct()
835 if (a->req_table == NULL) { in esas2r_init_adapter_struct()
842 esas2r_init_pci_cfg_space(a); in esas2r_init_adapter_struct()
845 * the thunder_stream boards all have a serial flash part that has a in esas2r_init_adapter_struct()
848 if ((a->pcid->subsystem_vendor == ATTO_VENDOR_ID) in esas2r_init_adapter_struct()
849 && (a->pcid->subsystem_device & ATTO_SSDID_TBT)) in esas2r_init_adapter_struct()
850 a->flags2 |= AF2_THUNDERBOLT; in esas2r_init_adapter_struct()
852 if (test_bit(AF2_THUNDERBOLT, &a->flags2)) in esas2r_init_adapter_struct()
853 a->flags2 |= AF2_SERIAL_FLASH; in esas2r_init_adapter_struct()
855 if (a->pcid->subsystem_device == ATTO_TLSH_1068) in esas2r_init_adapter_struct()
856 a->flags2 |= AF2_THUNDERLINK; in esas2r_init_adapter_struct()
863 for (i = 0, sgl = a->sg_list_mds; i < num_sg_lists; i++, sgl++) { in esas2r_init_adapter_struct()
866 list_add_tail(&sgl->next_desc, &a->free_sg_list_head); in esas2r_init_adapter_struct()
868 if (!esas2r_initmem_alloc(a, sgl, ESAS2R_SGL_ALIGN)) { in esas2r_init_adapter_struct()
877 a->list_size = num_requests + ESAS2R_LIST_EXTRA; in esas2r_init_adapter_struct()
880 a->inbound_list_md.size = a->list_size * in esas2r_init_adapter_struct()
884 if (!esas2r_initmem_alloc(a, &a->inbound_list_md, ESAS2R_LIST_ALIGN)) { in esas2r_init_adapter_struct()
890 a->outbound_list_md.size = a->list_size * in esas2r_init_adapter_struct()
893 if (!esas2r_initmem_alloc(a, &a->outbound_list_md, in esas2r_init_adapter_struct()
900 a->nvram = (struct esas2r_sas_nvram *)high; in esas2r_init_adapter_struct()
904 a->disc_buffer = high; in esas2r_init_adapter_struct()
909 a->outbound_copy = (u32 volatile *)high; in esas2r_init_adapter_struct()
912 if (!test_bit(AF_NVR_VALID, &a->flags)) in esas2r_init_adapter_struct()
913 esas2r_nvram_set_defaults(a); in esas2r_init_adapter_struct()
919 if (test_bit(AF_FIRST_INIT, &a->flags)) { in esas2r_init_adapter_struct()
920 esas2r_targ_db_initialize(a); in esas2r_init_adapter_struct()
924 (struct esas2r_inbound_list_source_entry *)a-> in esas2r_init_adapter_struct()
928 for (i = 0; i < a->list_size; i++) { in esas2r_init_adapter_struct()
940 for (rq = a->first_ae_req, i = 0; i < num_ae_requests; rq++, in esas2r_init_adapter_struct()
943 if (!alloc_vda_req(a, rq)) { in esas2r_init_adapter_struct()
945 "failed to allocate a VDA request!"); in esas2r_init_adapter_struct()
949 esas2r_rq_init_request(rq, a); in esas2r_init_adapter_struct()
960 bool esas2r_check_adapter(struct esas2r_adapter *a) in esas2r_check_adapter() argument
968 * if the chip reset detected flag is set, we can bypass a bunch of in esas2r_check_adapter()
971 if (test_bit(AF_CHPRST_DETECTED, &a->flags)) in esas2r_check_adapter()
976 * may have left them enabled or we may be recovering from a fault. in esas2r_check_adapter()
978 esas2r_write_register_dword(a, MU_INT_MASK_OUT, ESAS2R_INT_DIS_MASK); in esas2r_check_adapter()
979 esas2r_flush_register_dword(a, MU_INT_MASK_OUT); in esas2r_check_adapter()
983 * waiting for a response. in esas2r_check_adapter()
988 esas2r_force_interrupt(a); in esas2r_check_adapter()
989 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT); in esas2r_check_adapter()
993 * register access after a reset. in esas2r_check_adapter()
996 return esas2r_set_degraded_mode(a, in esas2r_check_adapter()
1005 esas2r_write_register_dword(a, MU_DOORBELL_OUT, in esas2r_check_adapter()
1009 set_bit(AF_LEGACY_SGE_MODE, &a->flags); in esas2r_check_adapter()
1011 a->max_vdareq_size = 128; in esas2r_check_adapter()
1012 a->build_sgl = esas2r_build_sg_list_sge; in esas2r_check_adapter()
1014 clear_bit(AF_LEGACY_SGE_MODE, &a->flags); in esas2r_check_adapter()
1016 a->max_vdareq_size = 1024; in esas2r_check_adapter()
1017 a->build_sgl = esas2r_build_sg_list_prd; in esas2r_check_adapter()
1019 return esas2r_set_degraded_mode(a, in esas2r_check_adapter()
1031 return esas2r_set_degraded_mode(a, in esas2r_check_adapter()
1037 esas2r_write_register_dword(a, MU_DOORBELL_IN, DRBL_MSG_IFC_DOWN); in esas2r_check_adapter()
1041 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT); in esas2r_check_adapter()
1043 esas2r_write_register_dword(a, MU_DOORBELL_OUT, in esas2r_check_adapter()
1060 dw = esas2r_read_register_dword(a, MU_IN_LIST_CONFIG); in esas2r_check_adapter()
1062 esas2r_write_register_dword(a, MU_IN_LIST_CONFIG, dw); in esas2r_check_adapter()
1063 dw = esas2r_read_register_dword(a, MU_OUT_LIST_CONFIG); in esas2r_check_adapter()
1065 esas2r_write_register_dword(a, MU_OUT_LIST_CONFIG, dw); in esas2r_check_adapter()
1068 ppaddr = a->inbound_list_md.phys_addr; in esas2r_check_adapter()
1069 esas2r_write_register_dword(a, MU_IN_LIST_ADDR_LO, in esas2r_check_adapter()
1071 esas2r_write_register_dword(a, MU_IN_LIST_ADDR_HI, in esas2r_check_adapter()
1073 ppaddr = a->outbound_list_md.phys_addr; in esas2r_check_adapter()
1074 esas2r_write_register_dword(a, MU_OUT_LIST_ADDR_LO, in esas2r_check_adapter()
1076 esas2r_write_register_dword(a, MU_OUT_LIST_ADDR_HI, in esas2r_check_adapter()
1078 ppaddr = a->uncached_phys + in esas2r_check_adapter()
1079 ((u8 *)a->outbound_copy - a->uncached); in esas2r_check_adapter()
1080 esas2r_write_register_dword(a, MU_OUT_LIST_COPY_PTR_LO, in esas2r_check_adapter()
1082 esas2r_write_register_dword(a, MU_OUT_LIST_COPY_PTR_HI, in esas2r_check_adapter()
1086 *a->outbound_copy = in esas2r_check_adapter()
1087 a->last_write = in esas2r_check_adapter()
1088 a->last_read = a->list_size - 1; in esas2r_check_adapter()
1089 set_bit(AF_COMM_LIST_TOGGLE, &a->flags); in esas2r_check_adapter()
1090 esas2r_write_register_dword(a, MU_IN_LIST_WRITE, MU_ILW_TOGGLE | in esas2r_check_adapter()
1091 a->last_write); in esas2r_check_adapter()
1092 esas2r_write_register_dword(a, MU_OUT_LIST_COPY, MU_OLC_TOGGLE | in esas2r_check_adapter()
1093 a->last_write); in esas2r_check_adapter()
1094 esas2r_write_register_dword(a, MU_IN_LIST_READ, MU_ILR_TOGGLE | in esas2r_check_adapter()
1095 a->last_write); in esas2r_check_adapter()
1096 esas2r_write_register_dword(a, MU_OUT_LIST_WRITE, in esas2r_check_adapter()
1097 MU_OLW_TOGGLE | a->last_write); in esas2r_check_adapter()
1100 dw = esas2r_read_register_dword(a, MU_IN_LIST_IFC_CONFIG); in esas2r_check_adapter()
1102 esas2r_write_register_dword(a, MU_IN_LIST_IFC_CONFIG, in esas2r_check_adapter()
1104 dw = esas2r_read_register_dword(a, MU_OUT_LIST_IFC_CONFIG); in esas2r_check_adapter()
1106 esas2r_write_register_dword(a, MU_OUT_LIST_IFC_CONFIG, in esas2r_check_adapter()
1111 dw = esas2r_read_register_dword(a, MU_IN_LIST_CONFIG); in esas2r_check_adapter()
1114 | (a->list_size << MU_ILC_NUMBER_SHIFT); in esas2r_check_adapter()
1115 esas2r_write_register_dword(a, MU_IN_LIST_CONFIG, dw); in esas2r_check_adapter()
1116 dw = esas2r_read_register_dword(a, MU_OUT_LIST_CONFIG); in esas2r_check_adapter()
1118 dw |= MU_OLC_ENTRY_4_DW | (a->list_size << MU_OLC_NUMBER_SHIFT); in esas2r_check_adapter()
1119 esas2r_write_register_dword(a, MU_OUT_LIST_CONFIG, dw); in esas2r_check_adapter()
1126 esas2r_write_register_dword(a, MU_DOORBELL_IN, DRBL_MSG_IFC_INIT); in esas2r_check_adapter()
1130 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT); in esas2r_check_adapter()
1132 esas2r_write_register_dword(a, MU_DOORBELL_OUT, in esas2r_check_adapter()
1143 return esas2r_set_degraded_mode(a, in esas2r_check_adapter()
1152 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_IN_ENB); in esas2r_check_adapter()
1154 set_bit(AF2_VDA_POWER_DOWN, &a->flags2); in esas2r_check_adapter()
1156 clear_bit(AF2_VDA_POWER_DOWN, &a->flags2); in esas2r_check_adapter()
1162 esas2r_write_register_dword(a, MU_OUT_LIST_INT_MASK, MU_OLIS_MASK); in esas2r_check_adapter()
1163 esas2r_write_register_dword(a, MU_DOORBELL_OUT_ENB, DRBL_ENB_MASK); in esas2r_check_adapter()
1168 static bool esas2r_format_init_msg(struct esas2r_adapter *a, in esas2r_format_init_msg() argument
1171 u32 msg = a->init_msg; in esas2r_format_init_msg()
1174 a->init_msg = 0; in esas2r_format_init_msg()
1181 esas2r_build_cfg_req(a, in esas2r_format_init_msg()
1191 a->init_msg = ESAS2R_INIT_MSG_INIT; in esas2r_format_init_msg()
1201 a->fw_version = le16_to_cpu( in esas2r_format_init_msg()
1203 a->fw_build = rq->func_rsp.cfg_rsp.fw_build; in esas2r_format_init_msg()
1208 a->fw_version += (major << 16) + (minor << 24); in esas2r_format_init_msg()
1218 if ((test_bit(AF2_THUNDERBOLT, &a->flags2)) in esas2r_format_init_msg()
1219 || (be32_to_cpu(a->fw_version) > 0x00524702)) { in esas2r_format_init_msg()
1221 esas2r_build_cfg_req(a, in esas2r_format_init_msg()
1236 a->init_msg = ESAS2R_INIT_MSG_GET_INIT; in esas2r_format_init_msg()
1245 a->num_targets_backend = in esas2r_format_init_msg()
1247 a->ioctl_tunnel = in esas2r_format_init_msg()
1266 bool esas2r_init_msgs(struct esas2r_adapter *a) in esas2r_init_msgs() argument
1269 struct esas2r_request *rq = &a->general_req; in esas2r_init_msgs()
1271 esas2r_rq_init_request(rq, a); in esas2r_init_msgs()
1274 if (a->init_msg == 0) in esas2r_init_msgs()
1275 a->init_msg = ESAS2R_INIT_MSG_REINIT; in esas2r_init_msgs()
1277 while (a->init_msg) { in esas2r_init_msgs()
1278 if (esas2r_format_init_msg(a, rq)) { in esas2r_init_msgs()
1281 spin_lock_irqsave(&a->queue_lock, flags); in esas2r_init_msgs()
1282 esas2r_start_vda_request(a, rq); in esas2r_init_msgs()
1283 spin_unlock_irqrestore(&a->queue_lock, flags); in esas2r_init_msgs()
1284 esas2r_wait_request(a, rq); in esas2r_init_msgs()
1296 a->init_msg, rq->req_stat, rq->flags); in esas2r_init_msgs()
1297 a->init_msg = ESAS2R_INIT_MSG_START; in esas2r_init_msgs()
1302 esas2r_rq_destroy_request(rq, a); in esas2r_init_msgs()
1307 bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll) in esas2r_init_adapter_hw() argument
1313 if (test_bit(AF_DEGRADED_MODE, &a->flags)) in esas2r_init_adapter_hw()
1316 if (!test_bit(AF_NVR_VALID, &a->flags)) { in esas2r_init_adapter_hw()
1317 if (!esas2r_nvram_read_direct(a)) in esas2r_init_adapter_hw()
1322 if (!esas2r_init_msgs(a)) { in esas2r_init_adapter_hw()
1323 esas2r_set_degraded_mode(a, "init messages failed"); in esas2r_init_adapter_hw()
1328 clear_bit(AF_DEGRADED_MODE, &a->flags); in esas2r_init_adapter_hw()
1329 clear_bit(AF_CHPRST_PENDING, &a->flags); in esas2r_init_adapter_hw()
1332 for (i = 0, rq = a->first_ae_req; i < num_ae_requests; i++, rq++) in esas2r_init_adapter_hw()
1333 esas2r_start_ae_request(a, rq); in esas2r_init_adapter_hw()
1335 if (!a->flash_rev[0]) in esas2r_init_adapter_hw()
1336 esas2r_read_flash_rev(a); in esas2r_init_adapter_hw()
1338 if (!a->image_type[0]) in esas2r_init_adapter_hw()
1339 esas2r_read_image_type(a); in esas2r_init_adapter_hw()
1341 if (a->fw_version == 0) in esas2r_init_adapter_hw()
1342 a->fw_rev[0] = 0; in esas2r_init_adapter_hw()
1344 sprintf(a->fw_rev, "%1d.%02d", in esas2r_init_adapter_hw()
1345 (int)LOBYTE(HIWORD(a->fw_version)), in esas2r_init_adapter_hw()
1346 (int)HIBYTE(HIWORD(a->fw_version))); in esas2r_init_adapter_hw()
1348 esas2r_hdebug("firmware revision: %s", a->fw_rev); in esas2r_init_adapter_hw()
1350 if (test_bit(AF_CHPRST_DETECTED, &a->flags) in esas2r_init_adapter_hw()
1351 && (test_bit(AF_FIRST_INIT, &a->flags))) { in esas2r_init_adapter_hw()
1352 esas2r_enable_chip_interrupts(a); in esas2r_init_adapter_hw()
1357 esas2r_disc_initialize(a); in esas2r_init_adapter_hw()
1362 * resuming from a low power state. deferred device waiting will use in esas2r_init_adapter_hw()
1364 * avoid being in a TASKLET too long. in esas2r_init_adapter_hw()
1367 u32 currtime = a->disc_start_time; in esas2r_init_adapter_hw()
1375 set_bit(AF_TASKLET_SCHEDULED, &a->flags); in esas2r_init_adapter_hw()
1376 set_bit(AF_DISC_POLLED, &a->flags); in esas2r_init_adapter_hw()
1383 if (test_bit(AF_FIRST_INIT, &a->flags)) in esas2r_init_adapter_hw()
1384 atomic_dec(&a->disable_cnt); in esas2r_init_adapter_hw()
1386 while (test_bit(AF_DISC_PENDING, &a->flags)) { in esas2r_init_adapter_hw()
1390 * Determine the need for a timer tick based on the in esas2r_init_adapter_hw()
1401 * up. If a chip reset happens during initial polling, in esas2r_init_adapter_hw()
1405 if (!test_bit(AF_CHPRST_PENDING, &a->flags)) in esas2r_init_adapter_hw()
1406 esas2r_disc_check_for_work(a); in esas2r_init_adapter_hw()
1408 /* Simulate a timer tick. */ in esas2r_init_adapter_hw()
1411 /* Time for a timer tick */ in esas2r_init_adapter_hw()
1413 esas2r_timer_tick(a); in esas2r_init_adapter_hw()
1420 if (esas2r_is_tasklet_pending(a)) in esas2r_init_adapter_hw()
1421 esas2r_do_tasklet_tasks(a); in esas2r_init_adapter_hw()
1425 if (test_bit(AF_FIRST_INIT, &a->flags)) in esas2r_init_adapter_hw()
1426 atomic_inc(&a->disable_cnt); in esas2r_init_adapter_hw()
1428 clear_bit(AF_DISC_POLLED, &a->flags); in esas2r_init_adapter_hw()
1429 clear_bit(AF_TASKLET_SCHEDULED, &a->flags); in esas2r_init_adapter_hw()
1433 esas2r_targ_db_report_changes(a); in esas2r_init_adapter_hw()
1436 * For cases where (a) the initialization messages processing may in esas2r_init_adapter_hw()
1437 * handle an interrupt for a port event and a discovery is waiting, but in esas2r_init_adapter_hw()
1442 esas2r_disc_start_waiting(a); in esas2r_init_adapter_hw()
1445 a->int_mask = ESAS2R_INT_STS_MASK; in esas2r_init_adapter_hw()
1446 esas2r_enable_chip_interrupts(a); in esas2r_init_adapter_hw()
1447 esas2r_enable_heartbeat(a); in esas2r_init_adapter_hw()
1456 if (test_bit(AF_CHPRST_DETECTED, &a->flags) && in esas2r_init_adapter_hw()
1457 test_bit(AF_FIRST_INIT, &a->flags)) { in esas2r_init_adapter_hw()
1464 clear_bit(AF_CHPRST_PENDING, &a->flags); in esas2r_init_adapter_hw()
1466 /* First initialization or a subsequent re-init is complete. */ in esas2r_init_adapter_hw()
1468 clear_bit(AF_CHPRST_PENDING, &a->flags); in esas2r_init_adapter_hw()
1469 clear_bit(AF_DISC_PENDING, &a->flags); in esas2r_init_adapter_hw()
1474 if (test_bit(AF_FIRST_INIT, &a->flags)) { in esas2r_init_adapter_hw()
1475 clear_bit(AF_FIRST_INIT, &a->flags); in esas2r_init_adapter_hw()
1477 if (atomic_dec_return(&a->disable_cnt) == 0) in esas2r_init_adapter_hw()
1478 esas2r_do_deferred_processes(a); in esas2r_init_adapter_hw()
1485 void esas2r_reset_adapter(struct esas2r_adapter *a) in esas2r_reset_adapter() argument
1487 set_bit(AF_OS_RESET, &a->flags); in esas2r_reset_adapter()
1488 esas2r_local_reset_adapter(a); in esas2r_reset_adapter()
1489 esas2r_schedule_tasklet(a); in esas2r_reset_adapter()
1492 void esas2r_reset_chip(struct esas2r_adapter *a) in esas2r_reset_chip() argument
1494 if (!esas2r_is_adapter_present(a)) in esas2r_reset_chip()
1500 * to not overwrite a previous crash that was saved. in esas2r_reset_chip()
1502 if (test_bit(AF2_COREDUMP_AVAIL, &a->flags2) && in esas2r_reset_chip()
1503 !test_bit(AF2_COREDUMP_SAVED, &a->flags2)) { in esas2r_reset_chip()
1504 esas2r_read_mem_block(a, in esas2r_reset_chip()
1505 a->fw_coredump_buff, in esas2r_reset_chip()
1509 set_bit(AF2_COREDUMP_SAVED, &a->flags2); in esas2r_reset_chip()
1512 clear_bit(AF2_COREDUMP_AVAIL, &a->flags2); in esas2r_reset_chip()
1515 if (a->pcid->revision == MVR_FREY_B2) in esas2r_reset_chip()
1516 esas2r_write_register_dword(a, MU_CTL_STATUS_IN_B2, in esas2r_reset_chip()
1519 esas2r_write_register_dword(a, MU_CTL_STATUS_IN, in esas2r_reset_chip()
1523 /* Stall a little while to let the reset condition clear */ in esas2r_reset_chip()
1527 static void esas2r_power_down_notify_firmware(struct esas2r_adapter *a) in esas2r_power_down_notify_firmware() argument
1532 esas2r_write_register_dword(a, MU_DOORBELL_IN, DRBL_POWER_DOWN); in esas2r_power_down_notify_firmware()
1536 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT); in esas2r_power_down_notify_firmware()
1538 esas2r_write_register_dword(a, MU_DOORBELL_OUT, in esas2r_power_down_notify_firmware()
1556 void esas2r_power_down(struct esas2r_adapter *a) in esas2r_power_down() argument
1558 set_bit(AF_POWER_MGT, &a->flags); in esas2r_power_down()
1559 set_bit(AF_POWER_DOWN, &a->flags); in esas2r_power_down()
1561 if (!test_bit(AF_DEGRADED_MODE, &a->flags)) { in esas2r_power_down()
1571 esas2r_disable_chip_interrupts(a); in esas2r_power_down()
1572 esas2r_disable_heartbeat(a); in esas2r_power_down()
1575 esas2r_write_register_dword(a, MU_DOORBELL_IN, in esas2r_power_down()
1581 esas2r_read_register_dword(a, MU_DOORBELL_OUT); in esas2r_power_down()
1583 esas2r_write_register_dword(a, MU_DOORBELL_OUT, in esas2r_power_down()
1601 if (test_bit(AF2_VDA_POWER_DOWN, &a->flags2)) in esas2r_power_down()
1602 esas2r_power_down_notify_firmware(a); in esas2r_power_down()
1606 set_bit(AF_OS_RESET, &a->flags); in esas2r_power_down()
1607 set_bit(AF_DISC_PENDING, &a->flags); in esas2r_power_down()
1608 set_bit(AF_CHPRST_PENDING, &a->flags); in esas2r_power_down()
1610 esas2r_process_adapter_reset(a); in esas2r_power_down()
1613 a->prev_dev_cnt = esas2r_targ_db_get_tgt_cnt(a); in esas2r_power_down()
1614 esas2r_targ_db_remove_all(a, false); in esas2r_power_down()
1621 bool esas2r_power_up(struct esas2r_adapter *a, bool init_poll) in esas2r_power_up() argument
1625 clear_bit(AF_POWER_DOWN, &a->flags); in esas2r_power_up()
1626 esas2r_init_pci_cfg_space(a); in esas2r_power_up()
1627 set_bit(AF_FIRST_INIT, &a->flags); in esas2r_power_up()
1628 atomic_inc(&a->disable_cnt); in esas2r_power_up()
1631 ret = esas2r_check_adapter(a); in esas2r_power_up()
1632 if (!esas2r_init_adapter_hw(a, init_poll)) in esas2r_power_up()
1636 esas2r_send_reset_ae(a, true); in esas2r_power_up()
1639 clear_bit(AF_POWER_MGT, &a->flags); in esas2r_power_up()
1643 bool esas2r_is_adapter_present(struct esas2r_adapter *a) in esas2r_is_adapter_present() argument
1645 if (test_bit(AF_NOT_PRESENT, &a->flags)) in esas2r_is_adapter_present()
1648 if (esas2r_read_register_dword(a, MU_DOORBELL_OUT) == 0xFFFFFFFF) { in esas2r_is_adapter_present()
1649 set_bit(AF_NOT_PRESENT, &a->flags); in esas2r_is_adapter_present()
1656 const char *esas2r_get_model_name(struct esas2r_adapter *a) in esas2r_get_model_name() argument
1658 switch (a->pcid->subsystem_device) { in esas2r_get_model_name()
1690 const char *esas2r_get_model_name_short(struct esas2r_adapter *a) in esas2r_get_model_name_short() argument
1692 switch (a->pcid->subsystem_device) { in esas2r_get_model_name_short()