Linux Audio

Check our new training course

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