Lines Matching defs:sfp
178 static int sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size);
179 static int sg_build_sgat(Sg_scatter_hold * schp, const Sg_fd * sfp,
181 static ssize_t sg_new_read(Sg_fd * sfp, char __user *buf, size_t count,
183 static ssize_t sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count,
185 static int sg_common_write(Sg_fd * sfp, Sg_request * srp,
193 static void sg_build_reserve(Sg_fd * sfp, int req_size);
194 static void sg_link_reserve(Sg_fd * sfp, Sg_request * srp, int size);
195 static void sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp);
199 static int sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp);
200 static void __sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp);
201 static Sg_request *sg_get_rq_mark(Sg_fd * sfp, int pack_id);
202 static Sg_request *sg_add_request(Sg_fd * sfp);
203 static int sg_remove_request(Sg_fd * sfp, Sg_request * srp);
204 static int sg_res_in_use(Sg_fd * sfp);
206 static int sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len);
228 Sg_fd *sfp;
292 if ((sfp = sg_add_sfp(sdp, dev)))
293 filp->private_data = sfp;
312 Sg_fd *sfp;
314 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
318 if (0 == sg_remove_sfp(sdp, sfp)) { /* Returns 1 when sdp gone */
332 Sg_fd *sfp;
339 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
346 if (sfp->force_packid && (count >= SZ_SG_HEADER)) {
374 srp = sg_get_rq_mark(sfp, req_pack_id);
386 __wait_event_interruptible(sfp->read_wait,
388 (srp = sg_get_rq_mark(sfp, req_pack_id))),
402 retval = sg_new_read(sfp, buf, count, srp);
481 sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
525 Sg_fd *sfp;
531 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
549 return sg_new_write(sfp, buf, count, blocking, 0, NULL);
553 if (!(srp = sg_add_request(sfp))) {
559 if (sfp->next_cmd_len > 0) {
560 if (sfp->next_cmd_len > MAX_COMMAND_SIZE) {
562 sfp->next_cmd_len = 0;
563 sg_remove_request(sfp, srp);
566 cmd_size = sfp->next_cmd_len;
567 sfp->next_cmd_len = 0; /* reset so only this write() effected */
581 sg_remove_request(sfp, srp);
617 k = sg_common_write(sfp, srp, cmnd, sfp->timeout, blocking);
622 sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count,
637 sfp->cmd_q = 1; /* when sg_io_hdr seen, set command queuing on */
638 if (!(srp = sg_add_request(sfp))) {
644 sg_remove_request(sfp, srp);
648 sg_remove_request(sfp, srp);
652 if (hp->dxfer_len > sfp->reserve.bufflen) {
653 sg_remove_request(sfp, srp);
657 sg_remove_request(sfp, srp);
660 if (sg_res_in_use(sfp)) {
661 sg_remove_request(sfp, srp);
668 sg_remove_request(sfp, srp);
672 sg_remove_request(sfp, srp);
676 sg_remove_request(sfp, srp);
680 (!sg_allow_access(cmnd[0], sfp->parentdp->device->type))) {
681 sg_remove_request(sfp, srp);
684 k = sg_common_write(sfp, srp, cmnd, timeout, blocking);
693 sg_common_write(Sg_fd * sfp, Sg_request * srp,
697 Sg_device *sdp = sfp->parentdp;
759 sg_srp_done(Sg_request *srp, Sg_fd *sfp)
764 read_lock_irqsave(&sfp->rq_list_lock, iflags);
766 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
778 Sg_fd *sfp;
782 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
800 sg_new_write(sfp, p, SZ_SG_IO_HDR,
807 __wait_event_interruptible(sfp->read_wait,
808 (sdp->detached || sfp->closed || sg_srp_done(srp, sfp)),
812 if (sfp->closed)
819 write_lock_irqsave(&sfp->rq_list_lock, iflags);
821 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
822 result = sg_new_read(sfp, p, SZ_SG_IO_HDR, srp);
833 sfp->timeout_user = val;
834 sfp->timeout = MULDIV (val, HZ, USER_HZ);
839 return sfp->timeout_user;
845 sfp->low_dma = 1;
846 if ((0 == sfp->low_dma) && (0 == sg_res_in_use(sfp))) {
847 val = (int) sfp->reserve.bufflen;
848 sg_remove_scat(&sfp->reserve);
849 sg_build_reserve(sfp, val);
854 sfp->low_dma = sdp->device->host->unchecked_isa_dma;
858 return put_user((int) sfp->low_dma, ip);
886 sfp->force_packid = val ? 1 : 0;
891 read_lock_irqsave(&sfp->rq_list_lock, iflags);
892 for (srp = sfp->headrp; srp; srp = srp->nextrp) {
894 read_unlock_irqrestore(&sfp->rq_list_lock,
900 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
904 read_lock_irqsave(&sfp->rq_list_lock, iflags);
905 for (val = 0, srp = sfp->headrp; srp; srp = srp->nextrp) {
909 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
921 if (val != sfp->reserve.bufflen) {
922 if (sg_res_in_use(sfp) || sfp->mmap_called)
924 sg_remove_scat(&sfp->reserve);
925 sg_build_reserve(sfp, val);
929 val = min_t(int, sfp->reserve.bufflen,
936 sfp->cmd_q = val ? 1 : 0;
939 return put_user((int) sfp->cmd_q, ip);
944 sfp->keep_orphan = val;
947 return put_user((int) sfp->keep_orphan, ip);
952 sfp->next_cmd_len = (val > 0) ? val : 0;
971 read_lock_irqsave(&sfp->rq_list_lock, iflags);
972 for (srp = sfp->headrp, val = 0; val < SG_MAX_QUEUE;
999 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
1080 Sg_fd *sfp;
1083 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
1104 Sg_fd *sfp;
1109 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))
1110 || sfp->closed)
1112 poll_wait(filp, &sfp->read_wait, wait);
1113 read_lock_irqsave(&sfp->rq_list_lock, iflags);
1114 for (srp = sfp->headrp; srp; srp = srp->nextrp) {
1120 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
1124 else if (!sfp->cmd_q) {
1139 Sg_fd *sfp;
1141 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
1146 retval = fasync_helper(fd, filp, mode, &sfp->async_qp);
1153 Sg_fd *sfp;
1160 if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data)))
1162 rsv_schp = &sfp->reserve;
1195 Sg_fd *sfp;
1201 if ((!filp) || (!vma) || (!(sfp = (Sg_fd *) filp->private_data)))
1208 rsv_schp = &sfp->reserve;
1221 sfp->mmap_called = 1;
1223 vma->vm_private_data = sfp;
1235 Sg_fd *sfp;
1243 sfp = srp->parentfp;
1244 if (sfp)
1245 sdp = sfp->parentdp;
1286 if (sfp->closed) { /* whoops this fd already released, cleanup */
1290 if (NULL == sfp->headrp) {
1292 if (0 == sg_remove_sfp(sdp, sfp)) { /* device still present */
1295 sfp = NULL;
1298 if (sfp->keep_orphan)
1305 if (sfp && srp) {
1307 kill_fasync(&sfp->async_qp, SIGPOLL, POLL_IN);
1308 write_lock_irqsave(&sfp->rq_list_lock, iflags);
1310 wake_up_interruptible(&sfp->read_wait);
1311 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
1487 Sg_fd *sfp;
1503 for (sfp = sdp->headfp; sfp; sfp = tsfp) {
1504 tsfp = sfp->nextfp;
1505 for (srp = sfp->headrp; srp; srp = tsrp) {
1507 if (sfp->closed || (0 == sg_srp_done(srp, sfp)))
1510 if (sfp->closed) {
1512 __sg_remove_sfp(sdp, sfp);
1515 wake_up_interruptible(&sfp->read_wait);
1516 kill_fasync(&sfp->async_qp, SIGPOLL,
1621 Sg_fd *sfp = srp->parentfp;
1626 Sg_scatter_hold *rsv_schp = &sfp->reserve;
1633 (!sfp->parentdp->device->host->unchecked_isa_dma)) {
1634 res = sg_build_direct(srp, sfp, dxfer_len);
1638 if ((!sg_res_in_use(sfp)) && (dxfer_len <= rsv_schp->bufflen))
1639 sg_link_reserve(sfp, srp, dxfer_len);
1641 res = sg_build_indirect(req_schp, sfp, dxfer_len);
1653 Sg_fd *sfp = srp->parentfp;
1658 sg_unlink_reserve(sfp, srp);
1661 sg_remove_request(sfp, srp);
1665 sg_build_sgat(Sg_scatter_hold * schp, const Sg_fd * sfp, int tablesize)
1670 if (sfp->low_dma)
1791 sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len)
1796 int sg_tablesize = sfp->parentdp->sg_tablesize;
1798 struct scsi_device *sdev = sfp->parentdp->device;
1804 mx_sc_elems = sg_build_sgat(schp, sfp, sg_tablesize);
1825 sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
1829 int sg_tablesize = sfp->parentdp->sg_tablesize;
1833 if ((blk_size < 0) || (!sfp))
1843 mx_sc_elems = sg_build_sgat(schp, sfp, sg_tablesize);
1861 p = sg_page_malloc(num, sfp->low_dma, &ret_sz);
2131 sg_build_reserve(Sg_fd * sfp, int req_size)
2133 Sg_scatter_hold *schp = &sfp->reserve;
2139 if (0 == sg_build_indirect(schp, sfp, req_size))
2148 sg_link_reserve(Sg_fd * sfp, Sg_request * srp, int size)
2151 Sg_scatter_hold *rsv_schp = &sfp->reserve;
2162 sfp->save_scat_len = num;
2180 sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp)
2183 Sg_scatter_hold *rsv_schp = &sfp->reserve;
2190 if (sfp->save_scat_len > 0)
2192 (unsigned) sfp->save_scat_len;
2200 sfp->save_scat_len = 0;
2205 sg_get_rq_mark(Sg_fd * sfp, int pack_id)
2210 write_lock_irqsave(&sfp->rq_list_lock, iflags);
2211 for (resp = sfp->headrp; resp; resp = resp->nextrp) {
2219 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
2225 sg_get_nth_request(Sg_fd * sfp, int nth)
2231 read_lock_irqsave(&sfp->rq_list_lock, iflags);
2232 for (k = 0, resp = sfp->headrp; resp && (k < nth);
2234 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
2241 sg_add_request(Sg_fd * sfp)
2246 Sg_request *rp = sfp->req_arr;
2248 write_lock_irqsave(&sfp->rq_list_lock, iflags);
2249 resp = sfp->headrp;
2252 rp->parentfp = sfp;
2254 sfp->headrp = resp;
2256 if (0 == sfp->cmd_q)
2265 rp->parentfp = sfp;
2278 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
2284 sg_remove_request(Sg_fd * sfp, Sg_request * srp)
2291 if ((!sfp) || (!srp) || (!sfp->headrp))
2293 write_lock_irqsave(&sfp->rq_list_lock, iflags);
2294 prev_rp = sfp->headrp;
2296 sfp->headrp = prev_rp->nextrp;
2310 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
2333 Sg_fd *sfp;
2337 sfp = kzalloc(sizeof(*sfp), GFP_ATOMIC | __GFP_NOWARN);
2338 if (!sfp)
2341 init_waitqueue_head(&sfp->read_wait);
2342 rwlock_init(&sfp->rq_list_lock);
2344 sfp->timeout = SG_DEFAULT_TIMEOUT;
2345 sfp->timeout_user = SG_DEFAULT_TIMEOUT_USER;
2346 sfp->force_packid = SG_DEF_FORCE_PACK_ID;
2347 sfp->low_dma = (SG_DEF_FORCE_LOW_DMA == 0) ?
2349 sfp->cmd_q = SG_DEF_COMMAND_Q;
2350 sfp->keep_orphan = SG_DEF_KEEP_ORPHAN;
2351 sfp->parentdp = sdp;
2354 sdp->headfp = sfp;
2359 pfp->nextfp = sfp;
2362 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: sfp=0x%p\n", sfp));
2368 sg_build_reserve(sfp, bufflen);
2370 sfp->reserve.bufflen, sfp->reserve.k_use_sg));
2371 return sfp;
2375 __sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp)
2381 if (sfp == prev_fp)
2385 if (sfp == fp) {
2392 if (sfp->reserve.bufflen > 0) {
2395 (int) sfp->reserve.bufflen, (int) sfp->reserve.k_use_sg));
2396 sg_remove_scat(&sfp->reserve);
2398 sfp->parentdp = NULL;
2399 SCSI_LOG_TIMEOUT(6, printk("__sg_remove_sfp: sfp=0x%p\n", sfp));
2400 kfree(sfp);
2405 sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp)
2412 for (srp = sfp->headrp; srp; srp = tsrp) {
2414 if (sg_srp_done(srp, sfp))
2423 __sg_remove_sfp(sdp, sfp);
2443 sfp->closed = 1; /* flag dirty state on this fd */
2451 sg_res_in_use(Sg_fd * sfp)
2456 read_lock_irqsave(&sfp->rq_list_lock, iflags);
2457 for (srp = sfp->headrp; srp; srp = srp->nextrp)
2460 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);