Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * cxgb3i_offload.h: Chelsio S3xx iscsi offloaded tcp connection management |
| 3 | * |
| 4 | * Copyright (C) 2003-2008 Chelsio Communications. All rights reserved. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 7 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 8 | * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this |
| 9 | * release for licensing terms and conditions. |
| 10 | * |
| 11 | * Written by: Dimitris Michailidis (dm@chelsio.com) |
| 12 | * Karen Xie (kxie@chelsio.com) |
| 13 | */ |
| 14 | |
| 15 | #ifndef _CXGB3I_OFFLOAD_H |
| 16 | #define _CXGB3I_OFFLOAD_H |
| 17 | |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <net/tcp.h> |
| 20 | |
| 21 | #include "common.h" |
| 22 | #include "adapter.h" |
| 23 | #include "t3cdev.h" |
| 24 | #include "cxgb3_offload.h" |
| 25 | |
| 26 | #define cxgb3i_log_error(fmt...) printk(KERN_ERR "cxgb3i: ERR! " fmt) |
| 27 | #define cxgb3i_log_warn(fmt...) printk(KERN_WARNING "cxgb3i: WARN! " fmt) |
| 28 | #define cxgb3i_log_info(fmt...) printk(KERN_INFO "cxgb3i: " fmt) |
| 29 | #define cxgb3i_log_debug(fmt, args...) \ |
| 30 | printk(KERN_INFO "cxgb3i: %s - " fmt, __func__ , ## args) |
| 31 | |
| 32 | /** |
| 33 | * struct s3_conn - an iscsi tcp connection structure |
| 34 | * |
| 35 | * @dev: net device of with connection |
| 36 | * @cdev: adapter t3cdev for net device |
| 37 | * @flags: see c3cn_flags below |
| 38 | * @tid: connection id assigned by the h/w |
| 39 | * @qset: queue set used by connection |
| 40 | * @mss_idx: Maximum Segment Size table index |
| 41 | * @l2t: ARP resolution entry for offload packets |
| 42 | * @wr_max: maximum in-flight writes |
| 43 | * @wr_avail: number of writes available |
| 44 | * @wr_unacked: writes since last request for completion notification |
| 45 | * @wr_pending_head: head of pending write queue |
| 46 | * @wr_pending_tail: tail of pending write queue |
| 47 | * @cpl_close: skb for cpl_close_req |
| 48 | * @cpl_abort_req: skb for cpl_abort_req |
| 49 | * @cpl_abort_rpl: skb for cpl_abort_rpl |
| 50 | * @lock: connection status lock |
| 51 | * @refcnt: reference count on connection |
| 52 | * @state: connection state |
| 53 | * @saddr: source ip/port address |
| 54 | * @daddr: destination ip/port address |
| 55 | * @dst_cache: reference to destination route |
| 56 | * @receive_queue: received PDUs |
| 57 | * @write_queue: un-pushed pending writes |
| 58 | * @retry_timer: retry timer for various operations |
| 59 | * @err: connection error status |
| 60 | * @callback_lock: lock for opaque user context |
| 61 | * @user_data: opaque user context |
| 62 | * @rcv_nxt: next receive seq. # |
| 63 | * @copied_seq: head of yet unread data |
| 64 | * @rcv_wup: rcv_nxt on last window update sent |
| 65 | * @snd_nxt: next sequence we send |
| 66 | * @snd_una: first byte we want an ack for |
| 67 | * @write_seq: tail+1 of data held in send buffer |
| 68 | */ |
| 69 | struct s3_conn { |
| 70 | struct net_device *dev; |
| 71 | struct t3cdev *cdev; |
| 72 | unsigned long flags; |
| 73 | int tid; |
| 74 | int qset; |
| 75 | int mss_idx; |
| 76 | struct l2t_entry *l2t; |
| 77 | int wr_max; |
| 78 | int wr_avail; |
| 79 | int wr_unacked; |
| 80 | struct sk_buff *wr_pending_head; |
| 81 | struct sk_buff *wr_pending_tail; |
| 82 | struct sk_buff *cpl_close; |
| 83 | struct sk_buff *cpl_abort_req; |
| 84 | struct sk_buff *cpl_abort_rpl; |
| 85 | spinlock_t lock; |
| 86 | atomic_t refcnt; |
| 87 | volatile unsigned int state; |
| 88 | struct sockaddr_in saddr; |
| 89 | struct sockaddr_in daddr; |
| 90 | struct dst_entry *dst_cache; |
| 91 | struct sk_buff_head receive_queue; |
| 92 | struct sk_buff_head write_queue; |
| 93 | struct timer_list retry_timer; |
| 94 | int err; |
| 95 | rwlock_t callback_lock; |
| 96 | void *user_data; |
| 97 | |
| 98 | u32 rcv_nxt; |
| 99 | u32 copied_seq; |
| 100 | u32 rcv_wup; |
| 101 | u32 snd_nxt; |
| 102 | u32 snd_una; |
| 103 | u32 write_seq; |
| 104 | }; |
| 105 | |
| 106 | /* |
| 107 | * connection state |
| 108 | */ |
| 109 | enum conn_states { |
| 110 | C3CN_STATE_CONNECTING = 1, |
| 111 | C3CN_STATE_ESTABLISHED, |
| 112 | C3CN_STATE_ACTIVE_CLOSE, |
| 113 | C3CN_STATE_PASSIVE_CLOSE, |
| 114 | C3CN_STATE_CLOSE_WAIT_1, |
| 115 | C3CN_STATE_CLOSE_WAIT_2, |
| 116 | C3CN_STATE_ABORTING, |
| 117 | C3CN_STATE_CLOSED, |
| 118 | }; |
| 119 | |
| 120 | static inline unsigned int c3cn_is_closing(const struct s3_conn *c3cn) |
| 121 | { |
| 122 | return c3cn->state >= C3CN_STATE_ACTIVE_CLOSE; |
| 123 | } |
| 124 | static inline unsigned int c3cn_is_established(const struct s3_conn *c3cn) |
| 125 | { |
| 126 | return c3cn->state == C3CN_STATE_ESTABLISHED; |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Connection flags -- many to track some close related events. |
| 131 | */ |
| 132 | enum c3cn_flags { |
| 133 | C3CN_ABORT_RPL_RCVD, /* received one ABORT_RPL_RSS message */ |
| 134 | C3CN_ABORT_REQ_RCVD, /* received one ABORT_REQ_RSS message */ |
| 135 | C3CN_ABORT_RPL_PENDING, /* expecting an abort reply */ |
| 136 | C3CN_TX_DATA_SENT, /* already sent a TX_DATA WR */ |
| 137 | C3CN_ACTIVE_CLOSE_NEEDED, /* need to be closed */ |
| 138 | }; |
| 139 | |
| 140 | /** |
| 141 | * cxgb3i_sdev_data - Per adapter data. |
| 142 | * Linked off of each Ethernet device port on the adapter. |
| 143 | * Also available via the t3cdev structure since we have pointers to our port |
| 144 | * net_device's there ... |
| 145 | * |
| 146 | * @list: list head to link elements |
| 147 | * @cdev: t3cdev adapter |
| 148 | * @client: CPL client pointer |
| 149 | * @ports: array of adapter ports |
| 150 | * @sport_map_next: next index into the port map |
| 151 | * @sport_map: source port map |
| 152 | */ |
| 153 | struct cxgb3i_sdev_data { |
| 154 | struct list_head list; |
| 155 | struct t3cdev *cdev; |
| 156 | struct cxgb3_client *client; |
| 157 | struct adap_ports ports; |
| 158 | unsigned int sport_map_next; |
| 159 | unsigned long sport_map[0]; |
| 160 | }; |
| 161 | #define NDEV2CDATA(ndev) (*(struct cxgb3i_sdev_data **)&(ndev)->ec_ptr) |
| 162 | #define CXGB3_SDEV_DATA(cdev) NDEV2CDATA((cdev)->lldev) |
| 163 | |
| 164 | void cxgb3i_sdev_cleanup(void); |
| 165 | int cxgb3i_sdev_init(cxgb3_cpl_handler_func *); |
| 166 | void cxgb3i_sdev_add(struct t3cdev *, struct cxgb3_client *); |
| 167 | void cxgb3i_sdev_remove(struct t3cdev *); |
| 168 | |
| 169 | struct s3_conn *cxgb3i_c3cn_create(void); |
| 170 | int cxgb3i_c3cn_connect(struct s3_conn *, struct sockaddr_in *); |
| 171 | void cxgb3i_c3cn_rx_credits(struct s3_conn *, int); |
| 172 | int cxgb3i_c3cn_send_pdus(struct s3_conn *, struct sk_buff *); |
| 173 | void cxgb3i_c3cn_release(struct s3_conn *); |
| 174 | |
| 175 | /** |
| 176 | * cxgb3_skb_cb - control block for received pdu state and ULP mode management. |
| 177 | * |
| 178 | * @flag: see C3CB_FLAG_* below |
| 179 | * @ulp_mode: ULP mode/submode of sk_buff |
| 180 | * @seq: tcp sequence number |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 181 | */ |
Karen Xie | 1648b11 | 2009-02-13 21:38:44 -0800 | [diff] [blame] | 182 | struct cxgb3_skb_rx_cb { |
| 183 | __u32 ddigest; /* data digest */ |
| 184 | __u32 pdulen; /* recovered pdu length */ |
| 185 | }; |
| 186 | |
| 187 | struct cxgb3_skb_tx_cb { |
| 188 | struct sk_buff *wr_next; /* next wr */ |
| 189 | }; |
| 190 | |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 191 | struct cxgb3_skb_cb { |
| 192 | __u8 flags; |
| 193 | __u8 ulp_mode; |
| 194 | __u32 seq; |
Karen Xie | 1648b11 | 2009-02-13 21:38:44 -0800 | [diff] [blame] | 195 | union { |
| 196 | struct cxgb3_skb_rx_cb rx; |
| 197 | struct cxgb3_skb_tx_cb tx; |
| 198 | }; |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | #define CXGB3_SKB_CB(skb) ((struct cxgb3_skb_cb *)&((skb)->cb[0])) |
Karen Xie | 1648b11 | 2009-02-13 21:38:44 -0800 | [diff] [blame] | 202 | #define skb_flags(skb) (CXGB3_SKB_CB(skb)->flags) |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 203 | #define skb_ulp_mode(skb) (CXGB3_SKB_CB(skb)->ulp_mode) |
Karen Xie | 1648b11 | 2009-02-13 21:38:44 -0800 | [diff] [blame] | 204 | #define skb_tcp_seq(skb) (CXGB3_SKB_CB(skb)->seq) |
| 205 | #define skb_rx_ddigest(skb) (CXGB3_SKB_CB(skb)->rx.ddigest) |
| 206 | #define skb_rx_pdulen(skb) (CXGB3_SKB_CB(skb)->rx.pdulen) |
| 207 | #define skb_tx_wr_next(skb) (CXGB3_SKB_CB(skb)->tx.wr_next) |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 208 | |
| 209 | enum c3cb_flags { |
| 210 | C3CB_FLAG_NEED_HDR = 1 << 0, /* packet needs a TX_DATA_WR header */ |
| 211 | C3CB_FLAG_NO_APPEND = 1 << 1, /* don't grow this skb */ |
| 212 | C3CB_FLAG_COMPL = 1 << 2, /* request WR completion */ |
| 213 | }; |
| 214 | |
| 215 | /** |
| 216 | * sge_opaque_hdr - |
| 217 | * Opaque version of structure the SGE stores at skb->head of TX_DATA packets |
| 218 | * and for which we must reserve space. |
| 219 | */ |
| 220 | struct sge_opaque_hdr { |
| 221 | void *dev; |
| 222 | dma_addr_t addr[MAX_SKB_FRAGS + 1]; |
| 223 | }; |
| 224 | |
| 225 | /* for TX: a skb must have a headroom of at least TX_HEADER_LEN bytes */ |
| 226 | #define TX_HEADER_LEN \ |
| 227 | (sizeof(struct tx_data_wr) + sizeof(struct sge_opaque_hdr)) |
Karen Xie | f62d089 | 2009-02-13 21:38:54 -0800 | [diff] [blame] | 228 | #define SKB_TX_HEADROOM SKB_MAX_HEAD(TX_HEADER_LEN) |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * get and set private ip for iscsi traffic |
| 232 | */ |
| 233 | #define cxgb3i_get_private_ipv4addr(ndev) \ |
| 234 | (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) |
| 235 | #define cxgb3i_set_private_ipv4addr(ndev, addr) \ |
| 236 | (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr |
| 237 | |
| 238 | /* max. connections per adapter */ |
| 239 | #define CXGB3I_MAX_CONN 16384 |
| 240 | #endif /* _CXGB3_OFFLOAD_H */ |