blob: 2e326145825c9b519990b65f9297dabd6c08be2f [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/* bnx2i.h: Broadcom NetXtreme II iSCSI driver.
2 *
Eddie Wai9ebd99c2012-04-25 15:08:37 -07003 * Copyright (c) 2006 - 2012 Broadcom Corporation
Michael Chancf4e6362009-06-08 18:14:44 -07004 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
10 *
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
Eddie Wai11cec1e2010-11-23 15:29:31 -080012 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
Michael Chancf4e6362009-06-08 18:14:44 -070013 */
14
15#ifndef _BNX2I_H_
16#define _BNX2I_H_
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20
21#include <linux/errno.h>
22#include <linux/pci.h>
23#include <linux/spinlock.h>
24#include <linux/interrupt.h>
Eddie Waib5cf6b62011-06-23 15:51:34 -070025#include <linux/delay.h>
Michael Chancf4e6362009-06-08 18:14:44 -070026#include <linux/sched.h>
27#include <linux/in.h>
28#include <linux/kfifo.h>
29#include <linux/netdevice.h>
30#include <linux/completion.h>
Eddie Waib5cf6b62011-06-23 15:51:34 -070031#include <linux/kthread.h>
32#include <linux/cpu.h>
Michael Chancf4e6362009-06-08 18:14:44 -070033
34#include <scsi/scsi_cmnd.h>
35#include <scsi/scsi_device.h>
36#include <scsi/scsi_eh.h>
37#include <scsi/scsi_host.h>
38#include <scsi/scsi.h>
39#include <scsi/iscsi_proto.h>
40#include <scsi/libiscsi.h>
41#include <scsi/scsi_transport_iscsi.h>
42
Jeff Kirsheradfc5212011-04-07 06:03:04 -070043#include "../../net/ethernet/broadcom/cnic_if.h"
Michael Chancf4e6362009-06-08 18:14:44 -070044#include "57xx_iscsi_hsi.h"
45#include "57xx_iscsi_constants.h"
46
Barak Witkowski2e499d32012-06-26 01:31:19 +000047#include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h"
48
Michael Chancf4e6362009-06-08 18:14:44 -070049#define BNX2_ISCSI_DRIVER_NAME "bnx2i"
50
51#define BNX2I_MAX_ADAPTERS 8
52
53#define ISCSI_MAX_CONNS_PER_HBA 128
54#define ISCSI_MAX_SESS_PER_HBA ISCSI_MAX_CONNS_PER_HBA
55#define ISCSI_MAX_CMDS_PER_SESS 128
56
57/* Total active commands across all connections supported by devices */
58#define ISCSI_MAX_CMDS_PER_HBA_5708 (28 * (ISCSI_MAX_CMDS_PER_SESS - 1))
59#define ISCSI_MAX_CMDS_PER_HBA_5709 (128 * (ISCSI_MAX_CMDS_PER_SESS - 1))
60#define ISCSI_MAX_CMDS_PER_HBA_57710 (256 * (ISCSI_MAX_CMDS_PER_SESS - 1))
61
62#define ISCSI_MAX_BDS_PER_CMD 32
63
64#define MAX_PAGES_PER_CTRL_STRUCT_POOL 8
65#define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS 4
66
Dmitry Kravkov523224a2010-10-06 03:23:26 +000067#define BNX2I_5771X_DBELL_PAGE_SIZE 128
68
Michael Chancf4e6362009-06-08 18:14:44 -070069/* 5706/08 hardware has limit on maximum buffer size per BD it can handle */
70#define MAX_BD_LENGTH 65535
71#define BD_SPLIT_SIZE 32768
72
73/* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */
Eddie Wai9ae58e12011-05-16 11:13:20 -070074#define BNX2I_SQ_WQES_MIN 16
75#define BNX2I_570X_SQ_WQES_MAX 128
76#define BNX2I_5770X_SQ_WQES_MAX 512
77#define BNX2I_570X_SQ_WQES_DEFAULT 128
78#define BNX2I_5770X_SQ_WQES_DEFAULT 128
Michael Chancf4e6362009-06-08 18:14:44 -070079
80#define BNX2I_570X_CQ_WQES_MAX 128
81#define BNX2I_5770X_CQ_WQES_MAX 512
82
83#define BNX2I_RQ_WQES_MIN 16
84#define BNX2I_RQ_WQES_MAX 32
85#define BNX2I_RQ_WQES_DEFAULT 16
86
87/* CCELLs per conn */
88#define BNX2I_CCELLS_MIN 16
89#define BNX2I_CCELLS_MAX 96
90#define BNX2I_CCELLS_DEFAULT 64
91
92#define ITT_INVALID_SIGNATURE 0xFFFF
93
94#define ISCSI_CMD_CLEANUP_TIMEOUT 100
95
96#define BNX2I_CONN_CTX_BUF_SIZE 16384
97
98#define BNX2I_SQ_WQE_SIZE 64
99#define BNX2I_RQ_WQE_SIZE 256
100#define BNX2I_CQE_SIZE 64
101
102#define MB_KERNEL_CTX_SHIFT 8
103#define MB_KERNEL_CTX_SIZE (1 << MB_KERNEL_CTX_SHIFT)
104
105#define CTX_SHIFT 7
106#define GET_CID_NUM(cid_addr) ((cid_addr) >> CTX_SHIFT)
107
108#define CTX_OFFSET 0x10000
109#define MAX_CID_CNT 0x4000
110
Anil Veerabhadrappa53203242009-09-11 10:38:26 -0700111#define BNX2I_570X_PAGE_SIZE_DEFAULT 4096
112
Michael Chancf4e6362009-06-08 18:14:44 -0700113/* 5709 context registers */
114#define BNX2_MQ_CONFIG2 0x00003d00
115#define BNX2_MQ_CONFIG2_CONT_SZ (0x7L<<4)
116#define BNX2_MQ_CONFIG2_FIRST_L4L5 (0x1fL<<8)
117
118/* 57710's BAR2 is mapped to doorbell registers */
119#define BNX2X_DOORBELL_PCI_BAR 2
120#define BNX2X_MAX_CQS 8
121
122#define CNIC_ARM_CQE 1
Eddie Wai9ae58e12011-05-16 11:13:20 -0700123#define CNIC_ARM_CQE_FP 2
Michael Chancf4e6362009-06-08 18:14:44 -0700124#define CNIC_DISARM_CQE 0
125
126#define REG_RD(__hba, offset) \
127 readl(__hba->regview + offset)
128#define REG_WR(__hba, offset, val) \
129 writel(val, __hba->regview + offset)
130
Barak Witkowski2e499d32012-06-26 01:31:19 +0000131#ifdef CONFIG_32BIT
132#define GET_STATS_64(__hba, dst, field) \
133 do { \
134 spin_lock_bh(&__hba->stat_lock); \
135 dst->field##_lo = __hba->stats.field##_lo; \
136 dst->field##_hi = __hba->stats.field##_hi; \
137 spin_unlock_bh(&__hba->stat_lock); \
138 } while (0)
139
140#define ADD_STATS_64(__hba, field, len) \
141 do { \
142 if (spin_trylock(&__hba->stat_lock)) { \
143 if (__hba->stats.field##_lo + len < \
144 __hba->stats.field##_lo) \
145 __hba->stats.field##_hi++; \
146 __hba->stats.field##_lo += len; \
147 spin_unlock(&__hba->stat_lock); \
148 } \
149 } while (0)
150
151#else
152#define GET_STATS_64(__hba, dst, field) \
153 do { \
154 u64 val, *out; \
155 \
156 val = __hba->bnx2i_stats.field; \
157 out = (u64 *)&__hba->stats.field##_lo; \
158 *out = cpu_to_le64(val); \
159 out = (u64 *)&dst->field##_lo; \
160 *out = cpu_to_le64(val); \
161 } while (0)
162
163#define ADD_STATS_64(__hba, field, len) \
164 do { \
165 __hba->bnx2i_stats.field += len; \
166 } while (0)
167#endif
Michael Chancf4e6362009-06-08 18:14:44 -0700168
169/**
170 * struct generic_pdu_resc - login pdu resource structure
171 *
172 * @req_buf: driver buffer used to stage payload associated with
173 * the login request
174 * @req_dma_addr: dma address for iscsi login request payload buffer
175 * @req_buf_size: actual login request payload length
176 * @req_wr_ptr: pointer into login request buffer when next data is
177 * to be written
178 * @resp_hdr: iscsi header where iscsi login response header is to
179 * be recreated
180 * @resp_buf: buffer to stage login response payload
181 * @resp_dma_addr: login response payload buffer dma address
182 * @resp_buf_size: login response paylod length
183 * @resp_wr_ptr: pointer into login response buffer when next data is
184 * to be written
185 * @req_bd_tbl: iscsi login request payload BD table
186 * @req_bd_dma: login request BD table dma address
187 * @resp_bd_tbl: iscsi login response payload BD table
188 * @resp_bd_dma: login request BD table dma address
189 *
190 * following structure defines buffer info for generic pdus such as iSCSI Login,
191 * Logout and NOP
192 */
193struct generic_pdu_resc {
194 char *req_buf;
195 dma_addr_t req_dma_addr;
196 u32 req_buf_size;
197 char *req_wr_ptr;
198 struct iscsi_hdr resp_hdr;
199 char *resp_buf;
200 dma_addr_t resp_dma_addr;
201 u32 resp_buf_size;
202 char *resp_wr_ptr;
203 char *req_bd_tbl;
204 dma_addr_t req_bd_dma;
205 char *resp_bd_tbl;
206 dma_addr_t resp_bd_dma;
207};
208
209
210/**
211 * struct bd_resc_page - tracks DMA'able memory allocated for BD tables
212 *
213 * @link: list head to link elements
214 * @max_ptrs: maximun pointers that can be stored in this page
215 * @num_valid: number of pointer valid in this page
216 * @page: base addess for page pointer array
217 *
218 * structure to track DMA'able memory allocated for command BD tables
219 */
220struct bd_resc_page {
221 struct list_head link;
222 u32 max_ptrs;
223 u32 num_valid;
224 void *page[1];
225};
226
227
228/**
229 * struct io_bdt - I/O buffer destricptor table
230 *
231 * @bd_tbl: BD table's virtual address
232 * @bd_tbl_dma: BD table's dma address
233 * @bd_valid: num valid BD entries
234 *
235 * IO BD table
236 */
237struct io_bdt {
238 struct iscsi_bd *bd_tbl;
239 dma_addr_t bd_tbl_dma;
240 u16 bd_valid;
241};
242
243
244/**
245 * bnx2i_cmd - iscsi command structure
246 *
Eddie Waib5cf6b62011-06-23 15:51:34 -0700247 * @hdr: iSCSI header
248 * @conn: iscsi_conn pointer
Michael Chancf4e6362009-06-08 18:14:44 -0700249 * @scsi_cmd: SCSI-ML task pointer corresponding to this iscsi cmd
250 * @sg: SG list
251 * @io_tbl: buffer descriptor (BD) table
252 * @bd_tbl_dma: buffer descriptor (BD) table's dma address
Eddie Waib5cf6b62011-06-23 15:51:34 -0700253 * @req: bnx2i specific command request struct
Michael Chancf4e6362009-06-08 18:14:44 -0700254 */
255struct bnx2i_cmd {
256 struct iscsi_hdr hdr;
257 struct bnx2i_conn *conn;
258 struct scsi_cmnd *scsi_cmd;
259 struct scatterlist *sg;
260 struct io_bdt io_tbl;
261 dma_addr_t bd_tbl_dma;
262 struct bnx2i_cmd_request req;
263};
264
265
266/**
267 * struct bnx2i_conn - iscsi connection structure
268 *
269 * @cls_conn: pointer to iscsi cls conn
270 * @hba: adapter structure pointer
271 * @iscsi_conn_cid: iscsi conn id
272 * @fw_cid: firmware iscsi context id
273 * @ep: endpoint structure pointer
274 * @gen_pdu: login/nopout/logout pdu resources
275 * @violation_notified: bit mask used to track iscsi error/warning messages
276 * already printed out
Eddie Waib5cf6b62011-06-23 15:51:34 -0700277 * @work_cnt: keeps track of the number of outstanding work
Michael Chancf4e6362009-06-08 18:14:44 -0700278 *
279 * iSCSI connection structure
280 */
281struct bnx2i_conn {
282 struct iscsi_cls_conn *cls_conn;
283 struct bnx2i_hba *hba;
284 struct completion cmd_cleanup_cmpl;
Michael Chancf4e6362009-06-08 18:14:44 -0700285
286 u32 iscsi_conn_cid;
287#define BNX2I_CID_RESERVED 0x5AFF
288 u32 fw_cid;
289
290 struct timer_list poll_timer;
291 /*
292 * Queue Pair (QP) related structure elements.
293 */
294 struct bnx2i_endpoint *ep;
295
296 /*
297 * Buffer for login negotiation process
298 */
299 struct generic_pdu_resc gen_pdu;
300 u64 violation_notified;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700301
302 atomic_t work_cnt;
Michael Chancf4e6362009-06-08 18:14:44 -0700303};
304
305
306
307/**
308 * struct iscsi_cid_queue - Per adapter iscsi cid queue
309 *
310 * @cid_que_base: queue base memory
311 * @cid_que: queue memory pointer
312 * @cid_q_prod_idx: produce index
313 * @cid_q_cons_idx: consumer index
314 * @cid_q_max_idx: max index. used to detect wrap around condition
315 * @cid_free_cnt: queue size
316 * @conn_cid_tbl: iscsi cid to conn structure mapping table
317 *
318 * Per adapter iSCSI CID Queue
319 */
320struct iscsi_cid_queue {
321 void *cid_que_base;
322 u32 *cid_que;
323 u32 cid_q_prod_idx;
324 u32 cid_q_cons_idx;
325 u32 cid_q_max_idx;
326 u32 cid_free_cnt;
327 struct bnx2i_conn **conn_cid_tbl;
328};
329
Barak Witkowski2e499d32012-06-26 01:31:19 +0000330
331struct bnx2i_stats_info {
332 u64 rx_pdus;
333 u64 rx_bytes;
334 u64 tx_pdus;
335 u64 tx_bytes;
336};
337
338
Michael Chancf4e6362009-06-08 18:14:44 -0700339/**
340 * struct bnx2i_hba - bnx2i adapter structure
341 *
342 * @link: list head to link elements
343 * @cnic: pointer to cnic device
344 * @pcidev: pointer to pci dev
345 * @netdev: pointer to netdev structure
346 * @regview: mapped PCI register space
347 * @age: age, incremented by every recovery
348 * @cnic_dev_type: cnic device type, 5706/5708/5709/57710
349 * @mail_queue_access: mailbox queue access mode, applicable to 5709 only
350 * @reg_with_cnic: indicates whether the device is register with CNIC
351 * @adapter_state: adapter state, UP, GOING_DOWN, LINK_DOWN
352 * @mtu_supported: Ethernet MTU supported
353 * @shost: scsi host pointer
354 * @max_sqes: SQ size
355 * @max_rqes: RQ size
356 * @max_cqes: CQ size
357 * @num_ccell: number of command cells per connection
358 * @ofld_conns_active: active connection list
Eddie Wai55e15c972010-07-01 15:34:52 -0700359 * @eh_wait: wait queue for the endpoint to shutdown
Michael Chancf4e6362009-06-08 18:14:44 -0700360 * @max_active_conns: max offload connections supported by this device
361 * @cid_que: iscsi cid queue
362 * @ep_rdwr_lock: read / write lock to synchronize various ep lists
363 * @ep_ofld_list: connection list for pending offload completion
Eddie Wai46012e82010-07-01 15:34:51 -0700364 * @ep_active_list: connection list for active offload endpoints
Michael Chancf4e6362009-06-08 18:14:44 -0700365 * @ep_destroy_list: connection list for pending offload completion
366 * @mp_bd_tbl: BD table to be used with middle path requests
367 * @mp_bd_dma: DMA address of 'mp_bd_tbl' memory buffer
368 * @dummy_buffer: Dummy buffer to be used with zero length scsicmd reqs
369 * @dummy_buf_dma: DMA address of 'dummy_buffer' memory buffer
370 * @lock: lock to synchonize access to hba structure
Eddie Wai55e15c972010-07-01 15:34:52 -0700371 * @hba_shutdown_tmo: Timeout value to shutdown each connection
Eddie Waie37d2c42010-07-01 15:34:53 -0700372 * @conn_teardown_tmo: Timeout value to tear down each connection
373 * @conn_ctx_destroy_tmo: Timeout value to destroy context of each connection
Michael Chancf4e6362009-06-08 18:14:44 -0700374 * @pci_did: PCI device ID
375 * @pci_vid: PCI vendor ID
376 * @pci_sdid: PCI subsystem device ID
377 * @pci_svid: PCI subsystem vendor ID
378 * @pci_func: PCI function number in system pci tree
379 * @pci_devno: PCI device number in system pci tree
380 * @num_wqe_sent: statistic counter, total wqe's sent
381 * @num_cqe_rcvd: statistic counter, total cqe's received
382 * @num_intr_claimed: statistic counter, total interrupts claimed
383 * @link_changed_count: statistic counter, num of link change notifications
384 * received
385 * @ipaddr_changed_count: statistic counter, num times IP address changed while
386 * at least one connection is offloaded
387 * @num_sess_opened: statistic counter, total num sessions opened
388 * @num_conn_opened: statistic counter, total num conns opened on this hba
389 * @ctx_ccell_tasks: captures number of ccells and tasks supported by
390 * currently offloaded connection, used to decode
391 * context memory
Barak Witkowski2e499d32012-06-26 01:31:19 +0000392 * @stat_lock: spin lock used by the statistic collector (32 bit)
393 * @stats: local iSCSI statistic collection place holder
Michael Chancf4e6362009-06-08 18:14:44 -0700394 *
395 * Adapter Data Structure
396 */
397struct bnx2i_hba {
398 struct list_head link;
399 struct cnic_dev *cnic;
400 struct pci_dev *pcidev;
401 struct net_device *netdev;
402 void __iomem *regview;
403
404 u32 age;
405 unsigned long cnic_dev_type;
406 #define BNX2I_NX2_DEV_5706 0x0
407 #define BNX2I_NX2_DEV_5708 0x1
408 #define BNX2I_NX2_DEV_5709 0x2
409 #define BNX2I_NX2_DEV_57710 0x3
410 u32 mail_queue_access;
411 #define BNX2I_MQ_KERNEL_MODE 0x0
412 #define BNX2I_MQ_KERNEL_BYPASS_MODE 0x1
413 #define BNX2I_MQ_BIN_MODE 0x2
414 unsigned long reg_with_cnic;
415 #define BNX2I_CNIC_REGISTERED 1
416
417 unsigned long adapter_state;
418 #define ADAPTER_STATE_UP 0
419 #define ADAPTER_STATE_GOING_DOWN 1
420 #define ADAPTER_STATE_LINK_DOWN 2
421 #define ADAPTER_STATE_INIT_FAILED 31
422 unsigned int mtu_supported;
Eddie Wai45188352011-02-16 15:04:29 -0600423 #define BNX2I_MAX_MTU_SUPPORTED 9000
Michael Chancf4e6362009-06-08 18:14:44 -0700424
425 struct Scsi_Host *shost;
426
427 u32 max_sqes;
428 u32 max_rqes;
429 u32 max_cqes;
430 u32 num_ccell;
431
432 int ofld_conns_active;
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700433 wait_queue_head_t eh_wait;
Michael Chancf4e6362009-06-08 18:14:44 -0700434
435 int max_active_conns;
436 struct iscsi_cid_queue cid_que;
437
438 rwlock_t ep_rdwr_lock;
439 struct list_head ep_ofld_list;
Eddie Wai46012e82010-07-01 15:34:51 -0700440 struct list_head ep_active_list;
Michael Chancf4e6362009-06-08 18:14:44 -0700441 struct list_head ep_destroy_list;
442
443 /*
444 * BD table to be used with MP (Middle Path requests.
445 */
446 char *mp_bd_tbl;
447 dma_addr_t mp_bd_dma;
448 char *dummy_buffer;
449 dma_addr_t dummy_buf_dma;
450
451 spinlock_t lock; /* protects hba structure access */
452 struct mutex net_dev_lock;/* sync net device access */
453
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700454 int hba_shutdown_tmo;
Eddie Waie37d2c42010-07-01 15:34:53 -0700455 int conn_teardown_tmo;
456 int conn_ctx_destroy_tmo;
Michael Chancf4e6362009-06-08 18:14:44 -0700457 /*
458 * PCI related info.
459 */
460 u16 pci_did;
461 u16 pci_vid;
462 u16 pci_sdid;
463 u16 pci_svid;
464 u16 pci_func;
465 u16 pci_devno;
466
467 /*
468 * Following are a bunch of statistics useful during development
469 * and later stage for score boarding.
470 */
471 u32 num_wqe_sent;
472 u32 num_cqe_rcvd;
473 u32 num_intr_claimed;
474 u32 link_changed_count;
475 u32 ipaddr_changed_count;
476 u32 num_sess_opened;
477 u32 num_conn_opened;
478 unsigned int ctx_ccell_tasks;
Barak Witkowski2e499d32012-06-26 01:31:19 +0000479
480#ifdef CONFIG_32BIT
481 spinlock_t stat_lock;
482#endif
483 struct bnx2i_stats_info bnx2i_stats;
484 struct iscsi_stats_info stats;
Michael Chancf4e6362009-06-08 18:14:44 -0700485};
486
487
488/*******************************************************************************
489 * QP [ SQ / RQ / CQ ] info.
490 ******************************************************************************/
491
492/*
493 * SQ/RQ/CQ generic structure definition
494 */
495struct sqe {
496 u8 sqe_byte[BNX2I_SQ_WQE_SIZE];
497};
498
499struct rqe {
500 u8 rqe_byte[BNX2I_RQ_WQE_SIZE];
501};
502
503struct cqe {
504 u8 cqe_byte[BNX2I_CQE_SIZE];
505};
506
507
508enum {
509#if defined(__LITTLE_ENDIAN)
510 CNIC_EVENT_COAL_INDEX = 0x0,
511 CNIC_SEND_DOORBELL = 0x4,
512 CNIC_EVENT_CQ_ARM = 0x7,
513 CNIC_RECV_DOORBELL = 0x8
514#elif defined(__BIG_ENDIAN)
515 CNIC_EVENT_COAL_INDEX = 0x2,
516 CNIC_SEND_DOORBELL = 0x6,
517 CNIC_EVENT_CQ_ARM = 0x4,
518 CNIC_RECV_DOORBELL = 0xa
519#endif
520};
521
522
523/*
524 * CQ DB
525 */
526struct bnx2x_iscsi_cq_pend_cmpl {
527 /* CQ producer, updated by Ustorm */
528 u16 ustrom_prod;
529 /* CQ pending completion counter */
530 u16 pend_cntr;
531};
532
533
534struct bnx2i_5771x_cq_db {
535 struct bnx2x_iscsi_cq_pend_cmpl qp_pend_cmpl[BNX2X_MAX_CQS];
536 /* CQ pending completion ITT array */
537 u16 itt[BNX2X_MAX_CQS];
538 /* Cstorm CQ sequence to notify array, updated by driver */;
539 u16 sqn[BNX2X_MAX_CQS];
540 u32 reserved[4] /* 16 byte allignment */;
541};
542
543
544struct bnx2i_5771x_sq_rq_db {
545 u16 prod_idx;
Michael Chanf4b5ad22011-06-20 15:15:56 +0000546 u8 reserved0[62]; /* Pad structure size to 64 bytes */
Michael Chancf4e6362009-06-08 18:14:44 -0700547};
548
549
550struct bnx2i_5771x_dbell_hdr {
551 u8 header;
552 /* 1 for rx doorbell, 0 for tx doorbell */
553#define B577XX_DOORBELL_HDR_RX (0x1<<0)
554#define B577XX_DOORBELL_HDR_RX_SHIFT 0
555 /* 0 for normal doorbell, 1 for advertise wnd doorbell */
556#define B577XX_DOORBELL_HDR_DB_TYPE (0x1<<1)
557#define B577XX_DOORBELL_HDR_DB_TYPE_SHIFT 1
558 /* rdma tx only: DPM transaction size specifier (64/128/256/512B) */
559#define B577XX_DOORBELL_HDR_DPM_SIZE (0x3<<2)
560#define B577XX_DOORBELL_HDR_DPM_SIZE_SHIFT 2
561 /* connection type */
562#define B577XX_DOORBELL_HDR_CONN_TYPE (0xF<<4)
563#define B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT 4
564};
565
566struct bnx2i_5771x_dbell {
567 struct bnx2i_5771x_dbell_hdr dbell;
568 u8 pad[3];
569
570};
571
572/**
573 * struct qp_info - QP (share queue region) atrributes structure
574 *
575 * @ctx_base: ioremapped pci register base to access doorbell register
576 * pertaining to this offloaded connection
577 * @sq_virt: virtual address of send queue (SQ) region
578 * @sq_phys: DMA address of SQ memory region
579 * @sq_mem_size: SQ size
580 * @sq_prod_qe: SQ producer entry pointer
581 * @sq_cons_qe: SQ consumer entry pointer
582 * @sq_first_qe: virtaul address of first entry in SQ
583 * @sq_last_qe: virtaul address of last entry in SQ
584 * @sq_prod_idx: SQ producer index
585 * @sq_cons_idx: SQ consumer index
586 * @sqe_left: number sq entry left
587 * @sq_pgtbl_virt: page table describing buffer consituting SQ region
588 * @sq_pgtbl_phys: dma address of 'sq_pgtbl_virt'
589 * @sq_pgtbl_size: SQ page table size
590 * @cq_virt: virtual address of completion queue (CQ) region
591 * @cq_phys: DMA address of RQ memory region
592 * @cq_mem_size: CQ size
593 * @cq_prod_qe: CQ producer entry pointer
594 * @cq_cons_qe: CQ consumer entry pointer
595 * @cq_first_qe: virtaul address of first entry in CQ
596 * @cq_last_qe: virtaul address of last entry in CQ
597 * @cq_prod_idx: CQ producer index
598 * @cq_cons_idx: CQ consumer index
599 * @cqe_left: number cq entry left
600 * @cqe_size: size of each CQ entry
601 * @cqe_exp_seq_sn: next expected CQE sequence number
602 * @cq_pgtbl_virt: page table describing buffer consituting CQ region
603 * @cq_pgtbl_phys: dma address of 'cq_pgtbl_virt'
604 * @cq_pgtbl_size: CQ page table size
605 * @rq_virt: virtual address of receive queue (RQ) region
606 * @rq_phys: DMA address of RQ memory region
607 * @rq_mem_size: RQ size
608 * @rq_prod_qe: RQ producer entry pointer
609 * @rq_cons_qe: RQ consumer entry pointer
610 * @rq_first_qe: virtaul address of first entry in RQ
611 * @rq_last_qe: virtaul address of last entry in RQ
612 * @rq_prod_idx: RQ producer index
613 * @rq_cons_idx: RQ consumer index
614 * @rqe_left: number rq entry left
615 * @rq_pgtbl_virt: page table describing buffer consituting RQ region
616 * @rq_pgtbl_phys: dma address of 'rq_pgtbl_virt'
617 * @rq_pgtbl_size: RQ page table size
618 *
619 * queue pair (QP) is a per connection shared data structure which is used
620 * to send work requests (SQ), receive completion notifications (CQ)
621 * and receive asynchoronous / scsi sense info (RQ). 'qp_info' structure
622 * below holds queue memory, consumer/producer indexes and page table
623 * information
624 */
625struct qp_info {
626 void __iomem *ctx_base;
627#define DPM_TRIGER_TYPE 0x40
628
629#define BNX2I_570x_QUE_DB_SIZE 0
630#define BNX2I_5771x_QUE_DB_SIZE 16
631 struct sqe *sq_virt;
632 dma_addr_t sq_phys;
633 u32 sq_mem_size;
634
635 struct sqe *sq_prod_qe;
636 struct sqe *sq_cons_qe;
637 struct sqe *sq_first_qe;
638 struct sqe *sq_last_qe;
639 u16 sq_prod_idx;
640 u16 sq_cons_idx;
641 u32 sqe_left;
642
643 void *sq_pgtbl_virt;
644 dma_addr_t sq_pgtbl_phys;
645 u32 sq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
646
647 struct cqe *cq_virt;
648 dma_addr_t cq_phys;
649 u32 cq_mem_size;
650
651 struct cqe *cq_prod_qe;
652 struct cqe *cq_cons_qe;
653 struct cqe *cq_first_qe;
654 struct cqe *cq_last_qe;
655 u16 cq_prod_idx;
656 u16 cq_cons_idx;
657 u32 cqe_left;
658 u32 cqe_size;
659 u32 cqe_exp_seq_sn;
660
661 void *cq_pgtbl_virt;
662 dma_addr_t cq_pgtbl_phys;
663 u32 cq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
664
665 struct rqe *rq_virt;
666 dma_addr_t rq_phys;
667 u32 rq_mem_size;
668
669 struct rqe *rq_prod_qe;
670 struct rqe *rq_cons_qe;
671 struct rqe *rq_first_qe;
672 struct rqe *rq_last_qe;
673 u16 rq_prod_idx;
674 u16 rq_cons_idx;
675 u32 rqe_left;
676
677 void *rq_pgtbl_virt;
678 dma_addr_t rq_pgtbl_phys;
679 u32 rq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
680};
681
682
683
684/*
685 * CID handles
686 */
687struct ep_handles {
688 u32 fw_cid;
689 u32 drv_iscsi_cid;
690 u16 pg_cid;
691 u16 rsvd;
692};
693
694
695enum {
696 EP_STATE_IDLE = 0x0,
697 EP_STATE_PG_OFLD_START = 0x1,
698 EP_STATE_PG_OFLD_COMPL = 0x2,
699 EP_STATE_OFLD_START = 0x4,
700 EP_STATE_OFLD_COMPL = 0x8,
701 EP_STATE_CONNECT_START = 0x10,
702 EP_STATE_CONNECT_COMPL = 0x20,
703 EP_STATE_ULP_UPDATE_START = 0x40,
704 EP_STATE_ULP_UPDATE_COMPL = 0x80,
705 EP_STATE_DISCONN_START = 0x100,
706 EP_STATE_DISCONN_COMPL = 0x200,
707 EP_STATE_CLEANUP_START = 0x400,
708 EP_STATE_CLEANUP_CMPL = 0x800,
709 EP_STATE_TCP_FIN_RCVD = 0x1000,
710 EP_STATE_TCP_RST_RCVD = 0x2000,
Eddie Wai2eefb202010-07-01 15:34:54 -0700711 EP_STATE_LOGOUT_SENT = 0x4000,
712 EP_STATE_LOGOUT_RESP_RCVD = 0x8000,
Michael Chancf4e6362009-06-08 18:14:44 -0700713 EP_STATE_PG_OFLD_FAILED = 0x1000000,
714 EP_STATE_ULP_UPDATE_FAILED = 0x2000000,
715 EP_STATE_CLEANUP_FAILED = 0x4000000,
716 EP_STATE_OFLD_FAILED = 0x8000000,
717 EP_STATE_CONNECT_FAILED = 0x10000000,
718 EP_STATE_DISCONN_TIMEDOUT = 0x20000000,
Eddie Waibee34872010-11-23 15:29:29 -0800719 EP_STATE_OFLD_FAILED_CID_BUSY = 0x80000000,
Michael Chancf4e6362009-06-08 18:14:44 -0700720};
721
722/**
723 * struct bnx2i_endpoint - representation of tcp connection in NX2 world
724 *
725 * @link: list head to link elements
726 * @hba: adapter to which this connection belongs
727 * @conn: iscsi connection this EP is linked to
Eddie Wai46012e82010-07-01 15:34:51 -0700728 * @cls_ep: associated iSCSI endpoint pointer
Michael Chancf4e6362009-06-08 18:14:44 -0700729 * @cm_sk: cnic sock struct
730 * @hba_age: age to detect if 'iscsid' issues ep_disconnect()
731 * after HBA reset is completed by bnx2i/cnic/bnx2
732 * modules
733 * @state: tracks offload connection state machine
Eddie Wai9ae58e12011-05-16 11:13:20 -0700734 * @timestamp: tracks the start time when the ep begins to connect
735 * @num_active_cmds: tracks the number of outstanding commands for this ep
736 * @ec_shift: the amount of shift as part of the event coal calc
Michael Chancf4e6362009-06-08 18:14:44 -0700737 * @qp: QP information
738 * @ids: contains chip allocated *context id* & driver assigned
739 * *iscsi cid*
740 * @ofld_timer: offload timer to detect timeout
741 * @ofld_wait: wait queue
742 *
743 * Endpoint Structure - equivalent of tcp socket structure
744 */
745struct bnx2i_endpoint {
746 struct list_head link;
747 struct bnx2i_hba *hba;
748 struct bnx2i_conn *conn;
Eddie Wai46012e82010-07-01 15:34:51 -0700749 struct iscsi_endpoint *cls_ep;
Michael Chancf4e6362009-06-08 18:14:44 -0700750 struct cnic_sock *cm_sk;
751 u32 hba_age;
752 u32 state;
753 unsigned long timestamp;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700754 atomic_t num_active_cmds;
Eddie Wai9ae58e12011-05-16 11:13:20 -0700755 u32 ec_shift;
Michael Chancf4e6362009-06-08 18:14:44 -0700756
757 struct qp_info qp;
758 struct ep_handles ids;
759 #define ep_iscsi_cid ids.drv_iscsi_cid
760 #define ep_cid ids.fw_cid
761 #define ep_pg_cid ids.pg_cid
762 struct timer_list ofld_timer;
763 wait_queue_head_t ofld_wait;
764};
765
766
Eddie Waib5cf6b62011-06-23 15:51:34 -0700767struct bnx2i_work {
768 struct list_head list;
769 struct iscsi_session *session;
770 struct bnx2i_conn *bnx2i_conn;
771 struct cqe cqe;
772};
773
774struct bnx2i_percpu_s {
775 struct task_struct *iothread;
776 struct list_head work_list;
777 spinlock_t p_work_lock;
778};
779
Michael Chancf4e6362009-06-08 18:14:44 -0700780
781/* Global variables */
782extern unsigned int error_mask1, error_mask2;
783extern u64 iscsi_error_mask;
784extern unsigned int en_tcp_dack;
785extern unsigned int event_coal_div;
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800786extern unsigned int event_coal_min;
Michael Chancf4e6362009-06-08 18:14:44 -0700787
788extern struct scsi_transport_template *bnx2i_scsi_xport_template;
789extern struct iscsi_transport bnx2i_iscsi_transport;
790extern struct cnic_ulp_ops bnx2i_cnic_cb;
791
792extern unsigned int sq_size;
793extern unsigned int rq_size;
794
795extern struct device_attribute *bnx2i_dev_attributes[];
796
797
798
799/*
800 * Function Prototypes
801 */
802extern void bnx2i_identify_device(struct bnx2i_hba *hba);
Michael Chancf4e6362009-06-08 18:14:44 -0700803
804extern void bnx2i_ulp_init(struct cnic_dev *dev);
805extern void bnx2i_ulp_exit(struct cnic_dev *dev);
806extern void bnx2i_start(void *handle);
807extern void bnx2i_stop(void *handle);
Barak Witkowski2e499d32012-06-26 01:31:19 +0000808extern int bnx2i_get_stats(void *handle);
809
Michael Chancf4e6362009-06-08 18:14:44 -0700810extern struct bnx2i_hba *get_adapter_list_head(void);
811
812struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
813 u16 iscsi_cid);
814
815int bnx2i_alloc_ep_pool(void);
816void bnx2i_release_ep_pool(void);
817struct bnx2i_endpoint *bnx2i_ep_ofld_list_next(struct bnx2i_hba *hba);
818struct bnx2i_endpoint *bnx2i_ep_destroy_list_next(struct bnx2i_hba *hba);
819
820struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic);
821
822struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic);
823void bnx2i_free_hba(struct bnx2i_hba *hba);
824
825void bnx2i_get_rq_buf(struct bnx2i_conn *conn, char *ptr, int len);
826void bnx2i_put_rq_buf(struct bnx2i_conn *conn, int count);
827
828void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd);
829
830void bnx2i_drop_session(struct iscsi_cls_session *session);
831
832extern int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba);
833extern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn,
834 struct iscsi_task *mtask);
835extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn,
836 struct iscsi_task *mtask);
Eddie Wai09813ba2011-02-16 15:04:30 -0600837extern int bnx2i_send_iscsi_text(struct bnx2i_conn *conn,
838 struct iscsi_task *mtask);
Michael Chancf4e6362009-06-08 18:14:44 -0700839extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn,
840 struct bnx2i_cmd *cmnd);
841extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn,
Eddie Wai39304072010-08-12 16:44:27 -0700842 struct iscsi_task *mtask,
Michael Chancf4e6362009-06-08 18:14:44 -0700843 char *datap, int data_len, int unsol);
844extern int bnx2i_send_iscsi_logout(struct bnx2i_conn *conn,
845 struct iscsi_task *mtask);
846extern void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba,
847 struct bnx2i_cmd *cmd);
Eddie Waibee34872010-11-23 15:29:29 -0800848extern int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba,
Michael Chancf4e6362009-06-08 18:14:44 -0700849 struct bnx2i_endpoint *ep);
Eddie Waibee34872010-11-23 15:29:29 -0800850extern void bnx2i_update_iscsi_conn(struct iscsi_conn *conn);
851extern int bnx2i_send_conn_destroy(struct bnx2i_hba *hba,
852 struct bnx2i_endpoint *ep);
Michael Chancf4e6362009-06-08 18:14:44 -0700853
854extern int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
855 struct bnx2i_endpoint *ep);
856extern void bnx2i_free_qp_resc(struct bnx2i_hba *hba,
857 struct bnx2i_endpoint *ep);
858extern void bnx2i_ep_ofld_timer(unsigned long data);
859extern struct bnx2i_endpoint *bnx2i_find_ep_in_ofld_list(
860 struct bnx2i_hba *hba, u32 iscsi_cid);
861extern struct bnx2i_endpoint *bnx2i_find_ep_in_destroy_list(
862 struct bnx2i_hba *hba, u32 iscsi_cid);
863
864extern int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep);
Eddie Waib5cf6b62011-06-23 15:51:34 -0700865extern int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action);
Michael Chancf4e6362009-06-08 18:14:44 -0700866
Eddie Wai55e15c972010-07-01 15:34:52 -0700867extern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep);
868
Michael Chancf4e6362009-06-08 18:14:44 -0700869/* Debug related function prototypes */
870extern void bnx2i_print_pend_cmd_queue(struct bnx2i_conn *conn);
871extern void bnx2i_print_active_cmd_queue(struct bnx2i_conn *conn);
872extern void bnx2i_print_xmit_pdu_queue(struct bnx2i_conn *conn);
873extern void bnx2i_print_recv_state(struct bnx2i_conn *conn);
874
Eddie Waib5cf6b62011-06-23 15:51:34 -0700875extern int bnx2i_percpu_io_thread(void *arg);
876extern int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
877 struct bnx2i_conn *bnx2i_conn,
878 struct cqe *cqe);
Michael Chancf4e6362009-06-08 18:14:44 -0700879#endif