blob: 3fa1e819f42d1765f0126d58443b7aee7763e7c6 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal533c1652013-04-05 20:38:34 -07002 * Copyright (C) 2005 - 2013 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
19
20#ifndef _BEISCSI_MAIN_
21#define _BEISCSI_MAIN_
22
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023#include <linux/kernel.h>
24#include <linux/pci.h>
Randy Dunlap82c57022010-05-04 10:29:52 -070025#include <linux/if_ether.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053026#include <linux/in.h>
John Soni Jose99bc5d52012-08-20 23:00:18 +053027#include <linux/ctype.h>
28#include <linux/module.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053029#include <scsi/scsi.h>
30#include <scsi/scsi_cmnd.h>
31#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/iscsi_proto.h>
34#include <scsi/libiscsi.h>
35#include <scsi/scsi_transport_iscsi.h>
36
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053037#define DRV_NAME "be2iscsi"
Jayamohan Kallickal96e58ce2013-04-05 20:38:38 -070038#define BUILD_STR "10.0.467.0"
Jayamohan Kallickal2f635882012-04-03 23:41:45 -050039#define BE_NAME "Emulex OneConnect" \
40 "Open-iSCSI Driver version" BUILD_STR
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053041#define DRV_DESC BE_NAME " " "Driver"
42
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +053043#define BE_VENDOR_ID 0x19A2
John Soni Jose139a1b12012-10-20 04:43:20 +053044#define ELX_VENDOR_ID 0x10DF
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +053045/* DEVICE ID's for BE2 */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053046#define BE_DEVICE_ID1 0x212
47#define OC_DEVICE_ID1 0x702
48#define OC_DEVICE_ID2 0x703
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +053049
50/* DEVICE ID's for BE3 */
51#define BE_DEVICE_ID2 0x222
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053052#define OC_DEVICE_ID3 0x712
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053053
John Soni Jose139a1b12012-10-20 04:43:20 +053054/* DEVICE ID for SKH */
55#define OC_SKH_ID1 0x722
56
Jayamohan Kallickal7da50872010-01-05 05:04:12 +053057#define BE2_IO_DEPTH 1024
58#define BE2_MAX_SESSIONS 256
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053059#define BE2_CMDS_PER_CXN 128
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053060#define BE2_TMFS 16
61#define BE2_NOPOUT_REQ 16
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053062#define BE2_SGE 32
63#define BE2_DEFPDU_HDR_SZ 64
64#define BE2_DEFPDU_DATA_SZ 8192
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053065
John Soni Jose22abeef2012-10-20 04:43:32 +053066#define MAX_CPUS 64
67#define BEISCSI_MAX_NUM_CPUS 7
Jayamohan Kallickalbf9131c2013-04-05 20:38:24 -070068#define OC_SKH_MAX_NUM_CPUS 31
John Soni Jose22abeef2012-10-20 04:43:32 +053069
Jayamohan Kallickal22661e22013-04-05 20:38:28 -070070#define BEISCSI_VER_STRLEN 32
John Soni Jose22abeef2012-10-20 04:43:32 +053071
Jayamohan Kallickalaa359032010-01-07 01:51:04 +053072#define BEISCSI_SGLIST_ELEMENTS 30
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053073
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053074#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
Jayamohan Kallickale919dee2010-07-22 04:30:32 +053075#define BEISCSI_MAX_SECTORS 2048 /* scsi_host->max_sectors */
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -070076#define BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE 128 /* Template size per cxn */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053077
78#define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */
79#define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */
80#define BEISCSI_NUM_DEVICES_SUPPORTED 0x01
81#define BEISCSI_MAX_FRAGS_INIT 192
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +053082#define BE_NUM_MSIX_ENTRIES 1
Jayamohan Kallickale9b91192010-07-22 04:24:53 +053083
84#define MPU_EP_CONTROL 0
85#define MPU_EP_SEMAPHORE 0xac
86#define BE2_SOFT_RESET 0x5c
87#define BE2_PCI_ONLINE0 0xb0
88#define BE2_PCI_ONLINE1 0xb4
89#define BE2_SET_RESET 0x80
90#define BE2_MPU_IRAM_ONLINE 0x00000080
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053091
92#define BE_SENSE_INFO_SIZE 258
93#define BE_ISCSI_PDU_HEADER_SIZE 64
94#define BE_MIN_MEM_SIZE 16384
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053095#define MAX_CMD_SZ 65536
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053096#define IIOC_SCSI_DATA 0x05 /* Write Operation */
97
John Soni Jose9aef4202012-08-20 23:00:08 +053098#define INVALID_SESS_HANDLE 0xFFFFFFFF
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053099
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530100#define BE_ADAPTER_UP 0x00000000
101#define BE_ADAPTER_LINK_DOWN 0x00000001
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530102/**
103 * hardware needs the async PDU buffers to be posted in multiples of 8
104 * So have atleast 8 of them by default
105 */
106
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700107#define HWI_GET_ASYNC_PDU_CTX(phwi, ulp_num) \
108 (phwi->phwi_ctxt->pasync_ctx[ulp_num])
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530109
110/********* Memory BAR register ************/
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530111#define PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET 0xfc
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530112/**
113 * Host Interrupt Enable, if set interrupts are enabled although "PCI Interrupt
114 * Disable" may still globally block interrupts in addition to individual
115 * interrupt masks; a mechanism for the device driver to block all interrupts
116 * atomically without having to arbitrate for the PCI Interrupt Disable bit
117 * with the OS.
118 */
119#define MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK (1 << 29) /* bit 29 */
120
121/********* ISR0 Register offset **********/
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530122#define CEV_ISR0_OFFSET 0xC18
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530123#define CEV_ISR_SIZE 4
124
125/**
126 * Macros for reading/writing a protection domain or CSR registers
127 * in BladeEngine.
128 */
129
130#define DB_TXULP0_OFFSET 0x40
131#define DB_RXULP0_OFFSET 0xA0
132/********* Event Q door bell *************/
133#define DB_EQ_OFFSET DB_CQ_OFFSET
134#define DB_EQ_RING_ID_MASK 0x1FF /* bits 0 - 8 */
135/* Clear the interrupt for this eq */
136#define DB_EQ_CLR_SHIFT (9) /* bit 9 */
137/* Must be 1 */
138#define DB_EQ_EVNT_SHIFT (10) /* bit 10 */
139/* Number of event entries processed */
140#define DB_EQ_NUM_POPPED_SHIFT (16) /* bits 16 - 28 */
141/* Rearm bit */
142#define DB_EQ_REARM_SHIFT (29) /* bit 29 */
143
144/********* Compl Q door bell *************/
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530145#define DB_CQ_OFFSET 0x120
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530146#define DB_CQ_RING_ID_MASK 0x3FF /* bits 0 - 9 */
147/* Number of event entries processed */
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530148#define DB_CQ_NUM_POPPED_SHIFT (16) /* bits 16 - 28 */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530149/* Rearm bit */
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530150#define DB_CQ_REARM_SHIFT (29) /* bit 29 */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530151
152#define GET_HWI_CONTROLLER_WS(pc) (pc->phwi_ctrlr)
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700153#define HWI_GET_DEF_BUFQ_ID(pc, ulp_num) (((struct hwi_controller *)\
154 (GET_HWI_CONTROLLER_WS(pc)))->default_pdu_data[ulp_num].id)
155#define HWI_GET_DEF_HDRQ_ID(pc, ulp_num) (((struct hwi_controller *)\
156 (GET_HWI_CONTROLLER_WS(pc)))->default_pdu_hdr[ulp_num].id)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530157
158#define PAGES_REQUIRED(x) \
159 ((x < PAGE_SIZE) ? 1 : ((x + PAGE_SIZE - 1) / PAGE_SIZE))
160
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700161#define BEISCSI_MSI_NAME 20 /* size of msi_name string */
162
Jayamohan Kallickala129d922013-09-28 15:35:46 -0700163#define MEM_DESCR_OFFSET 8
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700164#define BEISCSI_DEFQ_HDR 1
165#define BEISCSI_DEFQ_DATA 0
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530166enum be_mem_enum {
167 HWI_MEM_ADDN_CONTEXT,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530168 HWI_MEM_WRB,
169 HWI_MEM_WRBH,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530170 HWI_MEM_SGLH,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530171 HWI_MEM_SGE,
Jayamohan Kallickala129d922013-09-28 15:35:46 -0700172 HWI_MEM_TEMPLATE_HDR_ULP0,
173 HWI_MEM_ASYNC_HEADER_BUF_ULP0, /* 6 */
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700174 HWI_MEM_ASYNC_DATA_BUF_ULP0,
175 HWI_MEM_ASYNC_HEADER_RING_ULP0,
176 HWI_MEM_ASYNC_DATA_RING_ULP0,
177 HWI_MEM_ASYNC_HEADER_HANDLE_ULP0,
Jayamohan Kallickala129d922013-09-28 15:35:46 -0700178 HWI_MEM_ASYNC_DATA_HANDLE_ULP0, /* 11 */
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700179 HWI_MEM_ASYNC_PDU_CONTEXT_ULP0,
Jayamohan Kallickala129d922013-09-28 15:35:46 -0700180 HWI_MEM_TEMPLATE_HDR_ULP1,
181 HWI_MEM_ASYNC_HEADER_BUF_ULP1, /* 14 */
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700182 HWI_MEM_ASYNC_DATA_BUF_ULP1,
183 HWI_MEM_ASYNC_HEADER_RING_ULP1,
184 HWI_MEM_ASYNC_DATA_RING_ULP1,
185 HWI_MEM_ASYNC_HEADER_HANDLE_ULP1,
Jayamohan Kallickala129d922013-09-28 15:35:46 -0700186 HWI_MEM_ASYNC_DATA_HANDLE_ULP1, /* 19 */
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700187 HWI_MEM_ASYNC_PDU_CONTEXT_ULP1,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530188 ISCSI_MEM_GLOBAL_HEADER,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530189 SE_MEM_MAX
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530190};
191
192struct be_bus_address32 {
193 unsigned int address_lo;
194 unsigned int address_hi;
195};
196
197struct be_bus_address64 {
198 unsigned long long address;
199};
200
201struct be_bus_address {
202 union {
203 struct be_bus_address32 a32;
204 struct be_bus_address64 a64;
205 } u;
206};
207
208struct mem_array {
209 struct be_bus_address bus_address; /* Bus address of location */
210 void *virtual_address; /* virtual address to the location */
211 unsigned int size; /* Size required by memory block */
212};
213
214struct be_mem_descriptor {
215 unsigned int index; /* Index of this memory parameter */
216 unsigned int category; /* type indicates cached/non-cached */
217 unsigned int num_elements; /* number of elements in this
218 * descriptor
219 */
220 unsigned int alignment_mask; /* Alignment mask for this block */
221 unsigned int size_in_bytes; /* Size required by memory block */
222 struct mem_array *mem_array;
223};
224
225struct sgl_handle {
226 unsigned int sgl_index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530227 unsigned int type;
228 unsigned int cid;
229 struct iscsi_task *task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530230 struct iscsi_sge *pfrag;
231};
232
233struct hba_parameters {
234 unsigned int ios_per_ctrl;
235 unsigned int cxns_per_ctrl;
236 unsigned int asyncpdus_per_ctrl;
237 unsigned int icds_per_ctrl;
238 unsigned int num_sge_per_io;
239 unsigned int defpdu_hdr_sz;
240 unsigned int defpdu_data_sz;
241 unsigned int num_cq_entries;
242 unsigned int num_eq_entries;
243 unsigned int wrbs_per_cxn;
244 unsigned int crashmode;
245 unsigned int hba_num;
246
247 unsigned int mgmt_ws_sz;
248 unsigned int hwi_ws_sz;
249
250 unsigned int eto;
251 unsigned int ldto;
252
253 unsigned int dbg_flags;
254 unsigned int num_cxn;
255
256 unsigned int eq_timer;
257 /**
258 * These are calculated from other params. They're here
259 * for debug purposes
260 */
261 unsigned int num_mcc_pages;
262 unsigned int num_mcc_cq_pages;
263 unsigned int num_cq_pages;
264 unsigned int num_eq_pages;
265
266 unsigned int num_async_pdu_buf_pages;
267 unsigned int num_async_pdu_buf_sgl_pages;
268 unsigned int num_async_pdu_buf_cq_pages;
269
270 unsigned int num_async_pdu_hdr_pages;
271 unsigned int num_async_pdu_hdr_sgl_pages;
272 unsigned int num_async_pdu_hdr_cq_pages;
273
274 unsigned int num_sge;
275};
276
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530277struct invalidate_command_table {
278 unsigned short icd;
279 unsigned short cid;
280} __packed;
281
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -0700282#define BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cri) \
283 (phwi_ctrlr->wrb_context[cri].ulp_num)
284struct hwi_wrb_context {
285 struct list_head wrb_handle_list;
286 struct list_head wrb_handle_drvr_list;
287 struct wrb_handle **pwrb_handle_base;
288 struct wrb_handle **pwrb_handle_basestd;
289 struct iscsi_wrb *plast_wrb;
290 unsigned short alloc_index;
291 unsigned short free_index;
292 unsigned short wrb_handles_available;
293 unsigned short cid;
294 uint8_t ulp_num; /* ULP to which CID binded */
295 uint16_t register_set;
296 uint16_t doorbell_format;
297 uint32_t doorbell_offset;
298};
299
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700300struct ulp_cid_info {
301 unsigned short *cid_array;
302 unsigned short avlbl_cids;
303 unsigned short cid_alloc;
304 unsigned short cid_free;
305};
306
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -0700307#include "be.h"
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -0700308#define chip_be2(phba) (phba->generation == BE_GEN2)
309#define chip_be3_r(phba) (phba->generation == BE_GEN3)
310#define is_chip_be2_be3r(phba) (chip_be3_r(phba) || (chip_be2(phba)))
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700311
312#define BEISCSI_ULP0 0
313#define BEISCSI_ULP1 1
314#define BEISCSI_ULP_COUNT 2
315#define BEISCSI_ULP0_LOADED 0x01
316#define BEISCSI_ULP1_LOADED 0x02
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700317
318#define BEISCSI_ULP_AVLBL_CID(phba, ulp_num) \
319 (((struct ulp_cid_info *)phba->cid_array_info[ulp_num])->avlbl_cids)
320#define BEISCSI_ULP0_AVLBL_CID(phba) \
321 BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP0)
322#define BEISCSI_ULP1_AVLBL_CID(phba) \
323 BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP1)
324
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530325struct beiscsi_hba {
326 struct hba_parameters params;
327 struct hwi_controller *phwi_ctrlr;
328 unsigned int mem_req[SE_MEM_MAX];
329 /* PCI BAR mapped addresses */
330 u8 __iomem *csr_va; /* CSR */
331 u8 __iomem *db_va; /* Door Bell */
332 u8 __iomem *pci_va; /* PCI Config */
333 struct be_bus_address csr_pa; /* CSR */
334 struct be_bus_address db_pa; /* CSR */
335 struct be_bus_address pci_pa; /* CSR */
336 /* PCI representation of our HBA */
337 struct pci_dev *pcidev;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530338 unsigned short asic_revision;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530339 unsigned int num_cpus;
340 unsigned int nxt_cqid;
John Soni Jose22abeef2012-10-20 04:43:32 +0530341 struct msix_entry msix_entries[MAX_CPUS];
342 char *msi_name[MAX_CPUS];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530343 bool msix_enabled;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530344 struct be_mem_descriptor *init_mem;
345
346 unsigned short io_sgl_alloc_index;
347 unsigned short io_sgl_free_index;
348 unsigned short io_sgl_hndl_avbl;
349 struct sgl_handle **io_sgl_hndl_base;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530350 struct sgl_handle **sgl_hndl_array;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530351
352 unsigned short eh_sgl_alloc_index;
353 unsigned short eh_sgl_free_index;
354 unsigned short eh_sgl_hndl_avbl;
355 struct sgl_handle **eh_sgl_hndl_base;
356 spinlock_t io_sgl_lock;
357 spinlock_t mgmt_sgl_lock;
358 spinlock_t isr_lock;
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -0700359 spinlock_t async_pdu_lock;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530360 unsigned int age;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530361 struct list_head hba_queue;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700362#define BE_MAX_SESSION 2048
363#define BE_SET_CID_TO_CRI(cri_index, cid) \
364 (phba->cid_to_cri_map[cid] = cri_index)
365#define BE_GET_CRI_FROM_CID(cid) (phba->cid_to_cri_map[cid])
366 unsigned short cid_to_cri_map[BE_MAX_SESSION];
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700367 struct ulp_cid_info *cid_array_info[BEISCSI_ULP_COUNT];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530368 struct iscsi_endpoint **ep_array;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700369 struct beiscsi_conn **conn_table;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530370 struct iscsi_boot_kset *boot_kset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530371 struct Scsi_Host *shost;
Mike Christie0e438952012-04-03 23:41:51 -0500372 struct iscsi_iface *ipv4_iface;
373 struct iscsi_iface *ipv6_iface;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530374 struct {
375 /**
376 * group together since they are used most frequently
377 * for cid to cri conversion
378 */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530379 unsigned int phys_port;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700380 unsigned int iscsi_cid_start[BEISCSI_ULP_COUNT];
381#define BEISCSI_GET_CID_COUNT(phba, ulp_num) \
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700382 (phba->fw_config.iscsi_cid_count[ulp_num])
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700383 unsigned int iscsi_cid_count[BEISCSI_ULP_COUNT];
384 unsigned int iscsi_icd_count[BEISCSI_ULP_COUNT];
385 unsigned int iscsi_icd_start[BEISCSI_ULP_COUNT];
386 unsigned int iscsi_chain_start[BEISCSI_ULP_COUNT];
387 unsigned int iscsi_chain_count[BEISCSI_ULP_COUNT];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530388
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530389 unsigned short iscsi_features;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700390 uint16_t dual_ulp_aware;
391 unsigned long ulp_supported;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530392 } fw_config;
393
John Soni Josee175def2012-10-20 04:45:40 +0530394 unsigned int state;
395 bool fw_timeout;
396 bool ue_detected;
397 struct delayed_work beiscsi_hw_check_task;
398
Jayamohan Kallickal6c831852013-09-28 15:35:40 -0700399 bool mac_addr_set;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530400 u8 mac_address[ETH_ALEN];
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700401 char fw_ver_str[BEISCSI_VER_STRLEN];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530402 char wq_name[20];
403 struct workqueue_struct *wq; /* The actuak work queue */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530404 struct be_ctrl_info ctrl;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530405 unsigned int generation;
Mike Christie0e438952012-04-03 23:41:51 -0500406 unsigned int interface_handle;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530407 struct mgmt_session_info boot_sess;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530408 struct invalidate_command_table inv_tbl[128];
409
John Soni Jose99bc5d52012-08-20 23:00:18 +0530410 unsigned int attr_log_enable;
John Soni Jose09a10932012-10-20 04:44:23 +0530411 int (*iotask_fn)(struct iscsi_task *,
412 struct scatterlist *sg,
413 uint32_t num_sg, uint32_t xferlen,
414 uint32_t writedir);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530415};
416
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +0530417struct beiscsi_session {
418 struct pci_pool *bhs_pool;
419};
420
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530421/**
422 * struct beiscsi_conn - iscsi connection structure
423 */
424struct beiscsi_conn {
425 struct iscsi_conn *conn;
426 struct beiscsi_hba *phba;
427 u32 exp_statsn;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -0700428 u32 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530429 u32 beiscsi_conn_cid;
430 struct beiscsi_endpoint *ep;
431 unsigned short login_in_progress;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +0530432 struct wrb_handle *plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530433 struct sgl_handle *plogin_sgl_handle;
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +0530434 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530435 struct iscsi_task *task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530436};
437
438/* This structure is used by the chip */
439struct pdu_data_out {
440 u32 dw[12];
441};
442/**
443 * Pseudo amap definition in which each bit of the actual structure is defined
444 * as a byte: used to calculate offset/shift/mask of each field
445 */
446struct amap_pdu_data_out {
447 u8 opcode[6]; /* opcode */
448 u8 rsvd0[2]; /* should be 0 */
449 u8 rsvd1[7];
450 u8 final_bit; /* F bit */
451 u8 rsvd2[16];
452 u8 ahs_length[8]; /* no AHS */
453 u8 data_len_hi[8];
454 u8 data_len_lo[16]; /* DataSegmentLength */
455 u8 lun[64];
456 u8 itt[32]; /* ITT; initiator task tag */
457 u8 ttt[32]; /* TTT; valid for R2T or 0xffffffff */
458 u8 rsvd3[32];
459 u8 exp_stat_sn[32];
460 u8 rsvd4[32];
461 u8 data_sn[32];
462 u8 buffer_offset[32];
463 u8 rsvd5[32];
464};
465
466struct be_cmd_bhs {
Nicholas Bellinger12352182011-05-27 11:16:33 +0000467 struct iscsi_scsi_req iscsi_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530468 unsigned char pad1[16];
469 struct pdu_data_out iscsi_data_pdu;
470 unsigned char pad2[BE_SENSE_INFO_SIZE -
471 sizeof(struct pdu_data_out)];
472};
473
474struct beiscsi_io_task {
475 struct wrb_handle *pwrb_handle;
476 struct sgl_handle *psgl_handle;
477 struct beiscsi_conn *conn;
478 struct scsi_cmnd *scsi_cmnd;
479 unsigned int cmd_sn;
480 unsigned int flags;
481 unsigned short cid;
482 unsigned short header_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530483 itt_t libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530484 struct be_cmd_bhs *cmd_bhs;
485 struct be_bus_address bhs_pa;
486 unsigned short bhs_len;
John Soni Josed629c472012-10-20 04:42:00 +0530487 dma_addr_t mtask_addr;
488 uint32_t mtask_data_count;
John Soni Jose09a10932012-10-20 04:44:23 +0530489 uint8_t wrb_type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530490};
491
492struct be_nonio_bhs {
493 struct iscsi_hdr iscsi_hdr;
494 unsigned char pad1[16];
495 struct pdu_data_out iscsi_data_pdu;
496 unsigned char pad2[BE_SENSE_INFO_SIZE -
497 sizeof(struct pdu_data_out)];
498};
499
500struct be_status_bhs {
Nicholas Bellinger12352182011-05-27 11:16:33 +0000501 struct iscsi_scsi_req iscsi_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530502 unsigned char pad1[16];
503 /**
504 * The plus 2 below is to hold the sense info length that gets
505 * DMA'ed by RxULP
506 */
507 unsigned char sense_info[BE_SENSE_INFO_SIZE];
508};
509
510struct iscsi_sge {
511 u32 dw[4];
512};
513
514/**
515 * Pseudo amap definition in which each bit of the actual structure is defined
516 * as a byte: used to calculate offset/shift/mask of each field
517 */
518struct amap_iscsi_sge {
519 u8 addr_hi[32];
520 u8 addr_lo[32];
521 u8 sge_offset[22]; /* DWORD 2 */
522 u8 rsvd0[9]; /* DWORD 2 */
523 u8 last_sge; /* DWORD 2 */
524 u8 len[17]; /* DWORD 3 */
525 u8 rsvd1[15]; /* DWORD 3 */
526};
527
528struct beiscsi_offload_params {
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700529 u32 dw[6];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530530};
531
532#define OFFLD_PARAMS_ERL 0x00000003
533#define OFFLD_PARAMS_DDE 0x00000004
534#define OFFLD_PARAMS_HDE 0x00000008
535#define OFFLD_PARAMS_IR2T 0x00000010
536#define OFFLD_PARAMS_IMD 0x00000020
John Soni Joseacb96932012-10-20 04:44:35 +0530537#define OFFLD_PARAMS_DATA_SEQ_INORDER 0x00000040
538#define OFFLD_PARAMS_PDU_SEQ_INORDER 0x00000080
539#define OFFLD_PARAMS_MAX_R2T 0x00FFFF00
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530540
541/**
542 * Pseudo amap definition in which each bit of the actual structure is defined
543 * as a byte: used to calculate offset/shift/mask of each field
544 */
545struct amap_beiscsi_offload_params {
546 u8 max_burst_length[32];
547 u8 max_send_data_segment_length[32];
548 u8 first_burst_length[32];
549 u8 erl[2];
550 u8 dde[1];
551 u8 hde[1];
552 u8 ir2t[1];
553 u8 imd[1];
John Soni Joseacb96932012-10-20 04:44:35 +0530554 u8 data_seq_inorder[1];
555 u8 pdu_seq_inorder[1];
556 u8 max_r2t[16];
557 u8 pad[8];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530558 u8 exp_statsn[32];
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700559 u8 max_recv_data_segment_length[32];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530560};
561
562/* void hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
563 struct beiscsi_hba *phba, struct sol_cqe *psol);*/
564
565struct async_pdu_handle {
566 struct list_head link;
567 struct be_bus_address pa;
568 void *pbuffer;
569 unsigned int consumed;
570 unsigned char index;
571 unsigned char is_header;
572 unsigned short cri;
573 unsigned long buffer_len;
574};
575
576struct hwi_async_entry {
577 struct {
578 unsigned char hdr_received;
579 unsigned char hdr_len;
580 unsigned short bytes_received;
581 unsigned int bytes_needed;
582 struct list_head list;
583 } wait_queue;
584
585 struct list_head header_busy_list;
586 struct list_head data_busy_list;
587};
588
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530589struct hwi_async_pdu_context {
590 struct {
591 struct be_bus_address pa_base;
592 void *va_base;
593 void *ring_base;
594 struct async_pdu_handle *handle_base;
595
596 unsigned int host_write_ptr;
597 unsigned int ep_read_ptr;
598 unsigned int writables;
599
600 unsigned int free_entries;
601 unsigned int busy_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530602
603 struct list_head free_list;
604 } async_header;
605
606 struct {
607 struct be_bus_address pa_base;
608 void *va_base;
609 void *ring_base;
610 struct async_pdu_handle *handle_base;
611
612 unsigned int host_write_ptr;
613 unsigned int ep_read_ptr;
614 unsigned int writables;
615
616 unsigned int free_entries;
617 unsigned int busy_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530618 struct list_head free_list;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530619 } async_data;
620
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -0500621 unsigned int buffer_size;
622 unsigned int num_entries;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700623#define BE_GET_ASYNC_CRI_FROM_CID(cid) (pasync_ctx->cid_to_async_cri_map[cid])
624 unsigned short cid_to_async_cri_map[BE_MAX_SESSION];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530625 /**
626 * This is a varying size list! Do not add anything
627 * after this entry!!
628 */
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700629 struct hwi_async_entry *async_entry;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530630};
631
632#define PDUCQE_CODE_MASK 0x0000003F
633#define PDUCQE_DPL_MASK 0xFFFF0000
634#define PDUCQE_INDEX_MASK 0x0000FFFF
635
636struct i_t_dpdu_cqe {
637 u32 dw[4];
638} __packed;
639
640/**
641 * Pseudo amap definition in which each bit of the actual structure is defined
642 * as a byte: used to calculate offset/shift/mask of each field
643 */
644struct amap_i_t_dpdu_cqe {
645 u8 db_addr_hi[32];
646 u8 db_addr_lo[32];
647 u8 code[6];
648 u8 cid[10];
649 u8 dpl[16];
650 u8 index[16];
651 u8 num_cons[10];
652 u8 rsvd0[4];
653 u8 final;
654 u8 valid;
655} __packed;
656
John Soni Jose73133262012-10-20 04:44:49 +0530657struct amap_i_t_dpdu_cqe_v2 {
658 u8 db_addr_hi[32]; /* DWORD 0 */
659 u8 db_addr_lo[32]; /* DWORD 1 */
660 u8 code[6]; /* DWORD 2 */
661 u8 num_cons; /* DWORD 2*/
662 u8 rsvd0[8]; /* DWORD 2 */
663 u8 dpl[17]; /* DWORD 2 */
664 u8 index[16]; /* DWORD 3 */
665 u8 cid[13]; /* DWORD 3 */
666 u8 rsvd1; /* DWORD 3 */
667 u8 final; /* DWORD 3 */
668 u8 valid; /* DWORD 3 */
669} __packed;
670
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530671#define CQE_VALID_MASK 0x80000000
672#define CQE_CODE_MASK 0x0000003F
673#define CQE_CID_MASK 0x0000FFC0
674
675#define EQE_VALID_MASK 0x00000001
676#define EQE_MAJORCODE_MASK 0x0000000E
677#define EQE_RESID_MASK 0xFFFF0000
678
679struct be_eq_entry {
680 u32 dw[1];
681} __packed;
682
683/**
684 * Pseudo amap definition in which each bit of the actual structure is defined
685 * as a byte: used to calculate offset/shift/mask of each field
686 */
687struct amap_eq_entry {
688 u8 valid; /* DWORD 0 */
689 u8 major_code[3]; /* DWORD 0 */
690 u8 minor_code[12]; /* DWORD 0 */
691 u8 resource_id[16]; /* DWORD 0 */
692
693} __packed;
694
695struct cq_db {
696 u32 dw[1];
697} __packed;
698
699/**
700 * Pseudo amap definition in which each bit of the actual structure is defined
701 * as a byte: used to calculate offset/shift/mask of each field
702 */
703struct amap_cq_db {
704 u8 qid[10];
705 u8 event[1];
706 u8 rsvd0[5];
707 u8 num_popped[13];
708 u8 rearm[1];
709 u8 rsvd1[2];
710} __packed;
711
712void beiscsi_process_eq(struct beiscsi_hba *phba);
713
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530714struct iscsi_wrb {
715 u32 dw[16];
716} __packed;
717
718#define WRB_TYPE_MASK 0xF0000000
John Soni Jose09a10932012-10-20 04:44:23 +0530719#define SKH_WRB_TYPE_OFFSET 27
720#define BE_WRB_TYPE_OFFSET 28
721
722#define ADAPTER_SET_WRB_TYPE(pwrb, wrb_type, type_offset) \
723 (pwrb->dw[0] |= (wrb_type << type_offset))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530724
725/**
726 * Pseudo amap definition in which each bit of the actual structure is defined
727 * as a byte: used to calculate offset/shift/mask of each field
728 */
729struct amap_iscsi_wrb {
730 u8 lun[14]; /* DWORD 0 */
731 u8 lt; /* DWORD 0 */
732 u8 invld; /* DWORD 0 */
733 u8 wrb_idx[8]; /* DWORD 0 */
734 u8 dsp; /* DWORD 0 */
735 u8 dmsg; /* DWORD 0 */
736 u8 undr_run; /* DWORD 0 */
737 u8 over_run; /* DWORD 0 */
738 u8 type[4]; /* DWORD 0 */
739 u8 ptr2nextwrb[8]; /* DWORD 1 */
740 u8 r2t_exp_dtl[24]; /* DWORD 1 */
741 u8 sgl_icd_idx[12]; /* DWORD 2 */
742 u8 rsvd0[20]; /* DWORD 2 */
743 u8 exp_data_sn[32]; /* DWORD 3 */
744 u8 iscsi_bhs_addr_hi[32]; /* DWORD 4 */
745 u8 iscsi_bhs_addr_lo[32]; /* DWORD 5 */
746 u8 cmdsn_itt[32]; /* DWORD 6 */
747 u8 dif_ref_tag[32]; /* DWORD 7 */
748 u8 sge0_addr_hi[32]; /* DWORD 8 */
749 u8 sge0_addr_lo[32]; /* DWORD 9 */
750 u8 sge0_offset[22]; /* DWORD 10 */
751 u8 pbs; /* DWORD 10 */
752 u8 dif_mode[2]; /* DWORD 10 */
753 u8 rsvd1[6]; /* DWORD 10 */
754 u8 sge0_last; /* DWORD 10 */
755 u8 sge0_len[17]; /* DWORD 11 */
756 u8 dif_meta_tag[14]; /* DWORD 11 */
757 u8 sge0_in_ddr; /* DWORD 11 */
758 u8 sge1_addr_hi[32]; /* DWORD 12 */
759 u8 sge1_addr_lo[32]; /* DWORD 13 */
760 u8 sge1_r2t_offset[22]; /* DWORD 14 */
761 u8 rsvd2[9]; /* DWORD 14 */
762 u8 sge1_last; /* DWORD 14 */
763 u8 sge1_len[17]; /* DWORD 15 */
764 u8 ref_sgl_icd_idx[12]; /* DWORD 15 */
765 u8 rsvd3[2]; /* DWORD 15 */
766 u8 sge1_in_ddr; /* DWORD 15 */
767
768} __packed;
769
John Soni Jose09a10932012-10-20 04:44:23 +0530770struct amap_iscsi_wrb_v2 {
771 u8 r2t_exp_dtl[25]; /* DWORD 0 */
772 u8 rsvd0[2]; /* DWORD 0*/
773 u8 type[5]; /* DWORD 0 */
774 u8 ptr2nextwrb[8]; /* DWORD 1 */
775 u8 wrb_idx[8]; /* DWORD 1 */
776 u8 lun[16]; /* DWORD 1 */
777 u8 sgl_idx[16]; /* DWORD 2 */
778 u8 ref_sgl_icd_idx[16]; /* DWORD 2 */
779 u8 exp_data_sn[32]; /* DWORD 3 */
780 u8 iscsi_bhs_addr_hi[32]; /* DWORD 4 */
781 u8 iscsi_bhs_addr_lo[32]; /* DWORD 5 */
782 u8 cq_id[16]; /* DWORD 6 */
783 u8 rsvd1[16]; /* DWORD 6 */
784 u8 cmdsn_itt[32]; /* DWORD 7 */
785 u8 sge0_addr_hi[32]; /* DWORD 8 */
786 u8 sge0_addr_lo[32]; /* DWORD 9 */
787 u8 sge0_offset[24]; /* DWORD 10 */
788 u8 rsvd2[7]; /* DWORD 10 */
789 u8 sge0_last; /* DWORD 10 */
790 u8 sge0_len[17]; /* DWORD 11 */
791 u8 rsvd3[7]; /* DWORD 11 */
792 u8 diff_enbl; /* DWORD 11 */
793 u8 u_run; /* DWORD 11 */
794 u8 o_run; /* DWORD 11 */
795 u8 invalid; /* DWORD 11 */
796 u8 dsp; /* DWORD 11 */
797 u8 dmsg; /* DWORD 11 */
798 u8 rsvd4; /* DWORD 11 */
799 u8 lt; /* DWORD 11 */
800 u8 sge1_addr_hi[32]; /* DWORD 12 */
801 u8 sge1_addr_lo[32]; /* DWORD 13 */
802 u8 sge1_r2t_offset[24]; /* DWORD 14 */
803 u8 rsvd5[7]; /* DWORD 14 */
804 u8 sge1_last; /* DWORD 14 */
805 u8 sge1_len[17]; /* DWORD 15 */
806 u8 rsvd6[15]; /* DWORD 15 */
807} __packed;
808
809
Jayamohan Kallickald5431482010-01-05 05:06:21 +0530810struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530811void
812free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle);
813
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530814void beiscsi_process_all_cqs(struct work_struct *work);
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -0700815void beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
816 struct iscsi_task *task);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530817
John Soni Jose7a158002012-10-20 04:45:51 +0530818static inline bool beiscsi_error(struct beiscsi_hba *phba)
819{
820 return phba->ue_detected || phba->fw_timeout;
821}
822
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530823struct pdu_nop_out {
824 u32 dw[12];
825};
826
827/**
828 * Pseudo amap definition in which each bit of the actual structure is defined
829 * as a byte: used to calculate offset/shift/mask of each field
830 */
831struct amap_pdu_nop_out {
832 u8 opcode[6]; /* opcode 0x00 */
833 u8 i_bit; /* I Bit */
834 u8 x_bit; /* reserved; should be 0 */
835 u8 fp_bit_filler1[7];
836 u8 f_bit; /* always 1 */
837 u8 reserved1[16];
838 u8 ahs_length[8]; /* no AHS */
839 u8 data_len_hi[8];
840 u8 data_len_lo[16]; /* DataSegmentLength */
841 u8 lun[64];
842 u8 itt[32]; /* initiator id for ping or 0xffffffff */
843 u8 ttt[32]; /* target id for ping or 0xffffffff */
844 u8 cmd_sn[32];
845 u8 exp_stat_sn[32];
846 u8 reserved5[128];
847};
848
849#define PDUBASE_OPCODE_MASK 0x0000003F
850#define PDUBASE_DATALENHI_MASK 0x0000FF00
851#define PDUBASE_DATALENLO_MASK 0xFFFF0000
852
853struct pdu_base {
854 u32 dw[16];
855} __packed;
856
857/**
858 * Pseudo amap definition in which each bit of the actual structure is defined
859 * as a byte: used to calculate offset/shift/mask of each field
860 */
861struct amap_pdu_base {
862 u8 opcode[6];
863 u8 i_bit; /* immediate bit */
864 u8 x_bit; /* reserved, always 0 */
865 u8 reserved1[24]; /* opcode-specific fields */
866 u8 ahs_length[8]; /* length units is 4 byte words */
867 u8 data_len_hi[8];
868 u8 data_len_lo[16]; /* DatasegmentLength */
869 u8 lun[64]; /* lun or opcode-specific fields */
870 u8 itt[32]; /* initiator task tag */
871 u8 reserved4[224];
872};
873
874struct iscsi_target_context_update_wrb {
875 u32 dw[16];
876} __packed;
877
878/**
879 * Pseudo amap definition in which each bit of the actual structure is defined
880 * as a byte: used to calculate offset/shift/mask of each field
881 */
John Soni Joseacb96932012-10-20 04:44:35 +0530882#define BE_TGT_CTX_UPDT_CMD 0x07
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530883struct amap_iscsi_target_context_update_wrb {
884 u8 lun[14]; /* DWORD 0 */
885 u8 lt; /* DWORD 0 */
886 u8 invld; /* DWORD 0 */
887 u8 wrb_idx[8]; /* DWORD 0 */
888 u8 dsp; /* DWORD 0 */
889 u8 dmsg; /* DWORD 0 */
890 u8 undr_run; /* DWORD 0 */
891 u8 over_run; /* DWORD 0 */
892 u8 type[4]; /* DWORD 0 */
893 u8 ptr2nextwrb[8]; /* DWORD 1 */
894 u8 max_burst_length[19]; /* DWORD 1 */
895 u8 rsvd0[5]; /* DWORD 1 */
896 u8 rsvd1[15]; /* DWORD 2 */
897 u8 max_send_data_segment_length[17]; /* DWORD 2 */
898 u8 first_burst_length[14]; /* DWORD 3 */
899 u8 rsvd2[2]; /* DWORD 3 */
900 u8 tx_wrbindex_drv_msg[8]; /* DWORD 3 */
901 u8 rsvd3[5]; /* DWORD 3 */
902 u8 session_state[3]; /* DWORD 3 */
903 u8 rsvd4[16]; /* DWORD 4 */
904 u8 tx_jumbo; /* DWORD 4 */
905 u8 hde; /* DWORD 4 */
906 u8 dde; /* DWORD 4 */
907 u8 erl[2]; /* DWORD 4 */
908 u8 domain_id[5]; /* DWORD 4 */
909 u8 mode; /* DWORD 4 */
910 u8 imd; /* DWORD 4 */
911 u8 ir2t; /* DWORD 4 */
912 u8 notpredblq[2]; /* DWORD 4 */
913 u8 compltonack; /* DWORD 4 */
914 u8 stat_sn[32]; /* DWORD 5 */
915 u8 pad_buffer_addr_hi[32]; /* DWORD 6 */
916 u8 pad_buffer_addr_lo[32]; /* DWORD 7 */
917 u8 pad_addr_hi[32]; /* DWORD 8 */
918 u8 pad_addr_lo[32]; /* DWORD 9 */
919 u8 rsvd5[32]; /* DWORD 10 */
920 u8 rsvd6[32]; /* DWORD 11 */
921 u8 rsvd7[32]; /* DWORD 12 */
922 u8 rsvd8[32]; /* DWORD 13 */
923 u8 rsvd9[32]; /* DWORD 14 */
924 u8 rsvd10[32]; /* DWORD 15 */
925
926} __packed;
927
John Soni Joseacb96932012-10-20 04:44:35 +0530928#define BEISCSI_MAX_RECV_DATASEG_LEN (64 * 1024)
929#define BEISCSI_MAX_CXNS 1
930struct amap_iscsi_target_context_update_wrb_v2 {
931 u8 max_burst_length[24]; /* DWORD 0 */
932 u8 rsvd0[3]; /* DWORD 0 */
933 u8 type[5]; /* DWORD 0 */
934 u8 ptr2nextwrb[8]; /* DWORD 1 */
935 u8 wrb_idx[8]; /* DWORD 1 */
936 u8 rsvd1[16]; /* DWORD 1 */
937 u8 max_send_data_segment_length[24]; /* DWORD 2 */
938 u8 rsvd2[8]; /* DWORD 2 */
939 u8 first_burst_length[24]; /* DWORD 3 */
940 u8 rsvd3[8]; /* DOWRD 3 */
941 u8 max_r2t[16]; /* DWORD 4 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700942 u8 rsvd4; /* DWORD 4 */
John Soni Joseacb96932012-10-20 04:44:35 +0530943 u8 hde; /* DWORD 4 */
944 u8 dde; /* DWORD 4 */
945 u8 erl[2]; /* DWORD 4 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700946 u8 rsvd5[6]; /* DWORD 4 */
John Soni Joseacb96932012-10-20 04:44:35 +0530947 u8 imd; /* DWORD 4 */
948 u8 ir2t; /* DWORD 4 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700949 u8 rsvd6[3]; /* DWORD 4 */
John Soni Joseacb96932012-10-20 04:44:35 +0530950 u8 stat_sn[32]; /* DWORD 5 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700951 u8 rsvd7[32]; /* DWORD 6 */
952 u8 rsvd8[32]; /* DWORD 7 */
John Soni Joseacb96932012-10-20 04:44:35 +0530953 u8 max_recv_dataseg_len[24]; /* DWORD 8 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700954 u8 rsvd9[8]; /* DWORD 8 */
955 u8 rsvd10[32]; /* DWORD 9 */
956 u8 rsvd11[32]; /* DWORD 10 */
John Soni Joseacb96932012-10-20 04:44:35 +0530957 u8 max_cxns[16]; /* DWORD 11 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700958 u8 rsvd12[11]; /* DWORD 11*/
John Soni Joseacb96932012-10-20 04:44:35 +0530959 u8 invld; /* DWORD 11 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700960 u8 rsvd13;/* DWORD 11*/
John Soni Joseacb96932012-10-20 04:44:35 +0530961 u8 dmsg; /* DWORD 11 */
962 u8 data_seq_inorder; /* DWORD 11 */
963 u8 pdu_seq_inorder; /* DWORD 11 */
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700964 u8 rsvd14[32]; /*DWORD 12 */
965 u8 rsvd15[32]; /* DWORD 13 */
966 u8 rsvd16[32]; /* DWORD 14 */
967 u8 rsvd17[32]; /* DWORD 15 */
John Soni Joseacb96932012-10-20 04:44:35 +0530968} __packed;
969
970
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530971struct be_ring {
972 u32 pages; /* queue size in pages */
973 u32 id; /* queue id assigned by beklib */
974 u32 num; /* number of elements in queue */
975 u32 cidx; /* consumer index */
976 u32 pidx; /* producer index -- not used by most rings */
977 u32 item_size; /* size in bytes of one object */
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700978 u8 ulp_num; /* ULP to which CID binded */
979 u16 register_set;
980 u16 doorbell_format;
981 u32 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530982
983 void *va; /* The virtual address of the ring. This
984 * should be last to allow 32 & 64 bit debugger
985 * extensions to work.
986 */
987};
988
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530989struct hwi_controller {
990 struct list_head io_sgl_list;
991 struct list_head eh_sgl_list;
992 struct sgl_handle *psgl_handle_base;
993 unsigned int wrb_mem_index;
994
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700995 struct hwi_wrb_context *wrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530996 struct mcc_wrb *pmcc_wrb_base;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -0700997 struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
998 struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530999 struct hwi_context_memory *phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301000};
1001
1002enum hwh_type_enum {
1003 HWH_TYPE_IO = 1,
1004 HWH_TYPE_LOGOUT = 2,
1005 HWH_TYPE_TMF = 3,
1006 HWH_TYPE_NOP = 4,
1007 HWH_TYPE_IO_RD = 5,
1008 HWH_TYPE_LOGIN = 11,
1009 HWH_TYPE_INVALID = 0xFFFFFFFF
1010};
1011
1012struct wrb_handle {
1013 enum hwh_type_enum type;
1014 unsigned short wrb_index;
1015 unsigned short nxt_wrb_index;
1016
1017 struct iscsi_task *pio_handle;
1018 struct iscsi_wrb *pwrb;
1019};
1020
1021struct hwi_context_memory {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301022 /* Adaptive interrupt coalescing (AIC) info */
1023 u16 min_eqd; /* in usecs */
1024 u16 max_eqd; /* in usecs */
1025 u16 cur_eqd; /* in usecs */
1026 struct be_eq_obj be_eq[MAX_CPUS];
John Soni Jose22abeef2012-10-20 04:43:32 +05301027 struct be_queue_info be_cq[MAX_CPUS - 1];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301028
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001029 struct be_queue_info *be_wrbq;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001030 struct be_queue_info be_def_hdrq[BEISCSI_ULP_COUNT];
1031 struct be_queue_info be_def_dataq[BEISCSI_ULP_COUNT];
1032 struct hwi_async_pdu_context *pasync_ctx[BEISCSI_ULP_COUNT];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301033};
1034
John Soni Jose99bc5d52012-08-20 23:00:18 +05301035/* Logging related definitions */
1036#define BEISCSI_LOG_INIT 0x0001 /* Initialization events */
1037#define BEISCSI_LOG_MBOX 0x0002 /* Mailbox Events */
1038#define BEISCSI_LOG_MISC 0x0004 /* Miscllaneous Events */
1039#define BEISCSI_LOG_EH 0x0008 /* Error Handler */
1040#define BEISCSI_LOG_IO 0x0010 /* IO Code Path */
1041#define BEISCSI_LOG_CONFIG 0x0020 /* CONFIG Code Path */
1042
1043#define beiscsi_log(phba, level, mask, fmt, arg...) \
1044do { \
1045 uint32_t log_value = phba->attr_log_enable; \
1046 if (((mask) & log_value) || (level[1] <= '3')) \
1047 shost_printk(level, phba->shost, \
1048 fmt, __LINE__, ##arg); \
1049} while (0)
1050
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301051#endif