summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/bnx2i/bnx2i.h
blob: 663a63d4dae4dca425f39639d38308eb90e37f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
/* bnx2i.h: QLogic NetXtreme II iSCSI driver.
 *
 * Copyright (c) 2006 - 2013 Broadcom Corporation
 * Copyright (c) 2007, 2008 Red Hat, Inc.  All rights reserved.
 * Copyright (c) 2007, 2008 Mike Christie
 * Copyright (c) 2014, QLogic Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
 * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
 * Maintained by: QLogic-Storage-Upstream@qlogic.com
 */

#ifndef _BNX2I_H_
#define _BNX2I_H_

#include <linux/module.h>
#include <linux/moduleparam.h>

#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/sched/signal.h>
#include <linux/in.h>
#include <linux/kfifo.h>
#include <linux/netdevice.h>
#include <linux/completion.h>
#include <linux/kthread.h>
#include <linux/cpu.h>

#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi.h>
#include <scsi/iscsi_proto.h>
#include <scsi/libiscsi.h>
#include <scsi/scsi_transport_iscsi.h>

#include "../../net/ethernet/broadcom/cnic_if.h"
#include "57xx_iscsi_hsi.h"
#include "57xx_iscsi_constants.h"

#include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h"

#define BNX2_ISCSI_DRIVER_NAME		"bnx2i"

#define BNX2I_MAX_ADAPTERS		8

#define ISCSI_MAX_CONNS_PER_HBA		128
#define ISCSI_MAX_SESS_PER_HBA		ISCSI_MAX_CONNS_PER_HBA
#define ISCSI_MAX_CMDS_PER_SESS		128

/* Total active commands across all connections supported by devices */
#define ISCSI_MAX_CMDS_PER_HBA_5708	(28 * (ISCSI_MAX_CMDS_PER_SESS - 1))
#define ISCSI_MAX_CMDS_PER_HBA_5709	(128 * (ISCSI_MAX_CMDS_PER_SESS - 1))
#define ISCSI_MAX_CMDS_PER_HBA_57710	(256 * (ISCSI_MAX_CMDS_PER_SESS - 1))

#define ISCSI_MAX_BDS_PER_CMD		32

#define MAX_PAGES_PER_CTRL_STRUCT_POOL	8
#define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS	4

#define BNX2X_DB_SHIFT			3

/* 5706/08 hardware has limit on maximum buffer size per BD it can handle */
#define MAX_BD_LENGTH			65535
#define BD_SPLIT_SIZE			32768

/* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */
#define BNX2I_SQ_WQES_MIN		16
#define BNX2I_570X_SQ_WQES_MAX		128
#define BNX2I_5770X_SQ_WQES_MAX		512
#define BNX2I_570X_SQ_WQES_DEFAULT	128
#define BNX2I_5770X_SQ_WQES_DEFAULT	128

#define BNX2I_570X_CQ_WQES_MAX 		128
#define BNX2I_5770X_CQ_WQES_MAX 	512

#define BNX2I_RQ_WQES_MIN 		16
#define BNX2I_RQ_WQES_MAX 		32
#define BNX2I_RQ_WQES_DEFAULT 		16

/* CCELLs per conn */
#define BNX2I_CCELLS_MIN		16
#define BNX2I_CCELLS_MAX		96
#define BNX2I_CCELLS_DEFAULT		64

#define ITT_INVALID_SIGNATURE		0xFFFF

#define ISCSI_CMD_CLEANUP_TIMEOUT	100

#define BNX2I_CONN_CTX_BUF_SIZE		16384

#define BNX2I_SQ_WQE_SIZE		64
#define BNX2I_RQ_WQE_SIZE		256
#define BNX2I_CQE_SIZE			64

#define MB_KERNEL_CTX_SHIFT		8
#define MB_KERNEL_CTX_SIZE		(1 << MB_KERNEL_CTX_SHIFT)

#define CTX_SHIFT			7
#define GET_CID_NUM(cid_addr)		((cid_addr) >> CTX_SHIFT)

#define CTX_OFFSET 			0x10000
#define MAX_CID_CNT			0x4000

#define BNX2I_570X_PAGE_SIZE_DEFAULT	4096

/* 5709 context registers */
#define BNX2_MQ_CONFIG2			0x00003d00
#define BNX2_MQ_CONFIG2_CONT_SZ		(0x7L<<4)
#define BNX2_MQ_CONFIG2_FIRST_L4L5	(0x1fL<<8)

/* 57710's BAR2 is mapped to doorbell registers */
#define BNX2X_DOORBELL_PCI_BAR		2
#define BNX2X_MAX_CQS			8

