Lines Matching full:ch
96 struct ata_channel *ch = device_get_softc(dev); in ata_attach() local
104 if (ch->r_irq) in ata_attach()
108 ch->dev = dev; in ata_attach()
109 ch->state = ATA_IDLE; in ata_attach()
110 bzero(&ch->state_mtx, sizeof(struct mtx)); in ata_attach()
111 mtx_init(&ch->state_mtx, "ATA state lock", NULL, MTX_DEF); in ata_attach()
112 TASK_INIT(&ch->conntask, 0, ata_conn_event, dev); in ata_attach()
114 ch->user[i].revision = 0; in ata_attach()
122 ch->user[i].revision = mode; in ata_attach()
123 ch->user[i].mode = 0; in ata_attach()
134 ch->user[i].mode = mode; in ata_attach()
135 if (ch->flags & ATA_SATA) in ata_attach()
136 ch->user[i].bytecount = 8192; in ata_attach()
138 ch->user[i].bytecount = 65536; in ata_attach()
139 ch->user[i].caps = 0; in ata_attach()
140 ch->curr[i] = ch->user[i]; in ata_attach()
141 if (ch->flags & ATA_SATA) { in ata_attach()
142 if (ch->pm_level > 0) in ata_attach()
143 ch->user[i].caps |= CTS_SATA_CAPS_H_PMREQ; in ata_attach()
144 if (ch->pm_level > 1) in ata_attach()
145 ch->user[i].caps |= CTS_SATA_CAPS_D_PMREQ; in ata_attach()
147 if (!(ch->flags & ATA_NO_48BIT_DMA)) in ata_attach()
148 ch->user[i].caps |= CTS_ATA_CAPS_H_DMA48; in ata_attach()
151 callout_init(&ch->poll_callout, 1); in ata_attach()
154 if (ch->dma.alloc) in ata_attach()
155 ch->dma.alloc(dev); in ata_attach()
159 ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in ata_attach()
161 if (!ch->r_irq) { in ata_attach()
165 if ((error = bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL, in ata_attach()
166 ata_interrupt, ch, &ch->ih))) { in ata_attach()
167 bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq); in ata_attach()
172 if (ch->flags & ATA_PERIODIC_POLL) in ata_attach()
173 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_attach()
174 mtx_lock(&ch->state_mtx); in ata_attach()
183 ch->sim = cam_sim_alloc(ataaction, atapoll, "ata", ch, in ata_attach()
184 device_get_unit(dev), &ch->state_mtx, 1, 0, devq); in ata_attach()
185 if (ch->sim == NULL) { in ata_attach()
191 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) { in ata_attach()
196 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim), in ata_attach()
202 mtx_unlock(&ch->state_mtx); in ata_attach()
206 xpt_bus_deregister(cam_sim_path(ch->sim)); in ata_attach()
208 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ata_attach()
209 ch->sim = NULL; in ata_attach()
211 bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq); in ata_attach()
212 mtx_unlock(&ch->state_mtx); in ata_attach()
213 if (ch->flags & ATA_PERIODIC_POLL) in ata_attach()
214 callout_drain(&ch->poll_callout); in ata_attach()
221 struct ata_channel *ch = device_get_softc(dev); in ata_detach() local
224 if (!ch->r_irq) in ata_detach()
228 mtx_lock(&ch->state_mtx); in ata_detach()
229 ch->state |= ATA_STALL_QUEUE; in ata_detach()
230 mtx_unlock(&ch->state_mtx); in ata_detach()
231 if (ch->flags & ATA_PERIODIC_POLL) in ata_detach()
232 callout_drain(&ch->poll_callout); in ata_detach()
234 taskqueue_drain(taskqueue_thread, &ch->conntask); in ata_detach()
236 mtx_lock(&ch->state_mtx); in ata_detach()
237 xpt_async(AC_LOST_DEVICE, ch->path, NULL); in ata_detach()
238 xpt_free_path(ch->path); in ata_detach()
239 xpt_bus_deregister(cam_sim_path(ch->sim)); in ata_detach()
240 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ata_detach()
241 ch->sim = NULL; in ata_detach()
242 mtx_unlock(&ch->state_mtx); in ata_detach()
245 bus_teardown_intr(dev, ch->r_irq, ch->ih); in ata_detach()
246 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq); in ata_detach()
247 ch->r_irq = NULL; in ata_detach()
250 if (ch->dma.free) in ata_detach()
251 ch->dma.free(dev); in ata_detach()
253 mtx_destroy(&ch->state_mtx); in ata_detach()
261 struct ata_channel *ch = device_get_softc(dev); in ata_conn_event() local
264 mtx_lock(&ch->state_mtx); in ata_conn_event()
265 if (ch->sim == NULL) { in ata_conn_event()
266 mtx_unlock(&ch->state_mtx); in ata_conn_event()
273 cam_sim_path(ch->sim), in ata_conn_event()
279 mtx_unlock(&ch->state_mtx); in ata_conn_event()
285 struct ata_channel *ch = device_get_softc(dev); in ata_reinit() local
288 xpt_freeze_simq(ch->sim, 1); in ata_reinit()
289 if ((request = ch->running)) { in ata_reinit()
290 ch->running = NULL; in ata_reinit()
291 if (ch->state == ATA_ACTIVE) in ata_reinit()
292 ch->state = ATA_IDLE; in ata_reinit()
294 if (ch->dma.unload) in ata_reinit()
295 ch->dma.unload(request); in ata_reinit()
302 xpt_async(AC_BUS_RESET, ch->path, NULL); in ata_reinit()
303 xpt_release_simq(ch->sim, TRUE); in ata_reinit()
310 struct ata_channel *ch; in ata_suspend() local
313 if (!dev || !(ch = device_get_softc(dev))) in ata_suspend()
316 if (ch->flags & ATA_PERIODIC_POLL) in ata_suspend()
317 callout_drain(&ch->poll_callout); in ata_suspend()
318 mtx_lock(&ch->state_mtx); in ata_suspend()
319 xpt_freeze_simq(ch->sim, 1); in ata_suspend()
320 while (ch->state != ATA_IDLE) in ata_suspend()
321 msleep(ch, &ch->state_mtx, PRIBIO, "atasusp", hz/100); in ata_suspend()
322 mtx_unlock(&ch->state_mtx); in ata_suspend()
329 struct ata_channel *ch; in ata_resume() local
333 if (!dev || !(ch = device_get_softc(dev))) in ata_resume()
336 mtx_lock(&ch->state_mtx); in ata_resume()
338 xpt_release_simq(ch->sim, TRUE); in ata_resume()
339 mtx_unlock(&ch->state_mtx); in ata_resume()
340 if (ch->flags & ATA_PERIODIC_POLL) in ata_resume()
341 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_resume()
348 struct ata_channel *ch = (struct ata_channel *)data; in ata_interrupt() local
350 mtx_lock(&ch->state_mtx); in ata_interrupt()
352 mtx_unlock(&ch->state_mtx); in ata_interrupt()
358 struct ata_channel *ch = (struct ata_channel *)data; in ata_interrupt_locked() local
362 if (ch->hw.status && !ch->hw.status(ch->dev)) in ata_interrupt_locked()
366 if (!(request = ch->running)) in ata_interrupt_locked()
372 if (ch->state == ATA_IDLE) { in ata_interrupt_locked()
381 if (ch->hw.end_transaction(request) == ATA_OP_FINISHED) { in ata_interrupt_locked()
382 ch->running = NULL; in ata_interrupt_locked()
383 if (ch->state == ATA_ACTIVE) in ata_interrupt_locked()
384 ch->state = ATA_IDLE; in ata_interrupt_locked()
385 ata_cam_end_transaction(ch->dev, request); in ata_interrupt_locked()
393 struct ata_channel *ch = (struct ata_channel *)data; in ata_periodic_poll() local
395 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_periodic_poll()
396 ata_interrupt(ch); in ata_periodic_poll()
412 struct ata_channel *ch = device_get_softc(dev); in ata_default_registers() local
415 ch->r_io[ATA_ERROR].res = ch->r_io[ATA_FEATURE].res; in ata_default_registers()
416 ch->r_io[ATA_ERROR].offset = ch->r_io[ATA_FEATURE].offset; in ata_default_registers()
417 ch->r_io[ATA_IREASON].res = ch->r_io[ATA_COUNT].res; in ata_default_registers()
418 ch->r_io[ATA_IREASON].offset = ch->r_io[ATA_COUNT].offset; in ata_default_registers()
419 ch->r_io[ATA_STATUS].res = ch->r_io[ATA_COMMAND].res; in ata_default_registers()
420 ch->r_io[ATA_STATUS].offset = ch->r_io[ATA_COMMAND].offset; in ata_default_registers()
421 ch->r_io[ATA_ALTSTAT].res = ch->r_io[ATA_CONTROL].res; in ata_default_registers()
422 ch->r_io[ATA_ALTSTAT].offset = ch->r_io[ATA_CONTROL].offset; in ata_default_registers()
696 struct ata_channel *ch = device_get_softc(dev); in ata_atapi() local
698 return (ch->devices & (ATA_ATAPI_MASTER << target)); in ata_atapi()
705 struct ata_channel *ch; in ata_timeout() local
708 ch = device_get_softc(request->parent); in ata_timeout()
718 if (ch->state == ATA_ACTIVE) { in ata_timeout()
720 if (ch->dma.unload) in ata_timeout()
721 ch->dma.unload(request); in ata_timeout()
722 ch->running = NULL; in ata_timeout()
723 ch->state = ATA_IDLE; in ata_timeout()
724 ata_cam_end_transaction(ch->dev, request); in ata_timeout()
726 mtx_unlock(&ch->state_mtx); in ata_timeout()
732 struct ata_channel *ch = device_get_softc(dev); in ata_cam_begin_transaction() local
735 request = &ch->request; in ata_cam_begin_transaction()
777 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_begin_transaction()
787 if (ch->curr[ccb->ccb_h.target_id].atapi == 16) in ata_cam_begin_transaction()
790 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA) in ata_cam_begin_transaction()
797 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_begin_transaction()
801 callout_init_mtx(&request->callout, &ch->state_mtx, CALLOUT_RETURNUNLOCKED); in ata_cam_begin_transaction()
805 ch->running = request; in ata_cam_begin_transaction()
806 ch->state = ATA_ACTIVE; in ata_cam_begin_transaction()
807 if (ch->hw.begin_transaction(request) == ATA_OP_FINISHED) { in ata_cam_begin_transaction()
808 ch->running = NULL; in ata_cam_begin_transaction()
809 ch->state = ATA_IDLE; in ata_cam_begin_transaction()
818 struct ata_channel *ch = device_get_softc(dev); in ata_cam_request_sense() local
821 ch->requestsense = 1; in ata_cam_request_sense()
832 if (ch->curr[ccb->ccb_h.target_id].atapi == 16) in ata_cam_request_sense()
834 if (ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA) in ata_cam_request_sense()
838 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_request_sense()
841 callout_init_mtx(&request->callout, &ch->state_mtx, CALLOUT_RETURNUNLOCKED); in ata_cam_request_sense()
844 ch->running = request; in ata_cam_request_sense()
845 ch->state = ATA_ACTIVE; in ata_cam_request_sense()
846 if (ch->hw.begin_transaction(request) == ATA_OP_FINISHED) { in ata_cam_request_sense()
847 ch->running = NULL; in ata_cam_request_sense()
848 ch->state = ATA_IDLE; in ata_cam_request_sense()
857 struct ata_channel *ch = device_get_softc(dev); in ata_cam_process_sense() local
861 ch->requestsense = 0; in ata_cam_process_sense()
883 struct ata_channel *ch = device_get_softc(dev); in ata_cam_end_transaction() local
887 if (ch->requestsense) { in ata_cam_end_transaction()
894 xpt_freeze_simq(ch->sim, 1); in ata_cam_end_transaction()
954 struct ata_channel *ch = device_get_softc(dev); in ata_check_ids() local
956 if (ccb->ccb_h.target_id > ((ch->flags & ATA_NO_SLAVE) ? 0 : 1)) { in ata_check_ids()
979 struct ata_channel *ch; in ataaction() local
984 ch = (struct ata_channel *)cam_sim_softc(sim); in ataaction()
985 dev = ch->dev; in ataaction()
992 if ((ch->devices & ((ATA_ATA_MASTER | ATA_ATAPI_MASTER) in ataaction()
997 if (ch->running) in ataaction()
1005 if (ch->devices & (ATA_ATA_MASTER << ccb->ccb_h.target_id)) { in ataaction()
1029 d = &ch->curr[ccb->ccb_h.target_id]; in ataaction()
1031 d = &ch->user[ccb->ccb_h.target_id]; in ataaction()
1032 if (ch->flags & ATA_SATA) { in ataaction()
1037 d->mode = ATA_SETMODE(ch->dev, in ataaction()
1052 d->mode = ATA_SETMODE(ch->dev, in ataaction()
1076 d = &ch->curr[ccb->ccb_h.target_id]; in ataaction()
1078 d = &ch->user[ccb->ccb_h.target_id]; in ataaction()
1081 if (ch->flags & ATA_SATA) { in ataaction()
1098 if (ch->pm_level) { in ataaction()
1103 ch->user[ccb->ccb_h.target_id].caps; in ataaction()
1123 if (!(ch->flags & ATA_NO_48BIT_DMA)) in ataaction()
1127 ch->user[ccb->ccb_h.target_id].caps; in ataaction()
1156 if (ch->flags & ATA_NO_SLAVE) in ataaction()
1163 if (ch->flags & ATA_SATA) in ataaction()
1171 if (ch->flags & ATA_SATA) in ataaction()
1178 cpi->maxio = ch->dma.max_iosize ? ch->dma.max_iosize : DFLTPHYS; in ataaction()
1199 struct ata_channel *ch = (struct ata_channel *)cam_sim_softc(sim); in atapoll() local
1201 ata_interrupt_locked(ch); in atapoll()