Lines Matching refs:h

88 static int realloc_buffer(struct alua_dh_data *h, unsigned len)  in realloc_buffer()  argument
90 if (h->buff && h->buff != h->inq) in realloc_buffer()
91 kfree(h->buff); in realloc_buffer()
93 h->buff = kmalloc(len, GFP_NOIO); in realloc_buffer()
94 if (!h->buff) { in realloc_buffer()
95 h->buff = h->inq; in realloc_buffer()
96 h->bufflen = ALUA_INQUIRY_SIZE; in realloc_buffer()
99 h->bufflen = len; in realloc_buffer()
137 static int submit_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h) in submit_vpd_inquiry() argument
142 rq = get_alua_req(sdev, h->buff, h->bufflen, READ); in submit_vpd_inquiry()
150 rq->cmd[4] = h->bufflen; in submit_vpd_inquiry()
153 rq->sense = h->sense; in submit_vpd_inquiry()
155 rq->sense_len = h->senselen = 0; in submit_vpd_inquiry()
162 h->senselen = rq->sense_len; in submit_vpd_inquiry()
174 static unsigned submit_rtpg(struct scsi_device *sdev, struct alua_dh_data *h, in submit_rtpg() argument
180 rq = get_alua_req(sdev, h->buff, h->bufflen, READ); in submit_rtpg()
190 rq->cmd[6] = (h->bufflen >> 24) & 0xff; in submit_rtpg()
191 rq->cmd[7] = (h->bufflen >> 16) & 0xff; in submit_rtpg()
192 rq->cmd[8] = (h->bufflen >> 8) & 0xff; in submit_rtpg()
193 rq->cmd[9] = h->bufflen & 0xff; in submit_rtpg()
196 rq->sense = h->sense; in submit_rtpg()
198 rq->sense_len = h->senselen = 0; in submit_rtpg()
205 h->senselen = rq->sense_len; in submit_rtpg()
224 struct alua_dh_data *h = req->end_io_data; in stpg_endio() local
235 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, in stpg_endio()
241 err = alua_check_sense(h->sdev, &sense_hdr); in stpg_endio()
246 sdev_printk(KERN_INFO, h->sdev, in stpg_endio()
255 h->state = TPGS_STATE_OPTIMIZED; in stpg_endio()
256 sdev_printk(KERN_INFO, h->sdev, in stpg_endio()
258 ALUA_DH_NAME, h->group_id, in stpg_endio()
259 print_alua_state(h->state)); in stpg_endio()
264 if (h->callback_fn) { in stpg_endio()
265 h->callback_fn(h->callback_data, err); in stpg_endio()
266 h->callback_fn = h->callback_data = NULL; in stpg_endio()
278 static unsigned submit_stpg(struct alua_dh_data *h) in submit_stpg() argument
282 struct scsi_device *sdev = h->sdev; in submit_stpg()
285 memset(h->buff, 0, stpg_len); in submit_stpg()
286 h->buff[4] = TPGS_STATE_OPTIMIZED & 0x0f; in submit_stpg()
287 h->buff[6] = (h->group_id >> 8) & 0xff; in submit_stpg()
288 h->buff[7] = h->group_id & 0xff; in submit_stpg()
290 rq = get_alua_req(sdev, h->buff, stpg_len, WRITE); in submit_stpg()
303 rq->sense = h->sense; in submit_stpg()
305 rq->sense_len = h->senselen = 0; in submit_stpg()
306 rq->end_io_data = h; in submit_stpg()
319 static int alua_check_tpgs(struct scsi_device *sdev, struct alua_dh_data *h) in alua_check_tpgs() argument
323 h->tpgs = scsi_device_tpgs(sdev); in alua_check_tpgs()
324 switch (h->tpgs) { in alua_check_tpgs()
339 h->tpgs = TPGS_MODE_NONE; in alua_check_tpgs()
356 static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h) in alua_vpd_inquiry() argument
363 err = submit_vpd_inquiry(sdev, h); in alua_vpd_inquiry()
369 len = (h->buff[2] << 8) + h->buff[3] + 4; in alua_vpd_inquiry()
370 if (len > h->bufflen) { in alua_vpd_inquiry()
372 if (realloc_buffer(h, len)) { in alua_vpd_inquiry()
385 d = h->buff + 4; in alua_vpd_inquiry()
386 while (d < h->buff + len) { in alua_vpd_inquiry()
390 h->rel_port = (d[6] << 8) + d[7]; in alua_vpd_inquiry()
394 h->group_id = (d[6] << 8) + d[7]; in alua_vpd_inquiry()
402 if (h->group_id == -1) { in alua_vpd_inquiry()
411 h->state = TPGS_STATE_OPTIMIZED; in alua_vpd_inquiry()
412 h->tpgs = TPGS_MODE_NONE; in alua_vpd_inquiry()
417 ALUA_DH_NAME, h->group_id, h->rel_port); in alua_vpd_inquiry()
531 static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h, int wait_for_transition) in alua_rtpg() argument
542 if (!h->transition_tmo) in alua_rtpg()
545 expiry = round_jiffies_up(jiffies + h->transition_tmo * HZ); in alua_rtpg()
548 err = submit_rtpg(sdev, h, rtpg_ext_hdr_req); in alua_rtpg()
550 if (err == SCSI_DH_IO && h->senselen > 0) { in alua_rtpg()
551 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, in alua_rtpg()
583 len = (h->buff[0] << 24) + (h->buff[1] << 16) + in alua_rtpg()
584 (h->buff[2] << 8) + h->buff[3] + 4; in alua_rtpg()
586 if (len > h->bufflen) { in alua_rtpg()
588 if (realloc_buffer(h, len)) { in alua_rtpg()
597 orig_transition_tmo = h->transition_tmo; in alua_rtpg()
598 if ((h->buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && h->buff[5] != 0) in alua_rtpg()
599 h->transition_tmo = h->buff[5]; in alua_rtpg()
601 h->transition_tmo = ALUA_FAILOVER_TIMEOUT; in alua_rtpg()
603 if (wait_for_transition && (orig_transition_tmo != h->transition_tmo)) { in alua_rtpg()
606 ALUA_DH_NAME, h->transition_tmo); in alua_rtpg()
607 expiry = jiffies + h->transition_tmo * HZ; in alua_rtpg()
610 if ((h->buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR) in alua_rtpg()
615 for (k = tpg_desc_tbl_off, ucp = h->buff + tpg_desc_tbl_off; in alua_rtpg()
619 if (h->group_id == (ucp[2] << 8) + ucp[3]) { in alua_rtpg()
620 h->state = ucp[0] & 0x0f; in alua_rtpg()
621 h->pref = ucp[0] >> 7; in alua_rtpg()
629 ALUA_DH_NAME, h->group_id, print_alua_state(h->state), in alua_rtpg()
630 h->pref ? "preferred" : "non-preferred", in alua_rtpg()
639 switch (h->state) { in alua_rtpg()
654 h->state = TPGS_STATE_STANDBY; in alua_rtpg()
675 static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h) in alua_initialize() argument
679 err = alua_check_tpgs(sdev, h); in alua_initialize()
683 err = alua_vpd_inquiry(sdev, h); in alua_initialize()
687 err = alua_rtpg(sdev, h, 0); in alua_initialize()
705 struct alua_dh_data *h = sdev->handler_data; in alua_set_params() local
719 h->flags |= ALUA_OPTIMIZE_STPG; in alua_set_params()
721 h->flags &= ~ALUA_OPTIMIZE_STPG; in alua_set_params()
743 struct alua_dh_data *h = sdev->handler_data; in alua_activate() local
747 err = alua_rtpg(sdev, h, 1); in alua_activate()
752 h->flags |= ALUA_OPTIMIZE_STPG; in alua_activate()
754 if (h->tpgs & TPGS_MODE_EXPLICIT) { in alua_activate()
755 switch (h->state) { in alua_activate()
758 if ((h->flags & ALUA_OPTIMIZE_STPG) && in alua_activate()
759 (!h->pref) && in alua_activate()
760 (h->tpgs & TPGS_MODE_IMPLICIT)) in alua_activate()
779 h->callback_fn = fn; in alua_activate()
780 h->callback_data = data; in alua_activate()
781 err = submit_stpg(h); in alua_activate()
784 h->callback_fn = h->callback_data = NULL; in alua_activate()
801 struct alua_dh_data *h = sdev->handler_data; in alua_prep_fn() local
804 if (h->state == TPGS_STATE_TRANSITIONING) in alua_prep_fn()
806 else if (h->state != TPGS_STATE_OPTIMIZED && in alua_prep_fn()
807 h->state != TPGS_STATE_NONOPTIMIZED && in alua_prep_fn()
808 h->state != TPGS_STATE_LBA_DEPENDENT) { in alua_prep_fn()
822 struct alua_dh_data *h; in alua_bus_attach() local
825 h = kzalloc(sizeof(*h) , GFP_KERNEL); in alua_bus_attach()
826 if (!h) in alua_bus_attach()
828 h->tpgs = TPGS_MODE_UNINITIALIZED; in alua_bus_attach()
829 h->state = TPGS_STATE_OPTIMIZED; in alua_bus_attach()
830 h->group_id = -1; in alua_bus_attach()
831 h->rel_port = -1; in alua_bus_attach()
832 h->buff = h->inq; in alua_bus_attach()
833 h->bufflen = ALUA_INQUIRY_SIZE; in alua_bus_attach()
834 h->sdev = sdev; in alua_bus_attach()
836 err = alua_initialize(sdev, h); in alua_bus_attach()
840 sdev->handler_data = h; in alua_bus_attach()
843 kfree(h); in alua_bus_attach()
853 struct alua_dh_data *h = sdev->handler_data; in alua_bus_detach() local
855 if (h->buff && h->inq != h->buff) in alua_bus_detach()
856 kfree(h->buff); in alua_bus_detach()
858 kfree(h); in alua_bus_detach()