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