Lines Matching refs:h

94 static int realloc_buffer(struct alua_dh_data *h, unsigned len)  in realloc_buffer()  argument
96 if (h->buff && h->buff != h->inq) in realloc_buffer()
97 kfree(h->buff); in realloc_buffer()
99 h->buff = kmalloc(len, GFP_NOIO); in realloc_buffer()
100 if (!h->buff) { in realloc_buffer()
101 h->buff = h->inq; in realloc_buffer()
102 h->bufflen = ALUA_INQUIRY_SIZE; in realloc_buffer()
105 h->bufflen = len; in realloc_buffer()
143 static int submit_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h) in submit_vpd_inquiry() argument
148 rq = get_alua_req(sdev, h->buff, h->bufflen, READ); in submit_vpd_inquiry()
156 rq->cmd[4] = h->bufflen; in submit_vpd_inquiry()
159 rq->sense = h->sense; in submit_vpd_inquiry()
161 rq->sense_len = h->senselen = 0; in submit_vpd_inquiry()
168 h->senselen = rq->sense_len; in submit_vpd_inquiry()
180 static unsigned submit_rtpg(struct scsi_device *sdev, struct alua_dh_data *h, in submit_rtpg() argument
186 rq = get_alua_req(sdev, h->buff, h->bufflen, READ); in submit_rtpg()
196 rq->cmd[6] = (h->bufflen >> 24) & 0xff; in submit_rtpg()
197 rq->cmd[7] = (h->bufflen >> 16) & 0xff; in submit_rtpg()
198 rq->cmd[8] = (h->bufflen >> 8) & 0xff; in submit_rtpg()
199 rq->cmd[9] = h->bufflen & 0xff; in submit_rtpg()
202 rq->sense = h->sense; in submit_rtpg()
204 rq->sense_len = h->senselen = 0; in submit_rtpg()
211 h->senselen = rq->sense_len; in submit_rtpg()
230 struct alua_dh_data *h = req->end_io_data; in stpg_endio() local
241 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, in stpg_endio()
247 err = alua_check_sense(h->sdev, &sense_hdr); in stpg_endio()
252 sdev_printk(KERN_INFO, h->sdev, in stpg_endio()
261 h->state = TPGS_STATE_OPTIMIZED; in stpg_endio()
262 sdev_printk(KERN_INFO, h->sdev, in stpg_endio()
264 ALUA_DH_NAME, h->group_id, in stpg_endio()
265 print_alua_state(h->state)); in stpg_endio()
270 if (h->callback_fn) { in stpg_endio()
271 h->callback_fn(h->callback_data, err); in stpg_endio()
272 h->callback_fn = h->callback_data = NULL; in stpg_endio()
284 static unsigned submit_stpg(struct alua_dh_data *h) in submit_stpg() argument
288 struct scsi_device *sdev = h->sdev; in submit_stpg()
291 memset(h->buff, 0, stpg_len); in submit_stpg()
292 h->buff[4] = TPGS_STATE_OPTIMIZED & 0x0f; in submit_stpg()
293 h->buff[6] = (h->group_id >> 8) & 0xff; in submit_stpg()
294 h->buff[7] = h->group_id & 0xff; in submit_stpg()
296 rq = get_alua_req(sdev, h->buff, stpg_len, WRITE); in submit_stpg()
309 rq->sense = h->sense; in submit_stpg()
311 rq->sense_len = h->senselen = 0; in submit_stpg()
312 rq->end_io_data = h; in submit_stpg()
325 static int alua_check_tpgs(struct scsi_device *sdev, struct alua_dh_data *h) in alua_check_tpgs() argument
329 h->tpgs = scsi_device_tpgs(sdev); in alua_check_tpgs()
330 switch (h->tpgs) { in alua_check_tpgs()
345 h->tpgs = TPGS_MODE_NONE; in alua_check_tpgs()
362 static int alua_vpd_inquiry(struct scsi_device *sdev, struct alua_dh_data *h) in alua_vpd_inquiry() argument
369 err = submit_vpd_inquiry(sdev, h); in alua_vpd_inquiry()
375 len = (h->buff[2] << 8) + h->buff[3] + 4; in alua_vpd_inquiry()
376 if (len > h->bufflen) { in alua_vpd_inquiry()
378 if (realloc_buffer(h, len)) { in alua_vpd_inquiry()
391 d = h->buff + 4; in alua_vpd_inquiry()
392 while (d < h->buff + len) { in alua_vpd_inquiry()
396 h->rel_port = (d[6] << 8) + d[7]; in alua_vpd_inquiry()
400 h->group_id = (d[6] << 8) + d[7]; in alua_vpd_inquiry()
408 if (h->group_id == -1) { in alua_vpd_inquiry()
417 h->state = TPGS_STATE_OPTIMIZED; in alua_vpd_inquiry()
418 h->tpgs = TPGS_MODE_NONE; in alua_vpd_inquiry()
423 ALUA_DH_NAME, h->group_id, h->rel_port); in alua_vpd_inquiry()
537 static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h, int wait_for_transition) in alua_rtpg() argument
548 if (!h->transition_tmo) in alua_rtpg()
551 expiry = round_jiffies_up(jiffies + h->transition_tmo * HZ); in alua_rtpg()
554 err = submit_rtpg(sdev, h, rtpg_ext_hdr_req); in alua_rtpg()
556 if (err == SCSI_DH_IO && h->senselen > 0) { in alua_rtpg()
557 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, in alua_rtpg()
589 len = (h->buff[0] << 24) + (h->buff[1] << 16) + in alua_rtpg()
590 (h->buff[2] << 8) + h->buff[3] + 4; in alua_rtpg()
592 if (len > h->bufflen) { in alua_rtpg()
594 if (realloc_buffer(h, len)) { in alua_rtpg()
603 orig_transition_tmo = h->transition_tmo; in alua_rtpg()
604 if ((h->buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && h->buff[5] != 0) in alua_rtpg()
605 h->transition_tmo = h->buff[5]; in alua_rtpg()
607 h->transition_tmo = ALUA_FAILOVER_TIMEOUT; in alua_rtpg()
609 if (wait_for_transition && (orig_transition_tmo != h->transition_tmo)) { in alua_rtpg()
612 ALUA_DH_NAME, h->transition_tmo); in alua_rtpg()
613 expiry = jiffies + h->transition_tmo * HZ; in alua_rtpg()
616 if ((h->buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR) in alua_rtpg()
621 for (k = tpg_desc_tbl_off, ucp = h->buff + tpg_desc_tbl_off; in alua_rtpg()
625 if (h->group_id == (ucp[2] << 8) + ucp[3]) { in alua_rtpg()
626 h->state = ucp[0] & 0x0f; in alua_rtpg()
627 h->pref = ucp[0] >> 7; in alua_rtpg()
635 ALUA_DH_NAME, h->group_id, print_alua_state(h->state), in alua_rtpg()
636 h->pref ? "preferred" : "non-preferred", in alua_rtpg()
645 switch (h->state) { in alua_rtpg()
660 h->state = TPGS_STATE_STANDBY; in alua_rtpg()
681 static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h) in alua_initialize() argument
685 err = alua_check_tpgs(sdev, h); in alua_initialize()
689 err = alua_vpd_inquiry(sdev, h); in alua_initialize()
693 err = alua_rtpg(sdev, h, 0); in alua_initialize()
711 struct alua_dh_data *h = get_alua_data(sdev); in alua_set_params() local
725 h->flags |= ALUA_OPTIMIZE_STPG; in alua_set_params()
727 h->flags &= ~ALUA_OPTIMIZE_STPG; in alua_set_params()
749 struct alua_dh_data *h = get_alua_data(sdev); in alua_activate() local
753 err = alua_rtpg(sdev, h, 1); in alua_activate()
758 h->flags |= ALUA_OPTIMIZE_STPG; in alua_activate()
760 if (h->tpgs & TPGS_MODE_EXPLICIT) { in alua_activate()
761 switch (h->state) { in alua_activate()
764 if ((h->flags & ALUA_OPTIMIZE_STPG) && in alua_activate()
765 (!h->pref) && in alua_activate()
766 (h->tpgs & TPGS_MODE_IMPLICIT)) in alua_activate()
785 h->callback_fn = fn; in alua_activate()
786 h->callback_data = data; in alua_activate()
787 err = submit_stpg(h); in alua_activate()
790 h->callback_fn = h->callback_data = NULL; in alua_activate()
807 struct alua_dh_data *h = get_alua_data(sdev); in alua_prep_fn() local
810 if (h->state == TPGS_STATE_TRANSITIONING) in alua_prep_fn()
812 else if (h->state != TPGS_STATE_OPTIMIZED && in alua_prep_fn()
813 h->state != TPGS_STATE_NONOPTIMIZED && in alua_prep_fn()
814 h->state != TPGS_STATE_LBA_DEPENDENT) { in alua_prep_fn()
833 struct alua_dh_data *h; in alua_bus_attach() local
836 h = kzalloc(sizeof(*h) , GFP_KERNEL); in alua_bus_attach()
837 if (!h) in alua_bus_attach()
839 h->tpgs = TPGS_MODE_UNINITIALIZED; in alua_bus_attach()
840 h->state = TPGS_STATE_OPTIMIZED; in alua_bus_attach()
841 h->group_id = -1; in alua_bus_attach()
842 h->rel_port = -1; in alua_bus_attach()
843 h->buff = h->inq; in alua_bus_attach()
844 h->bufflen = ALUA_INQUIRY_SIZE; in alua_bus_attach()
845 h->sdev = sdev; in alua_bus_attach()
847 err = alua_initialize(sdev, h); in alua_bus_attach()
852 return &h->dh_data; in alua_bus_attach()
854 kfree(h); in alua_bus_attach()
864 struct alua_dh_data *h = get_alua_data(sdev); in alua_bus_detach() local
866 if (h->buff && h->inq != h->buff) in alua_bus_detach()
867 kfree(h->buff); in alua_bus_detach()
868 kfree(h); in alua_bus_detach()