#define CNIC_ARM_CQE			1
#define CNIC_ARM_CQE_FP			2
#define CNIC_DISARM_CQE			0

#define REG_RD(__hba, offset)				\
		readl(__hba->regview + offset)
#define REG_WR(__hba, offset, val)			\
		writel(val, __hba->regview + offset)

#ifdef CONFIG_32BIT
#define GET_STATS_64(__hba, dst, field)				\
	do {							\
		spin_lock_bh(&__hba->stat_lock);		\
		dst->field##_lo = __hba->stats.field##_lo;	\
		dst->field##_hi = __hba->stats.field##_hi;	\
		spin_unlock_bh(&__hba->stat_lock);		\
	} while (0)

#define ADD_STATS_64(__hba, field, len)				\
	do {							\
		if (spin_trylock(&__hba->stat_lock)) {		\
			if (__hba->stats.field##_lo + len <	\
			    __hba->stats.field##_lo)		\
				__hba->stats.field##_hi++;	\
			__hba->stats.field##_lo += len;		\
			spin_unlock(&__hba->stat_lock);		\
		}						\
	} while (0)

#else
#define GET_STATS_64(__hba, dst, field)				\
	do {							\
		u64 val, *out;					\
								\
		val = __hba->bnx2i_stats.field;			\
		out = (u64 *)&__hba->stats.field##_lo;		\
		*out = cpu_to_le64(val);			\
		out = (u64 *)&dst->field##_lo;			\
		*out = cpu_to_le64(val);			\
	} while (0)

#define ADD_STATS_64(__hba, field, len)				\
	do {							\
		__hba->bnx2i_stats.field += len;		\
	} while (0)
#endif

/**
 * struct generic_pdu_resc - login pdu resource structure
 *
 * @req_buf:            driver buffer used to stage payload associated with
 *                      the login request
 * @req_dma_addr:       dma address for iscsi login request payload buffer
 * @req_buf_size:       actual login request payload length
 * @req_wr_ptr:         pointer into login request buffer when next data is
 *                      to be written
 * @resp_hdr:           iscsi header where iscsi login response header is to
 *                      be recreated
 * @resp_buf:           buffer to stage login response payload
 * @resp_dma_addr:      login response payload buffer dma address
 * @resp_buf_size:      login response paylod length
 * @resp_wr_ptr:        pointer into login response buffer when next data is
 *                      to be written
 * @req_bd_tbl:         iscsi login request payload BD table
 * @req_bd_dma:         login request BD table dma address
 * @resp_bd_tbl:        iscsi login response payload BD table
 * @resp_bd_dma:        login request BD table dma address
 *
 * following structure defines buffer info for generic pdus such as iSCSI Login,
 *	Logout and NOP
 */
struct generic_pdu_resc {
	char *req_buf;
	dma_addr_t req_dma_addr;
	u32 req_buf_size;
	char *req_wr_ptr;
	struct iscsi_hdr resp_hdr;
	char *resp_buf;
	dma_addr_t resp_dma_addr;
	u32 resp_buf_size;
	char *resp_wr_ptr;
	char *req_bd_tbl;
	dma_addr_t req_bd_dma;
	char *resp_bd_tbl;
	dma_addr_t resp_bd_dma;
};


/**
 * struct bd_resc_page - tracks DMA'able memory allocated for BD tables
 *
 * @link:               list head to link elements
 * @max_ptrs:           maximun pointers that can be stored in this page
 * @num_valid:          number of pointer valid in this page
 * @page:               base addess for page pointer array
 *
 * structure to track DMA'able memory allocated for command BD tables
 */
struct bd_resc_page {
	struct list_head link;
	u32 max_ptrs;
	u32 num_valid;
	void *page[1];
};


/**
 * struct io_bdt - I/O buffer destricptor table
 *
 * @bd_tbl:             BD table's virtual address
 * @bd_tbl_dma:         BD table's dma address
 * @bd_valid:           num valid BD entries
 *
 * IO BD table
 */
struct io_bdt {
	struct iscsi_bd *bd_tbl;
	dma_addr_t bd_tbl_dma;
	u16 bd_valid;
};


/**
 * bnx2i_cmd - iscsi command structure
 *
 * @hdr:                iSCSI header
 * @conn:               iscsi_conn pointer
 * @scsi_cmd:           SCSI-ML task pointer corresponding to this iscsi cmd
 * @sg:                 SG list
 * @io_tbl:             buffer descriptor (BD) table
 * @bd_tbl_dma:         buffer descriptor (BD) table's dma address
 * @req:                bnx2i specific command request struct
 */
struct bnx2i_cmd {
	struct iscsi_hdr hdr;
	struct bnx2i_conn *conn;
	struct scsi_cmnd *scsi_cmd;
	struct scatterlist *sg;
	struct io_bdt io_tbl;
	dma_addr_t bd_tbl_dma;
	struct bnx2i_cmd_request req;
};


/**
 * struct bnx2i_conn - iscsi connection structure
 *
 * @cls_conn:              pointer to iscsi cls conn
 * @hba:                   adapter structure pointer
 * @iscsi_conn_cid:        iscsi conn id
 * @fw_cid:                firmware iscsi context id
 * @ep:                    endpoint structure pointer
 * @gen_pdu:               login/nopout/logout pdu resources
 * @violation_notified:    bit mask used to track iscsi error/warning messages
 *                         already printed out
 * @work_cnt:              keeps track of the number of outstanding work
 *
 * iSCSI connection structure
 */
struct bnx2i_conn {
	struct iscsi_cls_conn *cls_conn;
	struct bnx2i_hba *hba;
	struct completion cmd_cleanup_cmpl;

	u32 iscsi_conn_cid;
#define BNX2I_CID_RESERVED	0x5AFF
	u32 fw_cid;

	struct timer_list poll_timer;
	/*
	 * Queue Pair (QP) related structure elements.
	 */
	struct bnx2i_endpoint *ep;

	/*
	 * Buffer for login negotiation process
	 */
	struct generic_pdu_resc gen_pdu;
	u64 violation_notified;

	atomic_t work_cnt;
};



/**
 * struct iscsi_cid_queue - Per adapter iscsi cid queue
 *
 * @cid_que_base:           queue base memory
 * @cid_que:                queue memory pointer
 * @cid_q_prod_idx:         produce index
 * @cid_q_cons_idx:         consumer index
 * @cid_q_max_idx:          max index. used to detect wrap around condition
 * @cid_free_cnt:           queue size
 * @conn_cid_tbl:           iscsi cid to conn structure mapping table
 *
 * Per adapter iSCSI CID Queue
 */
struct iscsi_cid_queue {
	void *cid_que_base;
	u32 *cid_que;
	u32 cid_q_prod_idx;
	u32 cid_q_cons_idx;
	u32 cid_q_max_idx;
	u32 cid_free_cnt;
	struct bnx2i_conn **conn_cid_tbl;
};


struct bnx2i_stats_info {
	u64 rx_pdus;
	u64 rx_bytes;
	u64 tx_pdus;
	u64 tx_bytes;
};


/**
 * struct bnx2i_hba - bnx2i adapter structure
 *
 * @link:                  list head to link elements
 * @cnic:                  pointer to cnic device
 * @pcidev:                pointer to pci dev
 * @netdev:                pointer to netdev structure
 * @regview:               mapped PCI register space
 * @age:                   age, incremented by every recovery
 * @cnic_dev_type:         cnic device type, 5706/5708/5709/57710
 * @mail_queue_access:     mailbox queue access mode, applicable to 5709 only
 * @reg_with_cnic:         indicates whether the device is register with CNIC
 * @adapter_state:         adapter state, UP, GOING_DOWN, LINK_DOWN
 * @mtu_supported:         Ethernet MTU supported
 * @shost:                 scsi host pointer
 * @max_sqes:              SQ size
 * @max_rqes:              RQ size
 * @max_cqes:              CQ size
 * @num_ccell:             number of command cells per connection
 * @ofld_conns_active:     active connection list
 * @eh_wait:               wait queue for the endpoint to shutdown
 * @max_active_conns:      max offload connections supported by this device
 * @cid_que:               iscsi cid queue
 * @ep_rdwr_lock:          read / write lock to synchronize various ep lists
 * @ep_ofld_list:          connection list for pending offload completion
 * @ep_active_list:        connection list for active offload endpoints
 * @ep_destroy_list:       connection list for pending offload completion
 * @mp_bd_tbl:             BD table to be used with middle path requests
 * @mp_bd_dma:             DMA address of 'mp_bd_tbl' memory buffer
 * @dummy_buffer:          Dummy buffer to be used with zero length scsicmd reqs
 * @dummy_buf_dma:         DMA address of 'dummy_buffer' memory buffer
 * @lock:              	   lock to synchonize access to hba structure
 * @hba_shutdown_tmo:      Timeout value to shutdown each connection
 * @conn_teardown_tmo:     Timeout value to tear down each connection
 * @conn_ctx_destroy_tm