linux/include/scsi/libiscsi_tcp.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-or-later */
   2/*
   3 * iSCSI over TCP/IP Data-Path lib
   4 *
   5 * Copyright (C) 2008 Mike Christie
   6 * Copyright (C) 2008 Red Hat, Inc.  All rights reserved.
   7 * maintained by open-iscsi@googlegroups.com
   8 *
   9 * See the file COPYING included with this distribution for more details.
  10 */
  11
  12#ifndef LIBISCSI_TCP_H
  13#define LIBISCSI_TCP_H
  14
  15#include <scsi/libiscsi.h>
  16
  17struct iscsi_tcp_conn;
  18struct iscsi_segment;
  19struct sk_buff;
  20struct ahash_request;
  21
  22typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
  23                                    struct iscsi_segment *);
  24
  25struct iscsi_segment {
  26        unsigned char           *data;
  27        unsigned int            size;
  28        unsigned int            copied;
  29        unsigned int            total_size;
  30        unsigned int            total_copied;
  31
  32        struct ahash_request    *hash;
  33        unsigned char           padbuf[ISCSI_PAD_LEN];
  34        unsigned char           recv_digest[ISCSI_DIGEST_SIZE];
  35        unsigned char           digest[ISCSI_DIGEST_SIZE];
  36        unsigned int            digest_len;
  37
  38        struct scatterlist      *sg;
  39        void                    *sg_mapped;
  40        unsigned int            sg_offset;
  41        bool                    atomic_mapped;
  42
  43        iscsi_segment_done_fn_t *done;
  44};
  45
  46/* Socket connection receive helper */
  47struct iscsi_tcp_recv {
  48        struct iscsi_hdr        *hdr;
  49        struct iscsi_segment    segment;
  50
  51        /* Allocate buffer for BHS + AHS */
  52        uint32_t                hdr_buf[64];
  53
  54        /* copied and flipped values */
  55        int                     datalen;
  56};
  57
  58struct iscsi_tcp_conn {
  59        struct iscsi_conn       *iscsi_conn;
  60        void                    *dd_data;
  61        int                     stop_stage;     /* conn_stop() flag: *
  62                                                 * stop to recover,  *
  63                                                 * stop to terminate */
  64        /* control data */
  65        struct iscsi_tcp_recv   in;             /* TCP receive context */
  66        /* CRC32C (Rx) LLD should set this is they do not offload */
  67        struct ahash_request    *rx_hash;
  68};
  69
  70struct iscsi_tcp_task {
  71        uint32_t                exp_datasn;     /* expected target's R2TSN/DataSN */
  72        int                     data_offset;
  73        struct iscsi_r2t_info   *r2t;           /* in progress solict R2T */
  74        struct iscsi_pool       r2tpool;
  75        struct kfifo            r2tqueue;
  76        void                    *dd_data;
  77        spinlock_t              pool2queue;
  78        spinlock_t              queue2pool;
  79};
  80
  81enum {
  82        ISCSI_TCP_SEGMENT_DONE,         /* curr seg has been processed */
  83        ISCSI_TCP_SKB_DONE,             /* skb is out of data */
  84        ISCSI_TCP_CONN_ERR,             /* iscsi layer has fired a conn err */
  85        ISCSI_TCP_SUSPENDED,            /* conn is suspended */
  86};
  87
  88extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
  89extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
  90                              unsigned int offset, bool offloaded, int *status);
  91extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
  92extern int iscsi_tcp_task_init(struct iscsi_task *task);
  93extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
  94
  95/* segment helpers */
  96extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
  97extern int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
  98                                  struct iscsi_segment *segment, int recv,
  99                                  unsigned copied);
 100extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
 101
 102extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
 103                                      void *data, size_t size,
 104                                      iscsi_segment_done_fn_t *done,
 105                                      struct ahash_request *hash);
 106extern int
 107iscsi_segment_seek_sg(struct iscsi_segment *segment,
 108                      struct scatterlist *sg_list, unsigned int sg_count,
 109                      unsigned int offset, size_t size,
 110                      iscsi_segment_done_fn_t *done,
 111                      struct ahash_request *hash);
 112
 113/* digest helpers */
 114extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr,
 115                                  size_t hdrlen,
 116                                  unsigned char digest[ISCSI_DIGEST_SIZE]);
 117extern struct iscsi_cls_conn *
 118iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
 119                     uint32_t conn_idx);
 120extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
 121
 122/* misc helpers */
 123extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
 124extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
 125extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf);
 126extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
 127                                     struct iscsi_stats *stats);
 128#endif /* LIBISCSI_TCP_H */
 129