]>
Commit | Line | Data |
---|---|---|
6733b39a | 1 | /** |
60f36e04 | 2 | * Copyright (C) 2005 - 2016 Broadcom |
6733b39a JK |
3 | * 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 | * | |
60f36e04 | 10 | * Written by: Jayamohan Kallickal (jayamohan.kallickal@broadcom.com) |
6733b39a JK |
11 | * |
12 | * Contact Information: | |
60f36e04 | 13 | * linux-drivers@broadcom.com |
6733b39a | 14 | * |
c4f39bda | 15 | * Emulex |
255fa9a3 JK |
16 | * 3333 Susan Street |
17 | * Costa Mesa, CA 92626 | |
6733b39a | 18 | */ |
255fa9a3 | 19 | |
6733b39a JK |
20 | #include <linux/reboot.h> |
21 | #include <linux/delay.h> | |
5a0e3ad6 | 22 | #include <linux/slab.h> |
6733b39a JK |
23 | #include <linux/interrupt.h> |
24 | #include <linux/blkdev.h> | |
25 | #include <linux/pci.h> | |
26 | #include <linux/string.h> | |
27 | #include <linux/kernel.h> | |
28 | #include <linux/semaphore.h> | |
c7acc5b8 | 29 | #include <linux/iscsi_boot_sysfs.h> |
acf3368f | 30 | #include <linux/module.h> |
ffce3e2e | 31 | #include <linux/bsg-lib.h> |
1094cf68 | 32 | #include <linux/irq_poll.h> |
6733b39a JK |
33 | |
34 | #include <scsi/libiscsi.h> | |
ffce3e2e JK |
35 | #include <scsi/scsi_bsg_iscsi.h> |
36 | #include <scsi/scsi_netlink.h> | |
6733b39a JK |
37 | #include <scsi/scsi_transport_iscsi.h> |
38 | #include <scsi/scsi_transport.h> | |
39 | #include <scsi/scsi_cmnd.h> | |
40 | #include <scsi/scsi_device.h> | |
41 | #include <scsi/scsi_host.h> | |
42 | #include <scsi/scsi.h> | |
43 | #include "be_main.h" | |
44 | #include "be_iscsi.h" | |
45 | #include "be_mgmt.h" | |
0a513dd8 | 46 | #include "be_cmds.h" |
6733b39a JK |
47 | |
48 | static unsigned int be_iopoll_budget = 10; | |
49 | static unsigned int be_max_phys_size = 64; | |
bfead3b2 | 50 | static unsigned int enable_msix = 1; |
6733b39a | 51 | |
6733b39a | 52 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); |
76d15dbd | 53 | MODULE_VERSION(BUILD_STR); |
c4f39bda | 54 | MODULE_AUTHOR("Emulex Corporation"); |
6733b39a JK |
55 | MODULE_LICENSE("GPL"); |
56 | module_param(be_iopoll_budget, int, 0); | |
57 | module_param(enable_msix, int, 0); | |
58 | module_param(be_max_phys_size, uint, S_IRUGO); | |
99bc5d55 JSJ |
59 | MODULE_PARM_DESC(be_max_phys_size, |
60 | "Maximum Size (In Kilobytes) of physically contiguous " | |
61 | "memory that can be allocated. Range is 16 - 128"); | |
62 | ||
63 | #define beiscsi_disp_param(_name)\ | |
0825b8ee | 64 | static ssize_t \ |
99bc5d55 JSJ |
65 | beiscsi_##_name##_disp(struct device *dev,\ |
66 | struct device_attribute *attrib, char *buf) \ | |
67 | { \ | |
68 | struct Scsi_Host *shost = class_to_shost(dev);\ | |
69 | struct beiscsi_hba *phba = iscsi_host_priv(shost); \ | |
70 | uint32_t param_val = 0; \ | |
71 | param_val = phba->attr_##_name;\ | |
72 | return snprintf(buf, PAGE_SIZE, "%d\n",\ | |
73 | phba->attr_##_name);\ | |
74 | } | |
75 | ||
76 | #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\ | |
0825b8ee | 77 | static int \ |
99bc5d55 JSJ |
78 | beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\ |
79 | {\ | |
80 | if (val >= _minval && val <= _maxval) {\ | |
81 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ | |
82 | "BA_%d : beiscsi_"#_name" updated "\ | |
83 | "from 0x%x ==> 0x%x\n",\ | |
84 | phba->attr_##_name, val); \ | |
85 | phba->attr_##_name = val;\ | |
86 | return 0;\ | |
87 | } \ | |
88 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \ | |
89 | "BA_%d beiscsi_"#_name" attribute "\ | |
90 | "cannot be updated to 0x%x, "\ | |
91 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ | |
92 | return -EINVAL;\ | |
93 | } | |
94 | ||
95 | #define beiscsi_store_param(_name) \ | |
0825b8ee | 96 | static ssize_t \ |
99bc5d55 JSJ |
97 | beiscsi_##_name##_store(struct device *dev,\ |
98 | struct device_attribute *attr, const char *buf,\ | |
99 | size_t count) \ | |
100 | { \ | |
101 | struct Scsi_Host *shost = class_to_shost(dev);\ | |
102 | struct beiscsi_hba *phba = iscsi_host_priv(shost);\ | |
103 | uint32_t param_val = 0;\ | |
104 | if (!isdigit(buf[0]))\ | |
105 | return -EINVAL;\ | |
106 | if (sscanf(buf, "%i", ¶m_val) != 1)\ | |
107 | return -EINVAL;\ | |
108 | if (beiscsi_##_name##_change(phba, param_val) == 0) \ | |
109 | return strlen(buf);\ | |
110 | else \ | |
111 | return -EINVAL;\ | |
112 | } | |
113 | ||
114 | #define beiscsi_init_param(_name, _minval, _maxval, _defval) \ | |
0825b8ee | 115 | static int \ |
99bc5d55 JSJ |
116 | beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \ |
117 | { \ | |
118 | if (val >= _minval && val <= _maxval) {\ | |
119 | phba->attr_##_name = val;\ | |
120 | return 0;\ | |
121 | } \ | |
122 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ | |
123 | "BA_%d beiscsi_"#_name" attribute " \ | |
124 | "cannot be updated to 0x%x, "\ | |
125 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ | |
126 | phba->attr_##_name = _defval;\ | |
127 | return -EINVAL;\ | |
128 | } | |
129 | ||
130 | #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \ | |
131 | static uint beiscsi_##_name = _defval;\ | |
132 | module_param(beiscsi_##_name, uint, S_IRUGO);\ | |
133 | MODULE_PARM_DESC(beiscsi_##_name, _descp);\ | |
134 | beiscsi_disp_param(_name)\ | |
135 | beiscsi_change_param(_name, _minval, _maxval, _defval)\ | |
136 | beiscsi_store_param(_name)\ | |
137 | beiscsi_init_param(_name, _minval, _maxval, _defval)\ | |
138 | DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\ | |
139 | beiscsi_##_name##_disp, beiscsi_##_name##_store) | |
140 | ||
141 | /* | |
142 | * When new log level added update the | |
143 | * the MAX allowed value for log_enable | |
144 | */ | |
145 | BEISCSI_RW_ATTR(log_enable, 0x00, | |
146 | 0xFF, 0x00, "Enable logging Bit Mask\n" | |
147 | "\t\t\t\tInitialization Events : 0x01\n" | |
148 | "\t\t\t\tMailbox Events : 0x02\n" | |
149 | "\t\t\t\tMiscellaneous Events : 0x04\n" | |
150 | "\t\t\t\tError Handling : 0x08\n" | |
151 | "\t\t\t\tIO Path Events : 0x10\n" | |
afb96058 JK |
152 | "\t\t\t\tConfiguration Path : 0x20\n" |
153 | "\t\t\t\tiSCSI Protocol : 0x40\n"); | |
99bc5d55 | 154 | |
5cac7596 | 155 | DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL); |
26000db7 | 156 | DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL); |
22661e25 | 157 | DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL); |
d3fea9af | 158 | DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL); |
6103c1f7 JK |
159 | DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO, |
160 | beiscsi_active_session_disp, NULL); | |
161 | DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO, | |
162 | beiscsi_free_session_disp, NULL); | |
99bc5d55 JSJ |
163 | struct device_attribute *beiscsi_attrs[] = { |
164 | &dev_attr_beiscsi_log_enable, | |
5cac7596 | 165 | &dev_attr_beiscsi_drvr_ver, |
26000db7 | 166 | &dev_attr_beiscsi_adapter_family, |
22661e25 | 167 | &dev_attr_beiscsi_fw_ver, |
6103c1f7 JK |
168 | &dev_attr_beiscsi_active_session_count, |
169 | &dev_attr_beiscsi_free_session_count, | |
d3fea9af | 170 | &dev_attr_beiscsi_phys_port, |
99bc5d55 JSJ |
171 | NULL, |
172 | }; | |
6733b39a | 173 | |
6763daae JSJ |
174 | static char const *cqe_desc[] = { |
175 | "RESERVED_DESC", | |
176 | "SOL_CMD_COMPLETE", | |
177 | "SOL_CMD_KILLED_DATA_DIGEST_ERR", | |
178 | "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL", | |
179 | "CXN_KILLED_BURST_LEN_MISMATCH", | |
180 | "CXN_KILLED_AHS_RCVD", | |
181 | "CXN_KILLED_HDR_DIGEST_ERR", | |
182 | "CXN_KILLED_UNKNOWN_HDR", | |
183 | "CXN_KILLED_STALE_ITT_TTT_RCVD", | |
184 | "CXN_KILLED_INVALID_ITT_TTT_RCVD", | |
185 | "CXN_KILLED_RST_RCVD", | |
186 | "CXN_KILLED_TIMED_OUT", | |
187 | "CXN_KILLED_RST_SENT", | |
188 | "CXN_KILLED_FIN_RCVD", | |
189 | "CXN_KILLED_BAD_UNSOL_PDU_RCVD", | |
190 | "CXN_KILLED_BAD_WRB_INDEX_ERROR", | |
191 | "CXN_KILLED_OVER_RUN_RESIDUAL", | |
192 | "CXN_KILLED_UNDER_RUN_RESIDUAL", | |
193 | "CMD_KILLED_INVALID_STATSN_RCVD", | |
194 | "CMD_KILLED_INVALID_R2T_RCVD", | |
195 | "CMD_CXN_KILLED_LUN_INVALID", | |
196 | "CMD_CXN_KILLED_ICD_INVALID", | |
197 | "CMD_CXN_KILLED_ITT_INVALID", | |
198 | "CMD_CXN_KILLED_SEQ_OUTOFORDER", | |
199 | "CMD_CXN_KILLED_INVALID_DATASN_RCVD", | |
200 | "CXN_INVALIDATE_NOTIFY", | |
201 | "CXN_INVALIDATE_INDEX_NOTIFY", | |
202 | "CMD_INVALIDATED_NOTIFY", | |
203 | "UNSOL_HDR_NOTIFY", | |
204 | "UNSOL_DATA_NOTIFY", | |
205 | "UNSOL_DATA_DIGEST_ERROR_NOTIFY", | |
206 | "DRIVERMSG_NOTIFY", | |
207 | "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN", | |
208 | "SOL_CMD_KILLED_DIF_ERR", | |
209 | "CXN_KILLED_SYN_RCVD", | |
210 | "CXN_KILLED_IMM_DATA_RCVD" | |
211 | }; | |
212 | ||
6733b39a JK |
213 | static int beiscsi_slave_configure(struct scsi_device *sdev) |
214 | { | |
215 | blk_queue_max_segment_size(sdev->request_queue, 65536); | |
216 | return 0; | |
217 | } | |
218 | ||
4183122d JK |
219 | static int beiscsi_eh_abort(struct scsi_cmnd *sc) |
220 | { | |
faa0a22d | 221 | struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr; |
4183122d | 222 | struct iscsi_cls_session *cls_session; |
faa0a22d | 223 | struct beiscsi_io_task *abrt_io_task; |
4183122d | 224 | struct beiscsi_conn *beiscsi_conn; |
4183122d | 225 | struct iscsi_session *session; |
f3505013 | 226 | struct invldt_cmd_tbl inv_tbl; |
faa0a22d JB |
227 | struct beiscsi_hba *phba; |
228 | struct iscsi_conn *conn; | |
1957aa7f | 229 | int rc; |
4183122d JK |
230 | |
231 | cls_session = starget_to_session(scsi_target(sc->device)); | |
232 | session = cls_session->dd_data; | |
233 | ||
faa0a22d JB |
234 | /* check if we raced, task just got cleaned up under us */ |
235 | spin_lock_bh(&session->back_lock); | |
236 | if (!abrt_task || !abrt_task->sc) { | |
237 | spin_unlock_bh(&session->back_lock); | |
4183122d JK |
238 | return SUCCESS; |
239 | } | |
faa0a22d JB |
240 | /* get a task ref till FW processes the req for the ICD used */ |
241 | __iscsi_get_task(abrt_task); | |
242 | abrt_io_task = abrt_task->dd_data; | |
243 | conn = abrt_task->conn; | |
4183122d JK |
244 | beiscsi_conn = conn->dd_data; |
245 | phba = beiscsi_conn->phba; | |
faa0a22d | 246 | /* mark WRB invalid which have been not processed by FW yet */ |
f3505013 | 247 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
faa0a22d JB |
248 | abrt_io_task->pwrb_handle->pwrb, 1); |
249 | inv_tbl.cid = beiscsi_conn->beiscsi_conn_cid; | |
250 | inv_tbl.icd = abrt_io_task->psgl_handle->sgl_index; | |
251 | spin_unlock_bh(&session->back_lock); | |
252 | ||
98713216 | 253 | rc = beiscsi_mgmt_invalidate_icds(phba, &inv_tbl, 1); |
faa0a22d | 254 | iscsi_put_task(abrt_task); |
98713216 | 255 | if (rc) { |
99bc5d55 | 256 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
98713216 JB |
257 | "BM_%d : sc %p invalidation failed %d\n", |
258 | sc, rc); | |
4183122d | 259 | return FAILED; |
4183122d | 260 | } |
e175defe | 261 | |
4183122d JK |
262 | return iscsi_eh_abort(sc); |
263 | } | |
264 | ||
265 | static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) | |
266 | { | |
98713216 JB |
267 | struct beiscsi_invldt_cmd_tbl { |
268 | struct invldt_cmd_tbl tbl[BE_INVLDT_CMD_TBL_SZ]; | |
269 | struct iscsi_task *task[BE_INVLDT_CMD_TBL_SZ]; | |
270 | } *inv_tbl; | |
271 | struct iscsi_cls_session *cls_session; | |
4183122d | 272 | struct beiscsi_conn *beiscsi_conn; |
98713216 | 273 | struct beiscsi_io_task *io_task; |
4183122d | 274 | struct iscsi_session *session; |
98713216 JB |
275 | struct beiscsi_hba *phba; |
276 | struct iscsi_conn *conn; | |
277 | struct iscsi_task *task; | |
278 | unsigned int i, nents; | |
f3505013 | 279 | int rc, more = 0; |
4183122d | 280 | |
4183122d JK |
281 | cls_session = starget_to_session(scsi_target(sc->device)); |
282 | session = cls_session->dd_data; | |
98713216 | 283 | |
659743b0 | 284 | spin_lock_bh(&session->frwd_lock); |
db7f7709 | 285 | if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { |
659743b0 | 286 | spin_unlock_bh(&session->frwd_lock); |
db7f7709 JK |
287 | return FAILED; |
288 | } | |
98713216 | 289 | |
4183122d JK |
290 | conn = session->leadconn; |
291 | beiscsi_conn = conn->dd_data; | |
292 | phba = beiscsi_conn->phba; | |
f3505013 | 293 | |
98713216 | 294 | inv_tbl = kzalloc(sizeof(*inv_tbl), GFP_KERNEL); |
f3505013 JB |
295 | if (!inv_tbl) { |
296 | spin_unlock_bh(&session->frwd_lock); | |
297 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, | |
298 | "BM_%d : invldt_cmd_tbl alloc failed\n"); | |
299 | return FAILED; | |
300 | } | |
301 | nents = 0; | |
98713216 JB |
302 | /* take back_lock to prevent task from getting cleaned up under us */ |
303 | spin_lock(&session->back_lock); | |
4183122d | 304 | for (i = 0; i < conn->session->cmds_max; i++) { |
98713216 JB |
305 | task = conn->session->cmds[i]; |
306 | if (!task->sc) | |
4183122d JK |
307 | continue; |
308 | ||
98713216 | 309 | if (sc->device->lun != task->sc->device->lun) |
4183122d | 310 | continue; |
f3505013 JB |
311 | /** |
312 | * Can't fit in more cmds? Normally this won't happen b'coz | |
313 | * BEISCSI_CMD_PER_LUN is same as BE_INVLDT_CMD_TBL_SZ. | |
314 | */ | |
315 | if (nents == BE_INVLDT_CMD_TBL_SZ) { | |
316 | more = 1; | |
317 | break; | |
318 | } | |
4183122d | 319 | |
98713216 JB |
320 | /* get a task ref till FW processes the req for the ICD used */ |
321 | __iscsi_get_task(task); | |
322 | io_task = task->dd_data; | |
323 | /* mark WRB invalid which have been not processed by FW yet */ | |
7626c06b | 324 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
98713216 | 325 | io_task->pwrb_handle->pwrb, |
7626c06b JK |
326 | 1); |
327 | ||
98713216 JB |
328 | inv_tbl->tbl[nents].cid = beiscsi_conn->beiscsi_conn_cid; |
329 | inv_tbl->tbl[nents].icd = io_task->psgl_handle->sgl_index; | |
330 | inv_tbl->task[nents] = task; | |
f3505013 | 331 | nents++; |
4183122d | 332 | } |
98713216 | 333 | spin_unlock_bh(&session->back_lock); |
659743b0 | 334 | spin_unlock_bh(&session->frwd_lock); |
4183122d | 335 | |
98713216 JB |
336 | rc = SUCCESS; |
337 | if (!nents) | |
338 | goto end_reset; | |
339 | ||
f3505013 JB |
340 | if (more) { |
341 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, | |
342 | "BM_%d : number of cmds exceeds size of invalidation table\n"); | |
98713216 JB |
343 | rc = FAILED; |
344 | goto end_reset; | |
f3505013 JB |
345 | } |
346 | ||
98713216 | 347 | if (beiscsi_mgmt_invalidate_icds(phba, &inv_tbl->tbl[0], nents)) { |
99bc5d55 | 348 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
98713216 JB |
349 | "BM_%d : cid %u scmds invalidation failed\n", |
350 | beiscsi_conn->beiscsi_conn_cid); | |
351 | rc = FAILED; | |
4183122d | 352 | } |
e175defe | 353 | |
98713216 JB |
354 | end_reset: |
355 | for (i = 0; i < nents; i++) | |
356 | iscsi_put_task(inv_tbl->task[i]); | |
357 | kfree(inv_tbl); | |
358 | ||
359 | if (rc == SUCCESS) | |
360 | rc = iscsi_eh_device_reset(sc); | |
361 | return rc; | |
4183122d JK |
362 | } |
363 | ||
bfead3b2 | 364 | /*------------------- PCI Driver operations and data ----------------- */ |
9baa3c34 | 365 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
bfead3b2 | 366 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
f98c96b0 | 367 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
bfead3b2 JK |
368 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
369 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, | |
370 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, | |
139a1b1e | 371 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
bfead3b2 JK |
372 | { 0 } |
373 | }; | |
374 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); | |
375 | ||
99bc5d55 | 376 | |
6733b39a JK |
377 | static struct scsi_host_template beiscsi_sht = { |
378 | .module = THIS_MODULE, | |
c4f39bda | 379 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
6733b39a JK |
380 | .proc_name = DRV_NAME, |
381 | .queuecommand = iscsi_queuecommand, | |
db5ed4df | 382 | .change_queue_depth = scsi_change_queue_depth, |
6733b39a JK |
383 | .slave_configure = beiscsi_slave_configure, |
384 | .target_alloc = iscsi_target_alloc, | |
4183122d JK |
385 | .eh_abort_handler = beiscsi_eh_abort, |
386 | .eh_device_reset_handler = beiscsi_eh_device_reset, | |
309ce156 | 387 | .eh_target_reset_handler = iscsi_eh_session_reset, |
99bc5d55 | 388 | .shost_attrs = beiscsi_attrs, |
6733b39a JK |
389 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
390 | .can_queue = BE2_IO_DEPTH, | |
391 | .this_id = -1, | |
392 | .max_sectors = BEISCSI_MAX_SECTORS, | |
393 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, | |
394 | .use_clustering = ENABLE_CLUSTERING, | |
ffce3e2e | 395 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
c40ecc12 | 396 | .track_queue_depth = 1, |
6733b39a | 397 | }; |
6733b39a | 398 | |
bfead3b2 | 399 | static struct scsi_transport_template *beiscsi_scsi_transport; |
6733b39a JK |
400 | |
401 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) | |
402 | { | |
403 | struct beiscsi_hba *phba; | |
404 | struct Scsi_Host *shost; | |
405 | ||
406 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); | |
407 | if (!shost) { | |
99bc5d55 JSJ |
408 | dev_err(&pcidev->dev, |
409 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); | |
6733b39a JK |
410 | return NULL; |
411 | } | |
6733b39a JK |
412 | shost->max_id = BE2_MAX_SESSIONS; |
413 | shost->max_channel = 0; | |
414 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; | |
415 | shost->max_lun = BEISCSI_NUM_MAX_LUN; | |
416 | shost->transportt = beiscsi_scsi_transport; | |
6733b39a JK |
417 | phba = iscsi_host_priv(shost); |
418 | memset(phba, 0, sizeof(*phba)); | |
419 | phba->shost = shost; | |
420 | phba->pcidev = pci_dev_get(pcidev); | |
2807afb7 | 421 | pci_set_drvdata(pcidev, phba); |
0e43895e | 422 | phba->interface_handle = 0xFFFFFFFF; |
6733b39a | 423 | |
6733b39a | 424 | return phba; |
6733b39a JK |
425 | } |
426 | ||
427 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) | |
428 | { | |
429 | if (phba->csr_va) { | |
430 | iounmap(phba->csr_va); | |
431 | phba->csr_va = NULL; | |
432 | } | |
433 | if (phba->db_va) { | |
434 | iounmap(phba->db_va); | |
435 | phba->db_va = NULL; | |
436 | } | |
437 | if (phba->pci_va) { | |
438 | iounmap(phba->pci_va); | |
439 | phba->pci_va = NULL; | |
440 | } | |
441 | } | |
442 | ||
443 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, | |
444 | struct pci_dev *pcidev) | |
445 | { | |
446 | u8 __iomem *addr; | |
f98c96b0 | 447 | int pcicfg_reg; |
6733b39a JK |
448 | |
449 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), | |
450 | pci_resource_len(pcidev, 2)); | |
451 | if (addr == NULL) | |
452 | return -ENOMEM; | |
453 | phba->ctrl.csr = addr; | |
454 | phba->csr_va = addr; | |
455 | phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2); | |
456 | ||
457 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); | |
458 | if (addr == NULL) | |
459 | goto pci_map_err; | |
460 | phba->ctrl.db = addr; | |
461 | phba->db_va = addr; | |
462 | phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4); | |
463 | ||
f98c96b0 JK |
464 | if (phba->generation == BE_GEN2) |
465 | pcicfg_reg = 1; | |
466 | else | |
467 | pcicfg_reg = 0; | |
468 | ||
469 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), | |
470 | pci_resource_len(pcidev, pcicfg_reg)); | |
471 | ||
6733b39a JK |
472 | if (addr == NULL) |
473 | goto pci_map_err; | |
474 | phba->ctrl.pcicfg = addr; | |
475 | phba->pci_va = addr; | |
f98c96b0 | 476 | phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg); |
6733b39a JK |
477 | return 0; |
478 | ||
479 | pci_map_err: | |
480 | beiscsi_unmap_pci_function(phba); | |
481 | return -ENOMEM; | |
482 | } | |
483 | ||
484 | static int beiscsi_enable_pci(struct pci_dev *pcidev) | |
485 | { | |
486 | int ret; | |
487 | ||
488 | ret = pci_enable_device(pcidev); | |
489 | if (ret) { | |
99bc5d55 JSJ |
490 | dev_err(&pcidev->dev, |
491 | "beiscsi_enable_pci - enable device failed\n"); | |
6733b39a JK |
492 | return ret; |
493 | } | |
494 | ||
e307f3ac JSJ |
495 | ret = pci_request_regions(pcidev, DRV_NAME); |
496 | if (ret) { | |
497 | dev_err(&pcidev->dev, | |
498 | "beiscsi_enable_pci - request region failed\n"); | |
499 | goto pci_dev_disable; | |
500 | } | |
501 | ||
bfead3b2 | 502 | pci_set_master(pcidev); |
6c57625b JK |
503 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64)); |
504 | if (ret) { | |
505 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)); | |
506 | if (ret) { | |
507 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); | |
e307f3ac | 508 | goto pci_region_release; |
6c57625b JK |
509 | } else { |
510 | ret = pci_set_consistent_dma_mask(pcidev, | |
511 | DMA_BIT_MASK(32)); | |
512 | } | |
513 | } else { | |
514 | ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); | |
6733b39a JK |
515 | if (ret) { |
516 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); | |
e307f3ac | 517 | goto pci_region_release; |
6733b39a JK |
518 | } |
519 | } | |
520 | return 0; | |
e307f3ac JSJ |
521 | |
522 | pci_region_release: | |
523 | pci_release_regions(pcidev); | |
524 | pci_dev_disable: | |
525 | pci_disable_device(pcidev); | |
526 | ||
527 | return ret; | |
6733b39a JK |
528 | } |
529 | ||
530 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) | |
531 | { | |
532 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
533 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; | |
534 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; | |
535 | int status = 0; | |
536 | ||
537 | ctrl->pdev = pdev; | |
538 | status = beiscsi_map_pci_bars(phba, pdev); | |
539 | if (status) | |
540 | return status; | |
6733b39a JK |
541 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
542 | mbox_mem_alloc->va = pci_alloc_consistent(pdev, | |
543 | mbox_mem_alloc->size, | |
544 | &mbox_mem_alloc->dma); | |
545 | if (!mbox_mem_alloc->va) { | |
546 | beiscsi_unmap_pci_function(phba); | |
a49e06d5 | 547 | return -ENOMEM; |
6733b39a JK |
548 | } |
549 | ||
550 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); | |
551 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); | |
552 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); | |
553 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); | |
c03a50f7 | 554 | mutex_init(&ctrl->mbox_lock); |
bfead3b2 | 555 | spin_lock_init(&phba->ctrl.mcc_lock); |
bfead3b2 | 556 | |
6733b39a JK |
557 | return status; |
558 | } | |
559 | ||
843ae752 JK |
560 | /** |
561 | * beiscsi_get_params()- Set the config paramters | |
562 | * @phba: ptr device priv structure | |
563 | **/ | |
6733b39a JK |
564 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
565 | { | |
843ae752 JK |
566 | uint32_t total_cid_count = 0; |
567 | uint32_t total_icd_count = 0; | |
568 | uint8_t ulp_num = 0; | |
569 | ||
570 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + | |
571 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); | |
572 | ||
cf987b79 JK |
573 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
574 | uint32_t align_mask = 0; | |
575 | uint32_t icd_post_per_page = 0; | |
576 | uint32_t icd_count_unavailable = 0; | |
577 | uint32_t icd_start = 0, icd_count = 0; | |
578 | uint32_t icd_start_align = 0, icd_count_align = 0; | |
579 | ||
843ae752 | 580 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
cf987b79 JK |
581 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
582 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; | |
583 | ||
584 | /* Get ICD count that can be posted on each page */ | |
585 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * | |
586 | sizeof(struct iscsi_sge))); | |
587 | align_mask = (icd_post_per_page - 1); | |
588 | ||
589 | /* Check if icd_start is aligned ICD per page posting */ | |
590 | if (icd_start % icd_post_per_page) { | |
591 | icd_start_align = ((icd_start + | |
592 | icd_post_per_page) & | |
593 | ~(align_mask)); | |
594 | phba->fw_config. | |
595 | iscsi_icd_start[ulp_num] = | |
596 | icd_start_align; | |
597 | } | |
598 | ||
599 | icd_count_align = (icd_count & ~align_mask); | |
600 | ||
601 | /* ICD discarded in the process of alignment */ | |
602 | if (icd_start_align) | |
603 | icd_count_unavailable = ((icd_start_align - | |
604 | icd_start) + | |
605 | (icd_count - | |
606 | icd_count_align)); | |
607 | ||
608 | /* Updated ICD count available */ | |
609 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - | |
610 | icd_count_unavailable); | |
611 | ||
612 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
613 | "BM_%d : Aligned ICD values\n" | |
614 | "\t ICD Start : %d\n" | |
615 | "\t ICD Count : %d\n" | |
616 | "\t ICD Discarded : %d\n", | |
617 | phba->fw_config. | |
618 | iscsi_icd_start[ulp_num], | |
619 | phba->fw_config. | |
620 | iscsi_icd_count[ulp_num], | |
621 | icd_count_unavailable); | |
843ae752 JK |
622 | break; |
623 | } | |
cf987b79 | 624 | } |
843ae752 | 625 | |
cf987b79 | 626 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
843ae752 JK |
627 | phba->params.ios_per_ctrl = (total_icd_count - |
628 | (total_cid_count + | |
629 | BE2_TMFS + BE2_NOPOUT_REQ)); | |
630 | phba->params.cxns_per_ctrl = total_cid_count; | |
631 | phba->params.asyncpdus_per_ctrl = total_cid_count; | |
632 | phba->params.icds_per_ctrl = total_icd_count; | |
6733b39a JK |
633 | phba->params.num_sge_per_io = BE2_SGE; |
634 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; | |
635 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; | |
636 | phba->params.eq_timer = 64; | |
843ae752 JK |
637 | phba->params.num_eq_entries = 1024; |
638 | phba->params.num_cq_entries = 1024; | |
6733b39a JK |
639 | phba->params.wrbs_per_cxn = 256; |
640 | } | |
641 | ||
642 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, | |
643 | unsigned int id, unsigned int clr_interrupt, | |
644 | unsigned int num_processed, | |
645 | unsigned char rearm, unsigned char event) | |
646 | { | |
647 | u32 val = 0; | |
e08b3c8b | 648 | |
6733b39a JK |
649 | if (rearm) |
650 | val |= 1 << DB_EQ_REARM_SHIFT; | |
651 | if (clr_interrupt) | |
652 | val |= 1 << DB_EQ_CLR_SHIFT; | |
653 | if (event) | |
654 | val |= 1 << DB_EQ_EVNT_SHIFT; | |
e08b3c8b | 655 | |
6733b39a | 656 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
e08b3c8b JK |
657 | /* Setting lower order EQ_ID Bits */ |
658 | val |= (id & DB_EQ_RING_ID_LOW_MASK); | |
659 | ||
660 | /* Setting Higher order EQ_ID Bits */ | |
661 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & | |
662 | DB_EQ_RING_ID_HIGH_MASK) | |
663 | << DB_EQ_HIGH_SET_SHIFT); | |
664 | ||
6733b39a JK |
665 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
666 | } | |
667 | ||
bfead3b2 JK |
668 | /** |
669 | * be_isr_mcc - The isr routine of the driver. | |
670 | * @irq: Not used | |
671 | * @dev_id: Pointer to host adapter structure | |
672 | */ | |
673 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) | |
674 | { | |
675 | struct beiscsi_hba *phba; | |
a3095016 | 676 | struct be_eq_entry *eqe; |
bfead3b2 JK |
677 | struct be_queue_info *eq; |
678 | struct be_queue_info *mcc; | |
a3095016 | 679 | unsigned int mcc_events; |
bfead3b2 | 680 | struct be_eq_obj *pbe_eq; |
bfead3b2 JK |
681 | |
682 | pbe_eq = dev_id; | |
683 | eq = &pbe_eq->q; | |
684 | phba = pbe_eq->phba; | |
685 | mcc = &phba->ctrl.mcc_obj.cq; | |
686 | eqe = queue_tail_node(eq); | |
bfead3b2 | 687 | |
a3095016 | 688 | mcc_events = 0; |
bfead3b2 JK |
689 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
690 | & EQE_VALID_MASK) { | |
691 | if (((eqe->dw[offsetof(struct amap_eq_entry, | |
692 | resource_id) / 32] & | |
693 | EQE_RESID_MASK) >> 16) == mcc->id) { | |
a3095016 | 694 | mcc_events++; |
bfead3b2 JK |
695 | } |
696 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); | |
697 | queue_tail_inc(eq); | |
698 | eqe = queue_tail_node(eq); | |
bfead3b2 | 699 | } |
bfead3b2 | 700 | |
a3095016 JB |
701 | if (mcc_events) { |
702 | queue_work(phba->wq, &pbe_eq->mcc_work); | |
703 | hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1); | |
704 | } | |
bfead3b2 JK |
705 | return IRQ_HANDLED; |
706 | } | |
707 | ||
708 | /** | |
709 | * be_isr_msix - The isr routine of the driver. | |
710 | * @irq: Not used | |
711 | * @dev_id: Pointer to host adapter structure | |
712 | */ | |
713 | static irqreturn_t be_isr_msix(int irq, void *dev_id) | |
714 | { | |
715 | struct beiscsi_hba *phba; | |
bfead3b2 | 716 | struct be_queue_info *eq; |
bfead3b2 | 717 | struct be_eq_obj *pbe_eq; |
bfead3b2 JK |
718 | |
719 | pbe_eq = dev_id; | |
720 | eq = &pbe_eq->q; | |
bfead3b2 JK |
721 | |
722 | phba = pbe_eq->phba; | |
1094cf68 JB |
723 | /* disable interrupt till iopoll completes */ |
724 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); | |
725 | irq_poll_sched(&pbe_eq->iopoll); | |
72fb46a9 JSJ |
726 | |
727 | return IRQ_HANDLED; | |
bfead3b2 JK |
728 | } |
729 | ||
6733b39a JK |
730 | /** |
731 | * be_isr - The isr routine of the driver. | |
732 | * @irq: Not used | |
733 | * @dev_id: Pointer to host adapter structure | |
734 | */ | |
735 | static irqreturn_t be_isr(int irq, void *dev_id) | |
736 | { | |
737 | struct beiscsi_hba *phba; | |
738 | struct hwi_controller *phwi_ctrlr; | |
739 | struct hwi_context_memory *phwi_context; | |
a3095016 | 740 | struct be_eq_entry *eqe; |
6733b39a | 741 | struct be_queue_info *eq; |
bfead3b2 | 742 | struct be_queue_info *mcc; |
a3095016 | 743 | unsigned int mcc_events, io_events; |
6733b39a | 744 | struct be_ctrl_info *ctrl; |
bfead3b2 | 745 | struct be_eq_obj *pbe_eq; |
a3095016 | 746 | int isr, rearm; |
6733b39a JK |
747 | |
748 | phba = dev_id; | |
6eab04a8 | 749 | ctrl = &phba->ctrl; |
bfead3b2 JK |
750 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
751 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); | |
752 | if (!isr) | |
753 | return IRQ_NONE; | |
6733b39a JK |
754 | |
755 | phwi_ctrlr = phba->phwi_ctrlr; | |
756 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
bfead3b2 JK |
757 | pbe_eq = &phwi_context->be_eq[0]; |
758 | ||
759 | eq = &phwi_context->be_eq[0].q; | |
760 | mcc = &phba->ctrl.mcc_obj.cq; | |
6733b39a | 761 | eqe = queue_tail_node(eq); |
6733b39a | 762 | |
a3095016 JB |
763 | io_events = 0; |
764 | mcc_events = 0; | |
89f8b33c JA |
765 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
766 | & EQE_VALID_MASK) { | |
767 | if (((eqe->dw[offsetof(struct amap_eq_entry, | |
a3095016 JB |
768 | resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id) |
769 | mcc_events++; | |
770 | else | |
771 | io_events++; | |
89f8b33c JA |
772 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
773 | queue_tail_inc(eq); | |
774 | eqe = queue_tail_node(eq); | |
775 | } | |
a3095016 | 776 | if (!io_events && !mcc_events) |
89f8b33c | 777 | return IRQ_NONE; |
a3095016 JB |
778 | |
779 | /* no need to rearm if interrupt is only for IOs */ | |
780 | rearm = 0; | |
781 | if (mcc_events) { | |
782 | queue_work(phba->wq, &pbe_eq->mcc_work); | |
783 | /* rearm for MCCQ */ | |
784 | rearm = 1; | |
785 | } | |
786 | if (io_events) | |
787 | irq_poll_sched(&pbe_eq->iopoll); | |
788 | hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1); | |
789 | return IRQ_HANDLED; | |
6733b39a JK |
790 | } |
791 | ||
1094cf68 | 792 | |
6733b39a JK |
793 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
794 | { | |
795 | struct pci_dev *pcidev = phba->pcidev; | |
bfead3b2 JK |
796 | struct hwi_controller *phwi_ctrlr; |
797 | struct hwi_context_memory *phwi_context; | |
4f5af07e | 798 | int ret, msix_vec, i, j; |
6733b39a | 799 | |
bfead3b2 JK |
800 | phwi_ctrlr = phba->phwi_ctrlr; |
801 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
802 | ||
803 | if (phba->msix_enabled) { | |
804 | for (i = 0; i < phba->num_cpus; i++) { | |
8fcfb210 JK |
805 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, |
806 | GFP_KERNEL); | |
807 | if (!phba->msi_name[i]) { | |
808 | ret = -ENOMEM; | |
809 | goto free_msix_irqs; | |
810 | } | |
811 | ||
812 | sprintf(phba->msi_name[i], "beiscsi_%02x_%02x", | |
813 | phba->shost->host_no, i); | |
bfead3b2 | 814 | msix_vec = phba->msix_entries[i].vector; |
8fcfb210 JK |
815 | ret = request_irq(msix_vec, be_isr_msix, 0, |
816 | phba->msi_name[i], | |
bfead3b2 | 817 | &phwi_context->be_eq[i]); |
4f5af07e | 818 | if (ret) { |
99bc5d55 JSJ |
819 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
820 | "BM_%d : beiscsi_init_irqs-Failed to" | |
821 | "register msix for i = %d\n", | |
822 | i); | |
8fcfb210 | 823 | kfree(phba->msi_name[i]); |
4f5af07e JK |
824 | goto free_msix_irqs; |
825 | } | |
bfead3b2 | 826 | } |
8fcfb210 JK |
827 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL); |
828 | if (!phba->msi_name[i]) { | |
829 | ret = -ENOMEM; | |
830 | goto free_msix_irqs; | |
831 | } | |
832 | sprintf(phba->msi_name[i], "beiscsi_mcc_%02x", | |
833 | phba->shost->host_no); | |
bfead3b2 | 834 | msix_vec = phba->msix_entries[i].vector; |
8fcfb210 | 835 | ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i], |
bfead3b2 | 836 | &phwi_context->be_eq[i]); |
4f5af07e | 837 | if (ret) { |
99bc5d55 JSJ |
838 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
839 | "BM_%d : beiscsi_init_irqs-" | |
840 | "Failed to register beiscsi_msix_mcc\n"); | |
8fcfb210 | 841 | kfree(phba->msi_name[i]); |
4f5af07e JK |
842 | goto free_msix_irqs; |
843 | } | |
844 | ||
bfead3b2 JK |
845 | } else { |
846 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, | |
847 | "beiscsi", phba); | |
848 | if (ret) { | |
99bc5d55 JSJ |
849 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
850 | "BM_%d : beiscsi_init_irqs-" | |
851 | "Failed to register irq\\n"); | |
bfead3b2 JK |
852 | return ret; |
853 | } | |
6733b39a JK |
854 | } |
855 | return 0; | |
4f5af07e | 856 | free_msix_irqs: |
8fcfb210 JK |
857 | for (j = i - 1; j >= 0; j--) { |
858 | kfree(phba->msi_name[j]); | |
859 | msix_vec = phba->msix_entries[j].vector; | |
4f5af07e | 860 | free_irq(msix_vec, &phwi_context->be_eq[j]); |
8fcfb210 | 861 | } |
4f5af07e | 862 | return ret; |
6733b39a JK |
863 | } |
864 | ||
e08b3c8b | 865 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
6733b39a | 866 | unsigned int id, unsigned int num_processed, |
1094cf68 | 867 | unsigned char rearm) |
6733b39a JK |
868 | { |
869 | u32 val = 0; | |
e08b3c8b | 870 | |
6733b39a JK |
871 | if (rearm) |
872 | val |= 1 << DB_CQ_REARM_SHIFT; | |
e08b3c8b | 873 | |
6733b39a | 874 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
e08b3c8b JK |
875 | |
876 | /* Setting lower order CQ_ID Bits */ | |
877 | val |= (id & DB_CQ_RING_ID_LOW_MASK); | |
878 | ||
879 | /* Setting Higher order CQ_ID Bits */ | |
880 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & | |
881 | DB_CQ_RING_ID_HIGH_MASK) | |
882 | << DB_CQ_HIGH_SET_SHIFT); | |
883 | ||
6733b39a JK |
884 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
885 | } | |
886 | ||
6733b39a JK |
887 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
888 | { | |
889 | struct sgl_handle *psgl_handle; | |
7d2c0d64 | 890 | unsigned long flags; |
6733b39a | 891 | |
7d2c0d64 | 892 | spin_lock_irqsave(&phba->io_sgl_lock, flags); |
6733b39a | 893 | if (phba->io_sgl_hndl_avbl) { |
99bc5d55 JSJ |
894 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
895 | "BM_%d : In alloc_io_sgl_handle," | |
896 | " io_sgl_alloc_index=%d\n", | |
897 | phba->io_sgl_alloc_index); | |
898 | ||
6733b39a JK |
899 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
900 | io_sgl_alloc_index]; | |
901 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; | |
902 | phba->io_sgl_hndl_avbl--; | |
bfead3b2 JK |
903 | if (phba->io_sgl_alloc_index == (phba->params. |
904 | ios_per_ctrl - 1)) | |
6733b39a JK |
905 | phba->io_sgl_alloc_index = 0; |
906 | else | |
907 | phba->io_sgl_alloc_index++; | |
908 | } else | |
909 | psgl_handle = NULL; | |
7d2c0d64 | 910 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
6733b39a JK |
911 | return psgl_handle; |
912 | } | |
913 | ||
914 | static void | |
915 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) | |
916 | { | |
7d2c0d64 JB |
917 | unsigned long flags; |
918 | ||
919 | spin_lock_irqsave(&phba->io_sgl_lock, flags); | |
99bc5d55 JSJ |
920 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
921 | "BM_%d : In free_,io_sgl_free_index=%d\n", | |
922 | phba->io_sgl_free_index); | |
923 | ||
6733b39a JK |
924 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
925 | /* | |
926 | * this can happen if clean_task is called on a task that | |
927 | * failed in xmit_task or alloc_pdu. | |
928 | */ | |
99bc5d55 JSJ |
929 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
930 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d," | |
931 | "value there=%p\n", phba->io_sgl_free_index, | |
932 | phba->io_sgl_hndl_base | |
933 | [phba->io_sgl_free_index]); | |
7d2c0d64 | 934 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
6733b39a JK |
935 | return; |
936 | } | |
937 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; | |
938 | phba->io_sgl_hndl_avbl++; | |
939 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) | |
940 | phba->io_sgl_free_index = 0; | |
941 | else | |
942 | phba->io_sgl_free_index++; | |
7d2c0d64 | 943 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
6733b39a JK |
944 | } |
945 | ||
cb564c6b JB |
946 | static inline struct wrb_handle * |
947 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, | |
948 | unsigned int wrbs_per_cxn) | |
949 | { | |
950 | struct wrb_handle *pwrb_handle; | |
7d2c0d64 | 951 | unsigned long flags; |
cb564c6b | 952 | |
7d2c0d64 | 953 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); |
cb564c6b JB |
954 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
955 | pwrb_context->wrb_handles_available--; | |
956 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) | |
957 | pwrb_context->alloc_index = 0; | |
958 | else | |
959 | pwrb_context->alloc_index++; | |
7d2c0d64 | 960 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
bf9b7554 JB |
961 | |
962 | if (pwrb_handle) | |
963 | memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); | |
cb564c6b JB |
964 | |
965 | return pwrb_handle; | |
966 | } | |
967 | ||
6733b39a JK |
968 | /** |
969 | * alloc_wrb_handle - To allocate a wrb handle | |
970 | * @phba: The hba pointer | |
971 | * @cid: The cid to use for allocation | |
340c99e9 | 972 | * @pwrb_context: ptr to ptr to wrb context |
6733b39a JK |
973 | * |
974 | * This happens under session_lock until submission to chip | |
975 | */ | |
340c99e9 | 976 | struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, |
cb564c6b | 977 | struct hwi_wrb_context **pcontext) |
6733b39a JK |
978 | { |
979 | struct hwi_wrb_context *pwrb_context; | |
980 | struct hwi_controller *phwi_ctrlr; | |
a7909b39 | 981 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
6733b39a JK |
982 | |
983 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 | 984 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
cb564c6b JB |
985 | /* return the context address */ |
986 | *pcontext = pwrb_context; | |
987 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); | |
988 | } | |
340c99e9 | 989 | |
cb564c6b JB |
990 | static inline void |
991 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, | |
992 | struct wrb_handle *pwrb_handle, | |
993 | unsigned int wrbs_per_cxn) | |
994 | { | |
7d2c0d64 JB |
995 | unsigned long flags; |
996 | ||
997 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); | |
cb564c6b JB |
998 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
999 | pwrb_context->wrb_handles_available++; | |
1000 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) | |
1001 | pwrb_context->free_index = 0; | |
1002 | else | |
1003 | pwrb_context->free_index++; | |
7d2c0d64 | 1004 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
6733b39a JK |
1005 | } |
1006 | ||
1007 | /** | |
1008 | * free_wrb_handle - To free the wrb handle back to pool | |
1009 | * @phba: The hba pointer | |
1010 | * @pwrb_context: The context to free from | |
1011 | * @pwrb_handle: The wrb_handle to free | |
1012 | * | |
1013 | * This happens under session_lock until submission to chip | |
1014 | */ | |
1015 | static void | |
1016 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, | |
1017 | struct wrb_handle *pwrb_handle) | |
1018 | { | |
cb564c6b JB |
1019 | beiscsi_put_wrb_handle(pwrb_context, |
1020 | pwrb_handle, | |
1021 | phba->params.wrbs_per_cxn); | |
99bc5d55 JSJ |
1022 | beiscsi_log(phba, KERN_INFO, |
1023 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
1024 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" | |
1025 | "wrb_handles_available=%d\n", | |
1026 | pwrb_handle, pwrb_context->free_index, | |
1027 | pwrb_context->wrb_handles_available); | |
6733b39a JK |
1028 | } |
1029 | ||
1030 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) | |
1031 | { | |
1032 | struct sgl_handle *psgl_handle; | |
7d2c0d64 | 1033 | unsigned long flags; |
6733b39a | 1034 | |
7d2c0d64 | 1035 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); |
6733b39a JK |
1036 | if (phba->eh_sgl_hndl_avbl) { |
1037 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; | |
1038 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; | |
99bc5d55 JSJ |
1039 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
1040 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", | |
1041 | phba->eh_sgl_alloc_index, | |
1042 | phba->eh_sgl_alloc_index); | |
1043 | ||
6733b39a JK |
1044 | phba->eh_sgl_hndl_avbl--; |
1045 | if (phba->eh_sgl_alloc_index == | |
1046 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - | |
1047 | 1)) | |
1048 | phba->eh_sgl_alloc_index = 0; | |
1049 | else | |
1050 | phba->eh_sgl_alloc_index++; | |
1051 | } else | |
1052 | psgl_handle = NULL; | |
7d2c0d64 | 1053 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
6733b39a JK |
1054 | return psgl_handle; |
1055 | } | |
1056 | ||
1057 | void | |
1058 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) | |
1059 | { | |
7d2c0d64 JB |
1060 | unsigned long flags; |
1061 | ||
1062 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); | |
99bc5d55 JSJ |
1063 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
1064 | "BM_%d : In free_mgmt_sgl_handle," | |
1065 | "eh_sgl_free_index=%d\n", | |
1066 | phba->eh_sgl_free_index); | |
1067 | ||
6733b39a JK |
1068 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
1069 | /* | |
1070 | * this can happen if clean_task is called on a task that | |
1071 | * failed in xmit_task or alloc_pdu. | |
1072 | */ | |
99bc5d55 JSJ |
1073 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
1074 | "BM_%d : Double Free in eh SGL ," | |
1075 | "eh_sgl_free_index=%d\n", | |
1076 | phba->eh_sgl_free_index); | |
7d2c0d64 | 1077 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
6733b39a JK |
1078 | return; |
1079 | } | |
1080 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; | |
1081 | phba->eh_sgl_hndl_avbl++; | |
1082 | if (phba->eh_sgl_free_index == | |
1083 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) | |
1084 | phba->eh_sgl_free_index = 0; | |
1085 | else | |
1086 | phba->eh_sgl_free_index++; | |
7d2c0d64 | 1087 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
6733b39a JK |
1088 | } |
1089 | ||
1090 | static void | |
1091 | be_complete_io(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1092 | struct iscsi_task *task, |
1093 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1094 | { |
1095 | struct beiscsi_io_task *io_task = task->dd_data; | |
1096 | struct be_status_bhs *sts_bhs = | |
1097 | (struct be_status_bhs *)io_task->cmd_bhs; | |
1098 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
6733b39a JK |
1099 | unsigned char *sense; |
1100 | u32 resid = 0, exp_cmdsn, max_cmdsn; | |
1101 | u8 rsp, status, flags; | |
1102 | ||
73133261 JSJ |
1103 | exp_cmdsn = csol_cqe->exp_cmdsn; |
1104 | max_cmdsn = (csol_cqe->exp_cmdsn + | |
1105 | csol_cqe->cmd_wnd - 1); | |
1106 | rsp = csol_cqe->i_resp; | |
1107 | status = csol_cqe->i_sts; | |
1108 | flags = csol_cqe->i_flags; | |
1109 | resid = csol_cqe->res_cnt; | |
1110 | ||
bd535451 | 1111 | if (!task->sc) { |
da334977 | 1112 | if (io_task->scsi_cmnd) { |
bd535451 | 1113 | scsi_dma_unmap(io_task->scsi_cmnd); |
da334977 JK |
1114 | io_task->scsi_cmnd = NULL; |
1115 | } | |
6733b39a | 1116 | |
bd535451 JK |
1117 | return; |
1118 | } | |
6733b39a JK |
1119 | task->sc->result = (DID_OK << 16) | status; |
1120 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { | |
1121 | task->sc->result = DID_ERROR << 16; | |
1122 | goto unmap; | |
1123 | } | |
1124 | ||
1125 | /* bidi not initially supported */ | |
1126 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { | |
6733b39a JK |
1127 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
1128 | task->sc->result = DID_ERROR << 16; | |
1129 | ||
1130 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { | |
1131 | scsi_set_resid(task->sc, resid); | |
1132 | if (!status && (scsi_bufflen(task->sc) - resid < | |
1133 | task->sc->underflow)) | |
1134 | task->sc->result = DID_ERROR << 16; | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | if (status == SAM_STAT_CHECK_CONDITION) { | |
4053a4be | 1139 | u16 sense_len; |
bfead3b2 | 1140 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
4053a4be | 1141 | |
6733b39a | 1142 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
4053a4be | 1143 | sense_len = be16_to_cpu(*slen); |
6733b39a JK |
1144 | memcpy(task->sc->sense_buffer, sense, |
1145 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); | |
1146 | } | |
756d29c8 | 1147 | |
73133261 JSJ |
1148 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
1149 | conn->rxdata_octets += resid; | |
6733b39a | 1150 | unmap: |
eb1c4692 JSJ |
1151 | if (io_task->scsi_cmnd) { |
1152 | scsi_dma_unmap(io_task->scsi_cmnd); | |
1153 | io_task->scsi_cmnd = NULL; | |
1154 | } | |
6733b39a JK |
1155 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
1156 | } | |
1157 | ||
1158 | static void | |
1159 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1160 | struct iscsi_task *task, |
1161 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1162 | { |
1163 | struct iscsi_logout_rsp *hdr; | |
bfead3b2 | 1164 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1165 | struct iscsi_conn *conn = beiscsi_conn->conn; |
1166 | ||
1167 | hdr = (struct iscsi_logout_rsp *)task->hdr; | |
7bd6e25c | 1168 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
6733b39a JK |
1169 | hdr->t2wait = 5; |
1170 | hdr->t2retain = 0; | |
73133261 JSJ |
1171 | hdr->flags = csol_cqe->i_flags; |
1172 | hdr->response = csol_cqe->i_resp; | |
702dc5e8 JK |
1173 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
1174 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + | |
1175 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1176 | |
7bd6e25c JK |
1177 | hdr->dlength[0] = 0; |
1178 | hdr->dlength[1] = 0; | |
1179 | hdr->dlength[2] = 0; | |
6733b39a | 1180 | hdr->hlength = 0; |
bfead3b2 | 1181 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1182 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1183 | } | |
1184 | ||
1185 | static void | |
1186 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1187 | struct iscsi_task *task, |
1188 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1189 | { |
1190 | struct iscsi_tm_rsp *hdr; | |
1191 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
bfead3b2 | 1192 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1193 | |
1194 | hdr = (struct iscsi_tm_rsp *)task->hdr; | |
7bd6e25c | 1195 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
73133261 JSJ |
1196 | hdr->flags = csol_cqe->i_flags; |
1197 | hdr->response = csol_cqe->i_resp; | |
702dc5e8 JK |
1198 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
1199 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + | |
1200 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1201 | |
bfead3b2 | 1202 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1203 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1204 | } | |
1205 | ||
1206 | static void | |
1207 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, | |
1208 | struct beiscsi_hba *phba, struct sol_cqe *psol) | |
1209 | { | |
1210 | struct hwi_wrb_context *pwrb_context; | |
e1f9d31e | 1211 | uint16_t wrb_index, cid, cri_index; |
6733b39a | 1212 | struct hwi_controller *phwi_ctrlr; |
e1f9d31e | 1213 | struct wrb_handle *pwrb_handle; |
bfead3b2 | 1214 | struct iscsi_task *task; |
6733b39a JK |
1215 | |
1216 | phwi_ctrlr = phba->phwi_ctrlr; | |
2c9dfd36 JK |
1217 | if (is_chip_be2_be3r(phba)) { |
1218 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, | |
73133261 | 1219 | wrb_idx, psol); |
2c9dfd36 | 1220 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
73133261 JSJ |
1221 | cid, psol); |
1222 | } else { | |
2c9dfd36 | 1223 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
73133261 | 1224 | wrb_idx, psol); |
2c9dfd36 | 1225 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
73133261 JSJ |
1226 | cid, psol); |
1227 | } | |
1228 | ||
a7909b39 JK |
1229 | cri_index = BE_GET_CRI_FROM_CID(cid); |
1230 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; | |
73133261 | 1231 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
32951dd8 | 1232 | task = pwrb_handle->pio_handle; |
4a4a11b9 | 1233 | iscsi_put_task(task); |
6733b39a JK |
1234 | } |
1235 | ||
1236 | static void | |
1237 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1238 | struct iscsi_task *task, |
1239 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1240 | { |
1241 | struct iscsi_nopin *hdr; | |
1242 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
bfead3b2 | 1243 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1244 | |
1245 | hdr = (struct iscsi_nopin *)task->hdr; | |
73133261 JSJ |
1246 | hdr->flags = csol_cqe->i_flags; |
1247 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); | |
702dc5e8 JK |
1248 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
1249 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1250 | |
6733b39a | 1251 | hdr->opcode = ISCSI_OP_NOOP_IN; |
bfead3b2 | 1252 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1253 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1254 | } | |
1255 | ||
73133261 JSJ |
1256 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
1257 | struct sol_cqe *psol, | |
1258 | struct common_sol_cqe *csol_cqe) | |
1259 | { | |
2c9dfd36 JK |
1260 | if (is_chip_be2_be3r(phba)) { |
1261 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, | |
1262 | i_exp_cmd_sn, psol); | |
1263 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, | |
1264 | i_res_cnt, psol); | |
1265 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, | |
1266 | i_cmd_wnd, psol); | |
1267 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, | |
1268 | wrb_index, psol); | |
1269 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, | |
1270 | cid, psol); | |
1271 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, | |
1272 | hw_sts, psol); | |
1273 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, | |
1274 | i_resp, psol); | |
1275 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, | |
1276 | i_sts, psol); | |
1277 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, | |
1278 | i_flags, psol); | |
1279 | } else { | |
73133261 JSJ |
1280 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
1281 | i_exp_cmd_sn, psol); | |
1282 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1283 | i_res_cnt, psol); | |
1284 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1285 | wrb_index, psol); | |
1286 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1287 | cid, psol); | |
1288 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1289 | hw_sts, psol); | |
702dc5e8 | 1290 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
73133261 JSJ |
1291 | i_cmd_wnd, psol); |
1292 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1293 | cmd_cmpl, psol)) | |
1294 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1295 | i_sts, psol); | |
1296 | else | |
1297 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1298 | i_sts, psol); | |
1299 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1300 | u, psol)) | |
1301 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; | |
1302 | ||
1303 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1304 | o, psol)) | |
1305 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; | |
73133261 JSJ |
1306 | } |
1307 | } | |
1308 | ||
1309 | ||
6733b39a JK |
1310 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
1311 | struct beiscsi_hba *phba, struct sol_cqe *psol) | |
1312 | { | |
1313 | struct hwi_wrb_context *pwrb_context; | |
1314 | struct wrb_handle *pwrb_handle; | |
1315 | struct iscsi_wrb *pwrb = NULL; | |
1316 | struct hwi_controller *phwi_ctrlr; | |
1317 | struct iscsi_task *task; | |
bfead3b2 | 1318 | unsigned int type; |
6733b39a JK |
1319 | struct iscsi_conn *conn = beiscsi_conn->conn; |
1320 | struct iscsi_session *session = conn->session; | |
73133261 | 1321 | struct common_sol_cqe csol_cqe = {0}; |
a7909b39 | 1322 | uint16_t cri_index = 0; |
6733b39a JK |
1323 | |
1324 | phwi_ctrlr = phba->phwi_ctrlr; | |
73133261 JSJ |
1325 | |
1326 | /* Copy the elements to a common structure */ | |
1327 | adapter_get_sol_cqe(phba, psol, &csol_cqe); | |
1328 | ||
a7909b39 JK |
1329 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
1330 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; | |
73133261 JSJ |
1331 | |
1332 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ | |
1333 | csol_cqe.wrb_index]; | |
1334 | ||
32951dd8 JK |
1335 | task = pwrb_handle->pio_handle; |
1336 | pwrb = pwrb_handle->pwrb; | |
73133261 | 1337 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
32951dd8 | 1338 | |
659743b0 | 1339 | spin_lock_bh(&session->back_lock); |
bfead3b2 | 1340 | switch (type) { |
6733b39a JK |
1341 | case HWH_TYPE_IO: |
1342 | case HWH_TYPE_IO_RD: | |
1343 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == | |
dafab8e0 | 1344 | ISCSI_OP_NOOP_OUT) |
73133261 | 1345 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
dafab8e0 | 1346 | else |
73133261 | 1347 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1348 | break; |
1349 | ||
1350 | case HWH_TYPE_LOGOUT: | |
dafab8e0 | 1351 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
73133261 | 1352 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
dafab8e0 | 1353 | else |
73133261 | 1354 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1355 | break; |
1356 | ||
1357 | case HWH_TYPE_LOGIN: | |
99bc5d55 JSJ |
1358 | beiscsi_log(phba, KERN_ERR, |
1359 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1360 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" | |
1361 | " hwi_complete_cmd- Solicited path\n"); | |
6733b39a JK |
1362 | break; |
1363 | ||
6733b39a | 1364 | case HWH_TYPE_NOP: |
73133261 | 1365 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1366 | break; |
1367 | ||
1368 | default: | |
99bc5d55 JSJ |
1369 | beiscsi_log(phba, KERN_WARNING, |
1370 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1371 | "BM_%d : In hwi_complete_cmd, unknown type = %d" | |
1372 | "wrb_index 0x%x CID 0x%x\n", type, | |
73133261 JSJ |
1373 | csol_cqe.wrb_index, |
1374 | csol_cqe.cid); | |
6733b39a JK |
1375 | break; |
1376 | } | |
35e66019 | 1377 | |
659743b0 | 1378 | spin_unlock_bh(&session->back_lock); |
6733b39a JK |
1379 | } |
1380 | ||
938f372c JB |
1381 | /** |
1382 | * ASYNC PDUs include | |
1383 | * a. Unsolicited NOP-In (target initiated NOP-In) | |
1384 | * b. ASYNC Messages | |
1385 | * c. Reject PDU | |
1386 | * d. Login response | |
1387 | * These headers arrive unprocessed by the EP firmware. | |
1388 | * iSCSI layer processes them. | |
1389 | */ | |
1390 | static unsigned int | |
1391 | beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn, | |
1392 | struct pdu_base *phdr, void *pdata, unsigned int dlen) | |
6733b39a | 1393 | { |
938f372c JB |
1394 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1395 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
1396 | struct beiscsi_io_task *io_task; | |
1397 | struct iscsi_hdr *login_hdr; | |
1398 | struct iscsi_task *task; | |
1399 | u8 code; | |
1400 | ||
1401 | code = AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr); | |
1402 | switch (code) { | |
1403 | case ISCSI_OP_NOOP_IN: | |
1404 | pdata = NULL; | |
1405 | dlen = 0; | |
1406 | break; | |
1407 | case ISCSI_OP_ASYNC_EVENT: | |
1408 | break; | |
1409 | case ISCSI_OP_REJECT: | |
1410 | WARN_ON(!pdata); | |
1411 | WARN_ON(!(dlen == 48)); | |
1412 | beiscsi_log(phba, KERN_ERR, | |
1413 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1414 | "BM_%d : In ISCSI_OP_REJECT\n"); | |
1415 | break; | |
1416 | case ISCSI_OP_LOGIN_RSP: | |
1417 | case ISCSI_OP_TEXT_RSP: | |
1418 | task = conn->login_task; | |
1419 | io_task = task->dd_data; | |
1420 | login_hdr = (struct iscsi_hdr *)phdr; | |
1421 | login_hdr->itt = io_task->libiscsi_itt; | |
1422 | break; | |
1423 | default: | |
1424 | beiscsi_log(phba, KERN_WARNING, | |
1425 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
1426 | "BM_%d : unrecognized async PDU opcode 0x%x\n", | |
1427 | code); | |
1428 | return 1; | |
1429 | } | |
1430 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)phdr, pdata, dlen); | |
1431 | return 0; | |
1432 | } | |
1433 | ||
1434 | static inline void | |
1435 | beiscsi_hdl_put_handle(struct hd_async_context *pasync_ctx, | |
1436 | struct hd_async_handle *pasync_handle) | |
1437 | { | |
1438 | if (pasync_handle->is_header) { | |
1439 | list_add_tail(&pasync_handle->link, | |
1440 | &pasync_ctx->async_header.free_list); | |
1441 | pasync_ctx->async_header.free_entries++; | |
1442 | } else { | |
1443 | list_add_tail(&pasync_handle->link, | |
1444 | &pasync_ctx->async_data.free_list); | |
1445 | pasync_ctx->async_data.free_entries++; | |
1446 | } | |
6733b39a JK |
1447 | } |
1448 | ||
938f372c JB |
1449 | static struct hd_async_handle * |
1450 | beiscsi_hdl_get_handle(struct beiscsi_conn *beiscsi_conn, | |
1451 | struct hd_async_context *pasync_ctx, | |
1452 | struct i_t_dpdu_cqe *pdpdu_cqe) | |
6733b39a | 1453 | { |
938f372c JB |
1454 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1455 | struct hd_async_handle *pasync_handle; | |
6733b39a | 1456 | struct be_bus_address phys_addr; |
938f372c JB |
1457 | u8 final, error = 0; |
1458 | u16 cid, code, ci; | |
1459 | u32 dpl; | |
73133261 | 1460 | |
938f372c JB |
1461 | cid = beiscsi_conn->beiscsi_conn_cid; |
1462 | /** | |
1463 | * This function is invoked to get the right async_handle structure | |
1464 | * from a given DEF PDU CQ entry. | |
1465 | * | |
1466 | * - index in CQ entry gives the vertical index | |
1467 | * - address in CQ entry is the offset where the DMA last ended | |
1468 | * - final - no more notifications for this PDU | |
1469 | */ | |
2c9dfd36 JK |
1470 | if (is_chip_be2_be3r(phba)) { |
1471 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
73133261 | 1472 | dpl, pdpdu_cqe); |
938f372c | 1473 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
73133261 | 1474 | index, pdpdu_cqe); |
938f372c JB |
1475 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
1476 | final, pdpdu_cqe); | |
73133261 | 1477 | } else { |
2c9dfd36 | 1478 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
73133261 | 1479 | dpl, pdpdu_cqe); |
938f372c | 1480 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
73133261 | 1481 | index, pdpdu_cqe); |
938f372c JB |
1482 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
1483 | final, pdpdu_cqe); | |
73133261 | 1484 | } |
6733b39a | 1485 | |
938f372c JB |
1486 | /** |
1487 | * DB addr Hi/Lo is same for BE and SKH. | |
1488 | * Subtract the dataplacementlength to get to the base. | |
1489 | */ | |
1490 | phys_addr.u.a32.address_lo = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
1491 | db_addr_lo, pdpdu_cqe); | |
1492 | phys_addr.u.a32.address_lo -= dpl; | |
1493 | phys_addr.u.a32.address_hi = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
1494 | db_addr_hi, pdpdu_cqe); | |
1495 | ||
1496 | code = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, code, pdpdu_cqe); | |
1497 | switch (code) { | |
6733b39a | 1498 | case UNSOL_HDR_NOTIFY: |
938f372c | 1499 | pasync_handle = pasync_ctx->async_entry[ci].header; |
6733b39a | 1500 | break; |
938f372c JB |
1501 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
1502 | error = 1; | |
6733b39a | 1503 | case UNSOL_DATA_NOTIFY: |
938f372c | 1504 | pasync_handle = pasync_ctx->async_entry[ci].data; |
6733b39a | 1505 | break; |
938f372c | 1506 | /* called only for above codes */ |
6733b39a | 1507 | default: |
938f372c JB |
1508 | pasync_handle = NULL; |
1509 | break; | |
6733b39a JK |
1510 | } |
1511 | ||
938f372c JB |
1512 | if (!pasync_handle) { |
1513 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1514 | "BM_%d : cid %d async PDU handle not found - code %d ci %d addr %llx\n", | |
1515 | cid, code, ci, phys_addr.u.a64.address); | |
1516 | return pasync_handle; | |
6733b39a JK |
1517 | } |
1518 | ||
938f372c JB |
1519 | if (pasync_handle->pa.u.a64.address != phys_addr.u.a64.address || |
1520 | pasync_handle->index != ci) { | |
1521 | /* driver bug - if ci does not match async handle index */ | |
1522 | error = 1; | |
1523 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1524 | "BM_%d : cid %u async PDU handle mismatch - addr in %cQE %llx at %u:addr in CQE %llx ci %u\n", | |
1525 | cid, pasync_handle->is_header ? 'H' : 'D', | |
1526 | pasync_handle->pa.u.a64.address, | |
1527 | pasync_handle->index, | |
1528 | phys_addr.u.a64.address, ci); | |
1529 | /* FW has stale address - attempt continuing by dropping */ | |
1530 | } | |
6733b39a | 1531 | |
938f372c JB |
1532 | /** |
1533 | * Each CID is associated with unique CRI. | |
1534 | * ASYNC_CRI_FROM_CID mapping and CRI_FROM_CID are totaly different. | |
1535 | **/ | |
1536 | pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(cid); | |
1537 | pasync_handle->is_final = final; | |
73133261 | 1538 | pasync_handle->buffer_len = dpl; |
938f372c JB |
1539 | /* empty the slot */ |
1540 | if (pasync_handle->is_header) | |
1541 | pasync_ctx->async_entry[ci].header = NULL; | |
1542 | else | |
1543 | pasync_ctx->async_entry[ci].data = NULL; | |
6733b39a | 1544 | |
938f372c JB |
1545 | /** |
1546 | * DEF PDU header and data buffers with errors should be simply | |
1547 | * dropped as there are no consumers for it. | |
1548 | */ | |
1549 | if (error) { | |
1550 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
1551 | pasync_handle = NULL; | |
1552 | } | |
6733b39a JK |
1553 | return pasync_handle; |
1554 | } | |
1555 | ||
938f372c JB |
1556 | static void |
1557 | beiscsi_hdl_purge_handles(struct beiscsi_hba *phba, | |
1558 | struct hd_async_context *pasync_ctx, | |
1559 | u16 cri) | |
6733b39a | 1560 | { |
938f372c JB |
1561 | struct hd_async_handle *pasync_handle, *tmp_handle; |
1562 | struct list_head *plist; | |
6733b39a | 1563 | |
938f372c JB |
1564 | plist = &pasync_ctx->async_entry[cri].wq.list; |
1565 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) { | |
1566 | list_del(&pasync_handle->link); | |
1567 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
6733b39a JK |
1568 | } |
1569 | ||
938f372c JB |
1570 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wq.list); |
1571 | pasync_ctx->async_entry[cri].wq.hdr_len = 0; | |
1572 | pasync_ctx->async_entry[cri].wq.bytes_received = 0; | |
1573 | pasync_ctx->async_entry[cri].wq.bytes_needed = 0; | |
6733b39a JK |
1574 | } |
1575 | ||
938f372c JB |
1576 | static unsigned int |
1577 | beiscsi_hdl_fwd_pdu(struct beiscsi_conn *beiscsi_conn, | |
1578 | struct hd_async_context *pasync_ctx, | |
1579 | u16 cri) | |
6733b39a | 1580 | { |
938f372c JB |
1581 | struct iscsi_session *session = beiscsi_conn->conn->session; |
1582 | struct hd_async_handle *pasync_handle, *plast_handle; | |
1583 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
1584 | void *phdr = NULL, *pdata = NULL; | |
1585 | u32 dlen = 0, status = 0; | |
6733b39a | 1586 | struct list_head *plist; |
6733b39a | 1587 | |
938f372c JB |
1588 | plist = &pasync_ctx->async_entry[cri].wq.list; |
1589 | plast_handle = NULL; | |
1590 | list_for_each_entry(pasync_handle, plist, link) { | |
1591 | plast_handle = pasync_handle; | |
1592 | /* get the header, the first entry */ | |
1593 | if (!phdr) { | |
1594 | phdr = pasync_handle->pbuffer; | |
1595 | continue; | |
6733b39a | 1596 | } |
938f372c JB |
1597 | /* use first buffer to collect all the data */ |
1598 | if (!pdata) { | |
1599 | pdata = pasync_handle->pbuffer; | |
1600 | dlen = pasync_handle->buffer_len; | |
1601 | continue; | |
1602 | } | |
1603 | memcpy(pdata + dlen, pasync_handle->pbuffer, | |
1604 | pasync_handle->buffer_len); | |
1605 | dlen += pasync_handle->buffer_len; | |
6733b39a JK |
1606 | } |
1607 | ||
938f372c JB |
1608 | if (!plast_handle->is_final) { |
1609 | /* last handle should have final PDU notification from FW */ | |
1610 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1611 | "BM_%d : cid %u %p fwd async PDU with last handle missing - HL%u:DN%u:DR%u\n", | |
1612 | beiscsi_conn->beiscsi_conn_cid, plast_handle, | |
1613 | pasync_ctx->async_entry[cri].wq.hdr_len, | |
1614 | pasync_ctx->async_entry[cri].wq.bytes_needed, | |
1615 | pasync_ctx->async_entry[cri].wq.bytes_received); | |
1616 | } | |
1617 | spin_lock_bh(&session->back_lock); | |
1618 | status = beiscsi_complete_pdu(beiscsi_conn, phdr, pdata, dlen); | |
1619 | spin_unlock_bh(&session->back_lock); | |
1620 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); | |
1621 | return status; | |
6733b39a JK |
1622 | } |
1623 | ||
938f372c JB |
1624 | static unsigned int |
1625 | beiscsi_hdl_gather_pdu(struct beiscsi_conn *beiscsi_conn, | |
1626 | struct hd_async_context *pasync_ctx, | |
1627 | struct hd_async_handle *pasync_handle) | |
6733b39a | 1628 | { |
938f372c JB |
1629 | unsigned int bytes_needed = 0, status = 0; |
1630 | u16 cri = pasync_handle->cri; | |
1631 | struct cri_wait_queue *wq; | |
1632 | struct beiscsi_hba *phba; | |
1633 | struct pdu_base *ppdu; | |
1634 | char *err = ""; | |
6733b39a | 1635 | |
938f372c JB |
1636 | phba = beiscsi_conn->phba; |
1637 | wq = &pasync_ctx->async_entry[cri].wq; | |
1638 | if (pasync_handle->is_header) { | |
1639 | /* check if PDU hdr is rcv'd when old hdr not completed */ | |
1640 | if (wq->hdr_len) { | |
1641 | err = "incomplete"; | |
1642 | goto drop_pdu; | |
1643 | } | |
1644 | ppdu = pasync_handle->pbuffer; | |
1645 | bytes_needed = AMAP_GET_BITS(struct amap_pdu_base, | |
1646 | data_len_hi, ppdu); | |
1647 | bytes_needed <<= 16; | |
1648 | bytes_needed |= be16_to_cpu(AMAP_GET_BITS(struct amap_pdu_base, | |
1649 | data_len_lo, ppdu)); | |
1650 | wq->hdr_len = pasync_handle->buffer_len; | |
1651 | wq->bytes_received = 0; | |
1652 | wq->bytes_needed = bytes_needed; | |
1653 | list_add_tail(&pasync_handle->link, &wq->list); | |
1654 | if (!bytes_needed) | |
1655 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, | |
1656 | pasync_ctx, cri); | |
1657 | } else { | |
1658 | /* check if data received has header and is needed */ | |
1659 | if (!wq->hdr_len || !wq->bytes_needed) { | |
1660 | err = "header less"; | |
1661 | goto drop_pdu; | |
1662 | } | |
1663 | wq->bytes_received += pasync_handle->buffer_len; | |
1664 | /* Something got overwritten? Better catch it here. */ | |
1665 | if (wq->bytes_received > wq->bytes_needed) { | |
1666 | err = "overflow"; | |
1667 | goto drop_pdu; | |
1668 | } | |
1669 | list_add_tail(&pasync_handle->link, &wq->list); | |
1670 | if (wq->bytes_received == wq->bytes_needed) | |
1671 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, | |
1672 | pasync_ctx, cri); | |
1673 | } | |
1674 | return status; | |
6733b39a | 1675 | |
938f372c JB |
1676 | drop_pdu: |
1677 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1678 | "BM_%d : cid %u async PDU %s - def-%c:HL%u:DN%u:DR%u\n", | |
1679 | beiscsi_conn->beiscsi_conn_cid, err, | |
1680 | pasync_handle->is_header ? 'H' : 'D', | |
1681 | wq->hdr_len, wq->bytes_needed, | |
1682 | pasync_handle->buffer_len); | |
1683 | /* discard this handle */ | |
1684 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
1685 | /* free all the other handles in cri_wait_queue */ | |
1686 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); | |
1687 | /* try continuing */ | |
1688 | return status; | |
6733b39a JK |
1689 | } |
1690 | ||
938f372c JB |
1691 | static void |
1692 | beiscsi_hdq_post_handles(struct beiscsi_hba *phba, | |
1693 | u8 header, u8 ulp_num) | |
6733b39a | 1694 | { |
938f372c JB |
1695 | struct hd_async_handle *pasync_handle, *tmp, **slot; |
1696 | struct hd_async_context *pasync_ctx; | |
6733b39a | 1697 | struct hwi_controller *phwi_ctrlr; |
938f372c | 1698 | struct list_head *hfree_list; |
6733b39a | 1699 | struct phys_addr *pasync_sge; |
938f372c JB |
1700 | u32 ring_id, doorbell = 0; |
1701 | u16 index, num_entries; | |
1702 | u32 doorbell_offset; | |
1703 | u16 prod = 0, cons; | |
6733b39a JK |
1704 | |
1705 | phwi_ctrlr = phba->phwi_ctrlr; | |
8a86e833 | 1706 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
dc63aac6 | 1707 | num_entries = pasync_ctx->num_entries; |
938f372c JB |
1708 | if (header) { |
1709 | cons = pasync_ctx->async_header.free_entries; | |
1710 | hfree_list = &pasync_ctx->async_header.free_list; | |
8a86e833 JK |
1711 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
1712 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. | |
938f372c | 1713 | doorbell_offset; |
6733b39a | 1714 | } else { |
938f372c JB |
1715 | cons = pasync_ctx->async_data.free_entries; |
1716 | hfree_list = &pasync_ctx->async_data.free_list; | |
8a86e833 JK |
1717 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
1718 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. | |
938f372c | 1719 | doorbell_offset; |
6733b39a | 1720 | } |
938f372c JB |
1721 | /* number of entries posted must be in multiples of 8 */ |
1722 | if (cons % 8) | |
1723 | return; | |
6733b39a | 1724 | |
938f372c JB |
1725 | list_for_each_entry_safe(pasync_handle, tmp, hfree_list, link) { |
1726 | list_del_init(&pasync_handle->link); | |
1727 | pasync_handle->is_final = 0; | |
1728 | pasync_handle->buffer_len = 0; | |
6733b39a | 1729 | |
938f372c JB |
1730 | /* handles can be consumed out of order, use index in handle */ |
1731 | index = pasync_handle->index; | |
1732 | WARN_ON(pasync_handle->is_header != header); | |
1733 | if (header) | |
1734 | slot = &pasync_ctx->async_entry[index].header; | |
1735 | else | |
1736 | slot = &pasync_ctx->async_entry[index].data; | |
1737 | /** | |
1738 | * The slot just tracks handle's hold and release, so | |
1739 | * overwriting at the same index won't do any harm but | |
1740 | * needs to be caught. | |
1741 | */ | |
1742 | if (*slot != NULL) { | |
1743 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1744 | "BM_%d : async PDU %s slot at %u not empty\n", | |
1745 | header ? "header" : "data", index); | |
6733b39a | 1746 | } |
938f372c JB |
1747 | /** |
1748 | * We use same freed index as in completion to post so this | |
1749 | * operation is not required for refills. Its required only | |
1750 | * for ring creation. | |
1751 | */ | |
1752 | if (header) | |
1753 | pasync_sge = pasync_ctx->async_header.ring_base; | |
1754 | else | |
1755 | pasync_sge = pasync_ctx->async_data.ring_base; | |
1756 | pasync_sge += index; | |
1757 | /* if its a refill then address is same; hi is lo */ | |
1758 | WARN_ON(pasync_sge->hi && | |
1759 | pasync_sge->hi != pasync_handle->pa.u.a32.address_lo); | |
1760 | WARN_ON(pasync_sge->lo && | |
1761 | pasync_sge->lo != pasync_handle->pa.u.a32.address_hi); | |
1762 | pasync_sge->hi = pasync_handle->pa.u.a32.address_lo; | |
1763 | pasync_sge->lo = pasync_handle->pa.u.a32.address_hi; | |
1764 | ||
1765 | *slot = pasync_handle; | |
1766 | if (++prod == cons) | |
1767 | break; | |
6733b39a | 1768 | } |
938f372c JB |
1769 | if (header) |
1770 | pasync_ctx->async_header.free_entries -= prod; | |
1771 | else | |
1772 | pasync_ctx->async_data.free_entries -= prod; | |
6733b39a | 1773 | |
938f372c JB |
1774 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
1775 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; | |
1776 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; | |
1777 | doorbell |= (prod & DB_DEF_PDU_CQPROC_MASK) << DB_DEF_PDU_CQPROC_SHIFT; | |
1778 | iowrite32(doorbell, phba->db_va + doorbell_offset); | |
6733b39a JK |
1779 | } |
1780 | ||
938f372c JB |
1781 | static void |
1782 | beiscsi_hdq_process_compl(struct beiscsi_conn *beiscsi_conn, | |
1783 | struct i_t_dpdu_cqe *pdpdu_cqe) | |
6733b39a | 1784 | { |
938f372c JB |
1785 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1786 | struct hd_async_handle *pasync_handle = NULL; | |
1787 | struct hd_async_context *pasync_ctx; | |
6733b39a | 1788 | struct hwi_controller *phwi_ctrlr; |
938f372c JB |
1789 | u16 cid_cri; |
1790 | u8 ulp_num; | |
6733b39a JK |
1791 | |
1792 | phwi_ctrlr = phba->phwi_ctrlr; | |
938f372c JB |
1793 | cid_cri = BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid); |
1794 | ulp_num = BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cid_cri); | |
1795 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); | |
1796 | pasync_handle = beiscsi_hdl_get_handle(beiscsi_conn, pasync_ctx, | |
1797 | pdpdu_cqe); | |
1798 | if (!pasync_handle) | |
1799 | return; | |
99bc5d55 | 1800 | |
938f372c JB |
1801 | beiscsi_hdl_gather_pdu(beiscsi_conn, pasync_ctx, pasync_handle); |
1802 | beiscsi_hdq_post_handles(phba, pasync_handle->is_header, ulp_num); | |
6733b39a JK |
1803 | } |
1804 | ||
2e4e8f65 | 1805 | void beiscsi_process_mcc_cq(struct beiscsi_hba *phba) |
756d29c8 JK |
1806 | { |
1807 | struct be_queue_info *mcc_cq; | |
1808 | struct be_mcc_compl *mcc_compl; | |
1809 | unsigned int num_processed = 0; | |
1810 | ||
1811 | mcc_cq = &phba->ctrl.mcc_obj.cq; | |
1812 | mcc_compl = queue_tail_node(mcc_cq); | |
1813 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); | |
1814 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { | |
9122e991 JB |
1815 | if (beiscsi_hba_in_error(phba)) |
1816 | return; | |
1817 | ||
756d29c8 JK |
1818 | if (num_processed >= 32) { |
1819 | hwi_ring_cq_db(phba, mcc_cq->id, | |
1094cf68 | 1820 | num_processed, 0); |
756d29c8 JK |
1821 | num_processed = 0; |
1822 | } | |
1823 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { | |
53aefe25 | 1824 | beiscsi_process_async_event(phba, mcc_compl); |
756d29c8 | 1825 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
2e4e8f65 | 1826 | beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl); |
756d29c8 JK |
1827 | } |
1828 | ||
1829 | mcc_compl->flags = 0; | |
1830 | queue_tail_inc(mcc_cq); | |
1831 | mcc_compl = queue_tail_node(mcc_cq); | |
1832 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); | |
1833 | num_processed++; | |
1834 | } | |
1835 | ||
1836 | if (num_processed > 0) | |
1094cf68 | 1837 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
756d29c8 | 1838 | } |
bfead3b2 | 1839 | |
a3095016 JB |
1840 | static void beiscsi_mcc_work(struct work_struct *work) |
1841 | { | |
1842 | struct be_eq_obj *pbe_eq; | |
1843 | struct beiscsi_hba *phba; | |
1844 | ||
1845 | pbe_eq = container_of(work, struct be_eq_obj, mcc_work); | |
1846 | phba = pbe_eq->phba; | |
1847 | beiscsi_process_mcc_cq(phba); | |
1848 | /* rearm EQ for further interrupts */ | |
9122e991 JB |
1849 | if (!beiscsi_hba_in_error(phba)) |
1850 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); | |
a3095016 JB |
1851 | } |
1852 | ||
6763daae JSJ |
1853 | /** |
1854 | * beiscsi_process_cq()- Process the Completion Queue | |
1855 | * @pbe_eq: Event Q on which the Completion has come | |
1094cf68 | 1856 | * @budget: Max number of events to processed |
6763daae JSJ |
1857 | * |
1858 | * return | |
1859 | * Number of Completion Entries processed. | |
1860 | **/ | |
1094cf68 | 1861 | unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget) |
6733b39a | 1862 | { |
6733b39a JK |
1863 | struct be_queue_info *cq; |
1864 | struct sol_cqe *sol; | |
1865 | struct dmsg_cqe *dmsg; | |
1094cf68 | 1866 | unsigned int total = 0; |
6733b39a | 1867 | unsigned int num_processed = 0; |
0a513dd8 | 1868 | unsigned short code = 0, cid = 0; |
a7909b39 | 1869 | uint16_t cri_index = 0; |
6733b39a | 1870 | struct beiscsi_conn *beiscsi_conn; |
c2462288 JK |
1871 | struct beiscsi_endpoint *beiscsi_ep; |
1872 | struct iscsi_endpoint *ep; | |
bfead3b2 | 1873 | struct beiscsi_hba *phba; |
6733b39a | 1874 | |
bfead3b2 | 1875 | cq = pbe_eq->cq; |
6733b39a | 1876 | sol = queue_tail_node(cq); |
bfead3b2 | 1877 | phba = pbe_eq->phba; |
6733b39a JK |
1878 | |
1879 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & | |
1880 | CQE_VALID_MASK) { | |
9122e991 JB |
1881 | if (beiscsi_hba_in_error(phba)) |
1882 | return 0; | |
1883 | ||
6733b39a JK |
1884 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
1885 | ||
73133261 JSJ |
1886 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / |
1887 | 32] & CQE_CODE_MASK); | |
1888 | ||
1889 | /* Get the CID */ | |
2c9dfd36 JK |
1890 | if (is_chip_be2_be3r(phba)) { |
1891 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); | |
1892 | } else { | |
73133261 JSJ |
1893 | if ((code == DRIVERMSG_NOTIFY) || |
1894 | (code == UNSOL_HDR_NOTIFY) || | |
1895 | (code == UNSOL_DATA_NOTIFY)) | |
1896 | cid = AMAP_GET_BITS( | |
1897 | struct amap_i_t_dpdu_cqe_v2, | |
1898 | cid, sol); | |
1899 | else | |
1900 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1901 | cid, sol); | |
2c9dfd36 | 1902 | } |
32951dd8 | 1903 | |
a7909b39 JK |
1904 | cri_index = BE_GET_CRI_FROM_CID(cid); |
1905 | ep = phba->ep_array[cri_index]; | |
b7ab35b1 JK |
1906 | |
1907 | if (ep == NULL) { | |
1908 | /* connection has already been freed | |
1909 | * just move on to next one | |
1910 | */ | |
1911 | beiscsi_log(phba, KERN_WARNING, | |
1912 | BEISCSI_LOG_INIT, | |
1913 | "BM_%d : proc cqe of disconn ep: cid %d\n", | |
1914 | cid); | |
1915 | goto proc_next_cqe; | |
1916 | } | |
1917 | ||
c2462288 JK |
1918 | beiscsi_ep = ep->dd_data; |
1919 | beiscsi_conn = beiscsi_ep->conn; | |
756d29c8 | 1920 | |
1094cf68 JB |
1921 | /* replenish cq */ |
1922 | if (num_processed == 32) { | |
1923 | hwi_ring_cq_db(phba, cq->id, 32, 0); | |
6733b39a JK |
1924 | num_processed = 0; |
1925 | } | |
1094cf68 | 1926 | total++; |
6733b39a | 1927 | |
0a513dd8 | 1928 | switch (code) { |
6733b39a JK |
1929 | case SOL_CMD_COMPLETE: |
1930 | hwi_complete_cmd(beiscsi_conn, phba, sol); | |
1931 | break; | |
1932 | case DRIVERMSG_NOTIFY: | |
99bc5d55 JSJ |
1933 | beiscsi_log(phba, KERN_INFO, |
1934 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1935 | "BM_%d : Received %s[%d] on CID : %d\n", |
1936 | cqe_desc[code], code, cid); | |
99bc5d55 | 1937 | |
6733b39a JK |
1938 | dmsg = (struct dmsg_cqe *)sol; |
1939 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); | |
1940 | break; | |
1941 | case UNSOL_HDR_NOTIFY: | |
99bc5d55 JSJ |
1942 | beiscsi_log(phba, KERN_INFO, |
1943 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1944 | "BM_%d : Received %s[%d] on CID : %d\n", |
1945 | cqe_desc[code], code, cid); | |
99bc5d55 | 1946 | |
8f09a3b9 | 1947 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
1948 | beiscsi_hdq_process_compl(beiscsi_conn, |
1949 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 1950 | spin_unlock_bh(&phba->async_pdu_lock); |
bfead3b2 | 1951 | break; |
6733b39a | 1952 | case UNSOL_DATA_NOTIFY: |
99bc5d55 JSJ |
1953 | beiscsi_log(phba, KERN_INFO, |
1954 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
6763daae JSJ |
1955 | "BM_%d : Received %s[%d] on CID : %d\n", |
1956 | cqe_desc[code], code, cid); | |
99bc5d55 | 1957 | |
8f09a3b9 | 1958 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
1959 | beiscsi_hdq_process_compl(beiscsi_conn, |
1960 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 1961 | spin_unlock_bh(&phba->async_pdu_lock); |
6733b39a JK |
1962 | break; |
1963 | case CXN_INVALIDATE_INDEX_NOTIFY: | |
1964 | case CMD_INVALIDATED_NOTIFY: | |
1965 | case CXN_INVALIDATE_NOTIFY: | |
99bc5d55 JSJ |
1966 | beiscsi_log(phba, KERN_ERR, |
1967 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1968 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
1969 | cqe_desc[code], code, cid); | |
6733b39a | 1970 | break; |
1094cf68 | 1971 | case CXN_KILLED_HDR_DIGEST_ERR: |
6733b39a | 1972 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
1094cf68 JB |
1973 | beiscsi_log(phba, KERN_ERR, |
1974 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1975 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", | |
1976 | cqe_desc[code], code, cid); | |
1977 | break; | |
6733b39a JK |
1978 | case CMD_KILLED_INVALID_STATSN_RCVD: |
1979 | case CMD_KILLED_INVALID_R2T_RCVD: | |
1980 | case CMD_CXN_KILLED_LUN_INVALID: | |
1981 | case CMD_CXN_KILLED_ICD_INVALID: | |
1982 | case CMD_CXN_KILLED_ITT_INVALID: | |
1983 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: | |
1984 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: | |
99bc5d55 JSJ |
1985 | beiscsi_log(phba, KERN_ERR, |
1986 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
6763daae JSJ |
1987 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
1988 | cqe_desc[code], code, cid); | |
6733b39a JK |
1989 | break; |
1990 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: | |
99bc5d55 JSJ |
1991 | beiscsi_log(phba, KERN_ERR, |
1992 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1993 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
1994 | cqe_desc[code], code, cid); | |
8f09a3b9 | 1995 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
1996 | /* driver consumes the entry and drops the contents */ |
1997 | beiscsi_hdq_process_compl(beiscsi_conn, | |
1998 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 1999 | spin_unlock_bh(&phba->async_pdu_lock); |
6733b39a JK |
2000 | break; |
2001 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: | |
2002 | case CXN_KILLED_BURST_LEN_MISMATCH: | |
2003 | case CXN_KILLED_AHS_RCVD: | |
6733b39a JK |
2004 | case CXN_KILLED_UNKNOWN_HDR: |
2005 | case CXN_KILLED_STALE_ITT_TTT_RCVD: | |
2006 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: | |
2007 | case CXN_KILLED_TIMED_OUT: | |
2008 | case CXN_KILLED_FIN_RCVD: | |
6763daae JSJ |
2009 | case CXN_KILLED_RST_SENT: |
2010 | case CXN_KILLED_RST_RCVD: | |
6733b39a JK |
2011 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
2012 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: | |
2013 | case CXN_KILLED_OVER_RUN_RESIDUAL: | |
2014 | case CXN_KILLED_UNDER_RUN_RESIDUAL: | |
2015 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: | |
99bc5d55 JSJ |
2016 | beiscsi_log(phba, KERN_ERR, |
2017 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
2018 | "BM_%d : Event %s[%d] received on CID : %d\n", |
2019 | cqe_desc[code], code, cid); | |
0a513dd8 JSJ |
2020 | if (beiscsi_conn) |
2021 | iscsi_conn_failure(beiscsi_conn->conn, | |
2022 | ISCSI_ERR_CONN_FAILED); | |
6733b39a JK |
2023 | break; |
2024 | default: | |
99bc5d55 JSJ |
2025 | beiscsi_log(phba, KERN_ERR, |
2026 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
2027 | "BM_%d : Invalid CQE Event Received Code : %d" |
2028 | "CID 0x%x...\n", | |
0a513dd8 | 2029 | code, cid); |
6733b39a JK |
2030 | break; |
2031 | } | |
2032 | ||
b7ab35b1 | 2033 | proc_next_cqe: |
6733b39a JK |
2034 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
2035 | queue_tail_inc(cq); | |
2036 | sol = queue_tail_node(cq); | |
2037 | num_processed++; | |
1094cf68 JB |
2038 | if (total == budget) |
2039 | break; | |
6733b39a JK |
2040 | } |
2041 | ||
1094cf68 JB |
2042 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
2043 | return total; | |
6733b39a JK |
2044 | } |
2045 | ||
511cbce2 | 2046 | static int be_iopoll(struct irq_poll *iop, int budget) |
6733b39a | 2047 | { |
a3095016 | 2048 | unsigned int ret, io_events; |
6733b39a | 2049 | struct beiscsi_hba *phba; |
bfead3b2 | 2050 | struct be_eq_obj *pbe_eq; |
1094cf68 JB |
2051 | struct be_eq_entry *eqe = NULL; |
2052 | struct be_queue_info *eq; | |
6733b39a | 2053 | |
bfead3b2 | 2054 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
1094cf68 | 2055 | phba = pbe_eq->phba; |
9122e991 JB |
2056 | if (beiscsi_hba_in_error(phba)) { |
2057 | irq_poll_complete(iop); | |
2058 | return 0; | |
2059 | } | |
2060 | ||
2061 | io_events = 0; | |
1094cf68 JB |
2062 | eq = &pbe_eq->q; |
2063 | eqe = queue_tail_node(eq); | |
1094cf68 JB |
2064 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
2065 | EQE_VALID_MASK) { | |
2066 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); | |
2067 | queue_tail_inc(eq); | |
2068 | eqe = queue_tail_node(eq); | |
a3095016 | 2069 | io_events++; |
1094cf68 | 2070 | } |
a3095016 | 2071 | hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1); |
1094cf68 JB |
2072 | |
2073 | ret = beiscsi_process_cq(pbe_eq, budget); | |
73af08e1 | 2074 | pbe_eq->cq_count += ret; |
6733b39a | 2075 | if (ret < budget) { |
511cbce2 | 2076 | irq_poll_complete(iop); |
99bc5d55 JSJ |
2077 | beiscsi_log(phba, KERN_INFO, |
2078 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1094cf68 JB |
2079 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
2080 | pbe_eq->q.id, ret); | |
9122e991 JB |
2081 | if (!beiscsi_hba_in_error(phba)) |
2082 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); | |
6733b39a JK |
2083 | } |
2084 | return ret; | |
2085 | } | |
2086 | ||
09a1093a JSJ |
2087 | static void |
2088 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, | |
2089 | unsigned int num_sg, struct beiscsi_io_task *io_task) | |
2090 | { | |
2091 | struct iscsi_sge *psgl; | |
2092 | unsigned int sg_len, index; | |
2093 | unsigned int sge_len = 0; | |
2094 | unsigned long long addr; | |
2095 | struct scatterlist *l_sg; | |
2096 | unsigned int offset; | |
2097 | ||
2098 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, | |
2099 | io_task->bhs_pa.u.a32.address_lo); | |
2100 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, | |
2101 | io_task->bhs_pa.u.a32.address_hi); | |
2102 | ||
2103 | l_sg = sg; | |
2104 | for (index = 0; (index < num_sg) && (index < 2); index++, | |
2105 | sg = sg_next(sg)) { | |
2106 | if (index == 0) { | |
2107 | sg_len = sg_dma_len(sg); | |
2108 | addr = (u64) sg_dma_address(sg); | |
2109 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2110 | sge0_addr_lo, pwrb, | |
2111 | lower_32_bits(addr)); | |
2112 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2113 | sge0_addr_hi, pwrb, | |
2114 | upper_32_bits(addr)); | |
2115 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2116 | sge0_len, pwrb, | |
2117 | sg_len); | |
2118 | sge_len = sg_len; | |
2119 | } else { | |
2120 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, | |
2121 | pwrb, sge_len); | |
2122 | sg_len = sg_dma_len(sg); | |
2123 | addr = (u64) sg_dma_address(sg); | |
2124 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2125 | sge1_addr_lo, pwrb, | |
2126 | lower_32_bits(addr)); | |
2127 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2128 | sge1_addr_hi, pwrb, | |
2129 | upper_32_bits(addr)); | |
2130 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2131 | sge1_len, pwrb, | |
2132 | sg_len); | |
2133 | } | |
2134 | } | |
2135 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2136 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); | |
2137 | ||
2138 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); | |
2139 | ||
2140 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2141 | io_task->bhs_pa.u.a32.address_hi); | |
2142 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2143 | io_task->bhs_pa.u.a32.address_lo); | |
2144 | ||
2145 | if (num_sg == 1) { | |
2146 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2147 | 1); | |
2148 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2149 | 0); | |
2150 | } else if (num_sg == 2) { | |
2151 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2152 | 0); | |
2153 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2154 | 1); | |
2155 | } else { | |
2156 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2157 | 0); | |
2158 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2159 | 0); | |
2160 | } | |
2161 | ||
2162 | sg = l_sg; | |
2163 | psgl++; | |
2164 | psgl++; | |
2165 | offset = 0; | |
2166 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { | |
2167 | sg_len = sg_dma_len(sg); | |
2168 | addr = (u64) sg_dma_address(sg); | |
2169 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2170 | lower_32_bits(addr)); | |
2171 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2172 | upper_32_bits(addr)); | |
2173 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); | |
2174 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); | |
2175 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2176 | offset += sg_len; | |
2177 | } | |
2178 | psgl--; | |
2179 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
2180 | } | |
2181 | ||
6733b39a JK |
2182 | static void |
2183 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, | |
2184 | unsigned int num_sg, struct beiscsi_io_task *io_task) | |
2185 | { | |
2186 | struct iscsi_sge *psgl; | |
58ff4bd0 | 2187 | unsigned int sg_len, index; |
6733b39a JK |
2188 | unsigned int sge_len = 0; |
2189 | unsigned long long addr; | |
2190 | struct scatterlist *l_sg; | |
2191 | unsigned int offset; | |
2192 | ||
2193 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, | |
2194 | io_task->bhs_pa.u.a32.address_lo); | |
2195 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, | |
2196 | io_task->bhs_pa.u.a32.address_hi); | |
2197 | ||
2198 | l_sg = sg; | |
48bd86cf JK |
2199 | for (index = 0; (index < num_sg) && (index < 2); index++, |
2200 | sg = sg_next(sg)) { | |
6733b39a JK |
2201 | if (index == 0) { |
2202 | sg_len = sg_dma_len(sg); | |
2203 | addr = (u64) sg_dma_address(sg); | |
2204 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, | |
457ff3b7 | 2205 | ((u32)(addr & 0xFFFFFFFF))); |
6733b39a | 2206 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
457ff3b7 | 2207 | ((u32)(addr >> 32))); |
6733b39a JK |
2208 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
2209 | sg_len); | |
2210 | sge_len = sg_len; | |
6733b39a | 2211 | } else { |
6733b39a JK |
2212 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
2213 | pwrb, sge_len); | |
2214 | sg_len = sg_dma_len(sg); | |
2215 | addr = (u64) sg_dma_address(sg); | |
2216 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, | |
457ff3b7 | 2217 | ((u32)(addr & 0xFFFFFFFF))); |
6733b39a | 2218 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
457ff3b7 | 2219 | ((u32)(addr >> 32))); |
6733b39a JK |
2220 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
2221 | sg_len); | |
2222 | } | |
2223 | } | |
2224 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2225 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); | |
2226 | ||
2227 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); | |
2228 | ||
2229 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2230 | io_task->bhs_pa.u.a32.address_hi); | |
2231 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2232 | io_task->bhs_pa.u.a32.address_lo); | |
2233 | ||
caf818f1 JK |
2234 | if (num_sg == 1) { |
2235 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2236 | 1); | |
2237 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2238 | 0); | |
2239 | } else if (num_sg == 2) { | |
2240 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2241 | 0); | |
2242 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2243 | 1); | |
2244 | } else { | |
2245 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2246 | 0); | |
2247 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2248 | 0); | |
2249 | } | |
6733b39a JK |
2250 | sg = l_sg; |
2251 | psgl++; | |
2252 | psgl++; | |
2253 | offset = 0; | |
48bd86cf | 2254 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
6733b39a JK |
2255 | sg_len = sg_dma_len(sg); |
2256 | addr = (u64) sg_dma_address(sg); | |
2257 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2258 | (addr & 0xFFFFFFFF)); | |
2259 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2260 | (addr >> 32)); | |
2261 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); | |
2262 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); | |
2263 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2264 | offset += sg_len; | |
2265 | } | |
2266 | psgl--; | |
2267 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
2268 | } | |
2269 | ||
d629c471 JSJ |
2270 | /** |
2271 | * hwi_write_buffer()- Populate the WRB with task info | |
2272 | * @pwrb: ptr to the WRB entry | |
2273 | * @task: iscsi task which is to be executed | |
2274 | **/ | |
e0493627 | 2275 | static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task) |
6733b39a JK |
2276 | { |
2277 | struct iscsi_sge *psgl; | |
6733b39a JK |
2278 | struct beiscsi_io_task *io_task = task->dd_data; |
2279 | struct beiscsi_conn *beiscsi_conn = io_task->conn; | |
2280 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
09a1093a | 2281 | uint8_t dsp_value = 0; |
6733b39a JK |
2282 | |
2283 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; | |
2284 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, | |
2285 | io_task->bhs_pa.u.a32.address_lo); | |
2286 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, | |
2287 | io_task->bhs_pa.u.a32.address_hi); | |
2288 | ||
2289 | if (task->data) { | |
09a1093a JSJ |
2290 | |
2291 | /* Check for the data_count */ | |
2292 | dsp_value = (task->data_count) ? 1 : 0; | |
2293 | ||
2c9dfd36 JK |
2294 | if (is_chip_be2_be3r(phba)) |
2295 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, | |
09a1093a JSJ |
2296 | pwrb, dsp_value); |
2297 | else | |
2c9dfd36 | 2298 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
09a1093a JSJ |
2299 | pwrb, dsp_value); |
2300 | ||
2301 | /* Map addr only if there is data_count */ | |
2302 | if (dsp_value) { | |
d629c471 JSJ |
2303 | io_task->mtask_addr = pci_map_single(phba->pcidev, |
2304 | task->data, | |
2305 | task->data_count, | |
2306 | PCI_DMA_TODEVICE); | |
e0493627 AK |
2307 | if (pci_dma_mapping_error(phba->pcidev, |
2308 | io_task->mtask_addr)) | |
2309 | return -ENOMEM; | |
d629c471 | 2310 | io_task->mtask_data_count = task->data_count; |
09a1093a | 2311 | } else |
d629c471 | 2312 | io_task->mtask_addr = 0; |
09a1093a | 2313 | |
6733b39a | 2314 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
d629c471 | 2315 | lower_32_bits(io_task->mtask_addr)); |
6733b39a | 2316 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
d629c471 | 2317 | upper_32_bits(io_task->mtask_addr)); |
6733b39a JK |
2318 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
2319 | task->data_count); | |
2320 | ||
2321 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); | |
2322 | } else { | |
2323 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); | |
d629c471 | 2324 | io_task->mtask_addr = 0; |
6733b39a JK |
2325 | } |
2326 | ||
2327 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2328 | ||
2329 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); | |
2330 | ||
2331 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2332 | io_task->bhs_pa.u.a32.address_hi); | |
2333 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2334 | io_task->bhs_pa.u.a32.address_lo); | |
2335 | if (task->data) { | |
2336 | psgl++; | |
2337 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); | |
2338 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); | |
2339 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); | |
2340 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); | |
2341 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); | |
2342 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2343 | ||
2344 | psgl++; | |
2345 | if (task->data) { | |
2346 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
d629c471 | 2347 | lower_32_bits(io_task->mtask_addr)); |
6733b39a | 2348 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
d629c471 | 2349 | upper_32_bits(io_task->mtask_addr)); |
6733b39a JK |
2350 | } |
2351 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); | |
2352 | } | |
2353 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
e0493627 | 2354 | return 0; |
6733b39a JK |
2355 | } |
2356 | ||
843ae752 JK |
2357 | /** |
2358 | * beiscsi_find_mem_req()- Find mem needed | |
2359 | * @phba: ptr to HBA struct | |
2360 | **/ | |
6733b39a JK |
2361 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
2362 | { | |
8a86e833 | 2363 | uint8_t mem_descr_index, ulp_num; |
bfead3b2 | 2364 | unsigned int num_cq_pages, num_async_pdu_buf_pages; |
6733b39a JK |
2365 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
2366 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; | |
2367 | ||
2368 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ | |
2369 | sizeof(struct sol_cqe)); | |
6733b39a JK |
2370 | |
2371 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); | |
2372 | ||
2373 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * | |
2374 | BE_ISCSI_PDU_HEADER_SIZE; | |
2375 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = | |
2376 | sizeof(struct hwi_context_memory); | |
2377 | ||
6733b39a JK |
2378 | |
2379 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) | |
2380 | * (phba->params.wrbs_per_cxn) | |
2381 | * phba->params.cxns_per_ctrl; | |
2382 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * | |
2383 | (phba->params.wrbs_per_cxn); | |
2384 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * | |
2385 | phba->params.cxns_per_ctrl); | |
2386 | ||
2387 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * | |
2388 | phba->params.icds_per_ctrl; | |
2389 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * | |
2390 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; | |
8a86e833 JK |
2391 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
2392 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
6733b39a | 2393 | |
8a86e833 JK |
2394 | num_async_pdu_buf_sgl_pages = |
2395 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2396 | phba, ulp_num) * | |
2397 | sizeof(struct phys_addr)); | |
2398 | ||
2399 | num_async_pdu_buf_pages = | |
2400 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2401 | phba, ulp_num) * | |
2402 | phba->params.defpdu_hdr_sz); | |
2403 | ||
2404 | num_async_pdu_data_pages = | |
2405 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2406 | phba, ulp_num) * | |
2407 | phba->params.defpdu_data_sz); | |
2408 | ||
2409 | num_async_pdu_data_sgl_pages = | |
2410 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2411 | phba, ulp_num) * | |
2412 | sizeof(struct phys_addr)); | |
2413 | ||
a129d92f JK |
2414 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
2415 | (ulp_num * MEM_DESCR_OFFSET)); | |
2416 | phba->mem_req[mem_descr_index] = | |
2417 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
2418 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; | |
2419 | ||
8a86e833 JK |
2420 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
2421 | (ulp_num * MEM_DESCR_OFFSET)); | |
2422 | phba->mem_req[mem_descr_index] = | |
2423 | num_async_pdu_buf_pages * | |
2424 | PAGE_SIZE; | |
2425 | ||
2426 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + | |
2427 | (ulp_num * MEM_DESCR_OFFSET)); | |
2428 | phba->mem_req[mem_descr_index] = | |
2429 | num_async_pdu_data_pages * | |
2430 | PAGE_SIZE; | |
2431 | ||
2432 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + | |
2433 | (ulp_num * MEM_DESCR_OFFSET)); | |
2434 | phba->mem_req[mem_descr_index] = | |
2435 | num_async_pdu_buf_sgl_pages * | |
2436 | PAGE_SIZE; | |
2437 | ||
2438 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + | |
2439 | (ulp_num * MEM_DESCR_OFFSET)); | |
2440 | phba->mem_req[mem_descr_index] = | |
2441 | num_async_pdu_data_sgl_pages * | |
2442 | PAGE_SIZE; | |
2443 | ||
2444 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + | |
2445 | (ulp_num * MEM_DESCR_OFFSET)); | |
2446 | phba->mem_req[mem_descr_index] = | |
2447 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
938f372c | 2448 | sizeof(struct hd_async_handle); |
8a86e833 JK |
2449 | |
2450 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + | |
2451 | (ulp_num * MEM_DESCR_OFFSET)); | |
2452 | phba->mem_req[mem_descr_index] = | |
2453 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
938f372c | 2454 | sizeof(struct hd_async_handle); |
8a86e833 JK |
2455 | |
2456 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + | |
2457 | (ulp_num * MEM_DESCR_OFFSET)); | |
2458 | phba->mem_req[mem_descr_index] = | |
938f372c | 2459 | sizeof(struct hd_async_context) + |
8a86e833 | 2460 | (BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
938f372c | 2461 | sizeof(struct hd_async_entry)); |
8a86e833 JK |
2462 | } |
2463 | } | |
6733b39a JK |
2464 | } |
2465 | ||
2466 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) | |
2467 | { | |
6733b39a | 2468 | dma_addr_t bus_add; |
a7909b39 JK |
2469 | struct hwi_controller *phwi_ctrlr; |
2470 | struct be_mem_descriptor *mem_descr; | |
6733b39a JK |
2471 | struct mem_array *mem_arr, *mem_arr_orig; |
2472 | unsigned int i, j, alloc_size, curr_alloc_size; | |
2473 | ||
3ec78271 | 2474 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
6733b39a JK |
2475 | if (!phba->phwi_ctrlr) |
2476 | return -ENOMEM; | |
2477 | ||
a7909b39 JK |
2478 | /* Allocate memory for wrb_context */ |
2479 | phwi_ctrlr = phba->phwi_ctrlr; | |
2480 | phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) * | |
2481 | phba->params.cxns_per_ctrl, | |
2482 | GFP_KERNEL); | |
0c88740d ML |
2483 | if (!phwi_ctrlr->wrb_context) { |
2484 | kfree(phba->phwi_ctrlr); | |
a7909b39 | 2485 | return -ENOMEM; |
0c88740d | 2486 | } |
a7909b39 | 2487 | |
6733b39a JK |
2488 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
2489 | GFP_KERNEL); | |
2490 | if (!phba->init_mem) { | |
a7909b39 | 2491 | kfree(phwi_ctrlr->wrb_context); |
6733b39a JK |
2492 | kfree(phba->phwi_ctrlr); |
2493 | return -ENOMEM; | |
2494 | } | |
2495 | ||
2496 | mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT, | |
2497 | GFP_KERNEL); | |
2498 | if (!mem_arr_orig) { | |
2499 | kfree(phba->init_mem); | |
a7909b39 | 2500 | kfree(phwi_ctrlr->wrb_context); |
6733b39a JK |
2501 | kfree(phba->phwi_ctrlr); |
2502 | return -ENOMEM; | |
2503 | } | |
2504 | ||
2505 | mem_descr = phba->init_mem; | |
2506 | for (i = 0; i < SE_MEM_MAX; i++) { | |
8a86e833 JK |
2507 | if (!phba->mem_req[i]) { |
2508 | mem_descr->mem_array = NULL; | |
2509 | mem_descr++; | |
2510 | continue; | |
2511 | } | |
2512 | ||
6733b39a JK |
2513 | j = 0; |
2514 | mem_arr = mem_arr_orig; | |
2515 | alloc_size = phba->mem_req[i]; | |
2516 | memset(mem_arr, 0, sizeof(struct mem_array) * | |
2517 | BEISCSI_MAX_FRAGS_INIT); | |
2518 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); | |
2519 | do { | |
2520 | mem_arr->virtual_address = pci_alloc_consistent( | |
2521 | phba->pcidev, | |
2522 | curr_alloc_size, | |
2523 | &bus_add); | |
2524 | if (!mem_arr->virtual_address) { | |
2525 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) | |
2526 | goto free_mem; | |
2527 | if (curr_alloc_size - | |
2528 | rounddown_pow_of_two(curr_alloc_size)) | |
2529 | curr_alloc_size = rounddown_pow_of_two | |
2530 | (curr_alloc_size); | |
2531 | else | |
2532 | curr_alloc_size = curr_alloc_size / 2; | |
2533 | } else { | |
2534 | mem_arr->bus_address.u. | |
2535 | a64.address = (__u64) bus_add; | |
2536 | mem_arr->size = curr_alloc_size; | |
2537 | alloc_size -= curr_alloc_size; | |
2538 | curr_alloc_size = min(be_max_phys_size * | |
2539 | 1024, alloc_size); | |
2540 | j++; | |
2541 | mem_arr++; | |
2542 | } | |
2543 | } while (alloc_size); | |
2544 | mem_descr->num_elements = j; | |
2545 | mem_descr->size_in_bytes = phba->mem_req[i]; | |
2546 | mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j, | |
2547 | GFP_KERNEL); | |
2548 | if (!mem_descr->mem_array) | |
2549 | goto free_mem; | |
2550 | ||
2551 | memcpy(mem_descr->mem_array, mem_arr_orig, | |
2552 | sizeof(struct mem_array) * j); | |
2553 | mem_descr++; | |
2554 | } | |
2555 | kfree(mem_arr_orig); | |
2556 | return 0; | |
2557 | free_mem: | |
2558 | mem_descr->num_elements = j; | |
2559 | while ((i) || (j)) { | |
2560 | for (j = mem_descr->num_elements; j > 0; j--) { | |
2561 | pci_free_consistent(phba->pcidev, | |
2562 | mem_descr->mem_array[j - 1].size, | |
2563 | mem_descr->mem_array[j - 1]. | |
2564 | virtual_address, | |
457ff3b7 JK |
2565 | (unsigned long)mem_descr-> |
2566 | mem_array[j - 1]. | |
6733b39a JK |
2567 | bus_address.u.a64.address); |
2568 | } | |
2569 | if (i) { | |
2570 | i--; | |
2571 | kfree(mem_descr->mem_array); | |
2572 | mem_descr--; | |
2573 | } | |
2574 | } | |
2575 | kfree(mem_arr_orig); | |
2576 | kfree(phba->init_mem); | |
a7909b39 | 2577 | kfree(phba->phwi_ctrlr->wrb_context); |
6733b39a JK |
2578 | kfree(phba->phwi_ctrlr); |
2579 | return -ENOMEM; | |
2580 | } | |
2581 | ||
2582 | static int beiscsi_get_memory(struct beiscsi_hba *phba) | |
2583 | { | |
2584 | beiscsi_find_mem_req(phba); | |
2585 | return beiscsi_alloc_mem(phba); | |
2586 | } | |
2587 | ||
2588 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) | |
2589 | { | |
2590 | struct pdu_data_out *pdata_out; | |
2591 | struct pdu_nop_out *pnop_out; | |
2592 | struct be_mem_descriptor *mem_descr; | |
2593 | ||
2594 | mem_descr = phba->init_mem; | |
2595 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; | |
2596 | pdata_out = | |
2597 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; | |
2598 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); | |
2599 | ||
2600 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, | |
2601 | IIOC_SCSI_DATA); | |
2602 | ||
2603 | pnop_out = | |
2604 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. | |
2605 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); | |
2606 | ||
2607 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); | |
2608 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); | |
2609 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); | |
2610 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); | |
2611 | } | |
2612 | ||
3ec78271 | 2613 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
6733b39a JK |
2614 | { |
2615 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; | |
a7909b39 | 2616 | struct hwi_context_memory *phwi_ctxt; |
3ec78271 | 2617 | struct wrb_handle *pwrb_handle = NULL; |
6733b39a JK |
2618 | struct hwi_controller *phwi_ctrlr; |
2619 | struct hwi_wrb_context *pwrb_context; | |
3ec78271 JK |
2620 | struct iscsi_wrb *pwrb = NULL; |
2621 | unsigned int num_cxn_wrbh = 0; | |
2622 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; | |
6733b39a JK |
2623 | |
2624 | mem_descr_wrbh = phba->init_mem; | |
2625 | mem_descr_wrbh += HWI_MEM_WRBH; | |
2626 | ||
2627 | mem_descr_wrb = phba->init_mem; | |
2628 | mem_descr_wrb += HWI_MEM_WRB; | |
6733b39a JK |
2629 | phwi_ctrlr = phba->phwi_ctrlr; |
2630 | ||
a7909b39 JK |
2631 | /* Allocate memory for WRBQ */ |
2632 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; | |
2633 | phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) * | |
843ae752 | 2634 | phba->params.cxns_per_ctrl, |
a7909b39 JK |
2635 | GFP_KERNEL); |
2636 | if (!phwi_ctxt->be_wrbq) { | |
2637 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
2638 | "BM_%d : WRBQ Mem Alloc Failed\n"); | |
2639 | return -ENOMEM; | |
2640 | } | |
2641 | ||
2642 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { | |
6733b39a | 2643 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
6733b39a JK |
2644 | pwrb_context->pwrb_handle_base = |
2645 | kzalloc(sizeof(struct wrb_handle *) * | |
2646 | phba->params.wrbs_per_cxn, GFP_KERNEL); | |
3ec78271 | 2647 | if (!pwrb_context->pwrb_handle_base) { |
99bc5d55 JSJ |
2648 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
2649 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
3ec78271 JK |
2650 | goto init_wrb_hndl_failed; |
2651 | } | |
6733b39a JK |
2652 | pwrb_context->pwrb_handle_basestd = |
2653 | kzalloc(sizeof(struct wrb_handle *) * | |
2654 | phba->params.wrbs_per_cxn, GFP_KERNEL); | |
3ec78271 | 2655 | if (!pwrb_context->pwrb_handle_basestd) { |
99bc5d55 JSJ |
2656 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
2657 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
3ec78271 JK |
2658 | goto init_wrb_hndl_failed; |
2659 | } | |
2660 | if (!num_cxn_wrbh) { | |
2661 | pwrb_handle = | |
2662 | mem_descr_wrbh->mem_array[idx].virtual_address; | |
2663 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / | |
2664 | ((sizeof(struct wrb_handle)) * | |
2665 | phba->params.wrbs_per_cxn)); | |
2666 | idx++; | |
2667 | } | |
2668 | pwrb_context->alloc_index = 0; | |
2669 | pwrb_context->wrb_handles_available = 0; | |
2670 | pwrb_context->free_index = 0; | |
2671 | ||
6733b39a | 2672 | if (num_cxn_wrbh) { |
6733b39a JK |
2673 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
2674 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; | |
2675 | pwrb_context->pwrb_handle_basestd[j] = | |
2676 | pwrb_handle; | |
2677 | pwrb_context->wrb_handles_available++; | |
bfead3b2 | 2678 | pwrb_handle->wrb_index = j; |
6733b39a JK |
2679 | pwrb_handle++; |
2680 | } | |
6733b39a JK |
2681 | num_cxn_wrbh--; |
2682 | } | |
f64d92e6 | 2683 | spin_lock_init(&pwrb_context->wrb_lock); |
6733b39a JK |
2684 | } |
2685 | idx = 0; | |
a7909b39 | 2686 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
6733b39a | 2687 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
3ec78271 | 2688 | if (!num_cxn_wrb) { |
6733b39a | 2689 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
7c56533c | 2690 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
3ec78271 JK |
2691 | ((sizeof(struct iscsi_wrb) * |
2692 | phba->params.wrbs_per_cxn)); | |
2693 | idx++; | |
2694 | } | |
2695 | ||
2696 | if (num_cxn_wrb) { | |
6733b39a JK |
2697 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
2698 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; | |
2699 | pwrb_handle->pwrb = pwrb; | |
2700 | pwrb++; | |
2701 | } | |
2702 | num_cxn_wrb--; | |
2703 | } | |
2704 | } | |
3ec78271 JK |
2705 | return 0; |
2706 | init_wrb_hndl_failed: | |
2707 | for (j = index; j > 0; j--) { | |
2708 | pwrb_context = &phwi_ctrlr->wrb_context[j]; | |
2709 | kfree(pwrb_context->pwrb_handle_base); | |
2710 | kfree(pwrb_context->pwrb_handle_basestd); | |
2711 | } | |
2712 | return -ENOMEM; | |
6733b39a JK |
2713 | } |
2714 | ||
a7909b39 | 2715 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
6733b39a | 2716 | { |
8a86e833 | 2717 | uint8_t ulp_num; |
6733b39a JK |
2718 | struct hwi_controller *phwi_ctrlr; |
2719 | struct hba_parameters *p = &phba->params; | |
938f372c JB |
2720 | struct hd_async_context *pasync_ctx; |
2721 | struct hd_async_handle *pasync_header_h, *pasync_data_h; | |
dc63aac6 | 2722 | unsigned int index, idx, num_per_mem, num_async_data; |
6733b39a JK |
2723 | struct be_mem_descriptor *mem_descr; |
2724 | ||
8a86e833 JK |
2725 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
2726 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
938f372c | 2727 | /* get async_ctx for each ULP */ |
8a86e833 JK |
2728 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2729 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + | |
2730 | (ulp_num * MEM_DESCR_OFFSET)); | |
2731 | ||
2732 | phwi_ctrlr = phba->phwi_ctrlr; | |
2733 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = | |
938f372c | 2734 | (struct hd_async_context *) |
8a86e833 JK |
2735 | mem_descr->mem_array[0].virtual_address; |
2736 | ||
2737 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; | |
2738 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); | |
2739 | ||
2740 | pasync_ctx->async_entry = | |
938f372c | 2741 | (struct hd_async_entry *) |
8a86e833 | 2742 | ((long unsigned int)pasync_ctx + |
938f372c | 2743 | sizeof(struct hd_async_context)); |
8a86e833 JK |
2744 | |
2745 | pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba, | |
2746 | ulp_num); | |
938f372c | 2747 | /* setup header buffers */ |
8a86e833 JK |
2748 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2749 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + | |
2750 | (ulp_num * MEM_DESCR_OFFSET); | |
2751 | if (mem_descr->mem_array[0].virtual_address) { | |
2752 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2753 | "BM_%d : hwi_init_async_pdu_ctx" | |
2754 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", | |
2755 | ulp_num, | |
2756 | mem_descr->mem_array[0]. | |
2757 | virtual_address); | |
2758 | } else | |
2759 | beiscsi_log(phba, KERN_WARNING, | |
2760 | BEISCSI_LOG_INIT, | |
2761 | "BM_%d : No Virtual address for ULP : %d\n", | |
2762 | ulp_num); | |
2763 | ||
938f372c | 2764 | pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz; |
8a86e833 | 2765 | pasync_ctx->async_header.va_base = |
6733b39a | 2766 | mem_descr->mem_array[0].virtual_address; |
6733b39a | 2767 | |
8a86e833 JK |
2768 | pasync_ctx->async_header.pa_base.u.a64.address = |
2769 | mem_descr->mem_array[0]. | |
2770 | bus_address.u.a64.address; | |
6733b39a | 2771 | |
938f372c | 2772 | /* setup header buffer sgls */ |
8a86e833 JK |
2773 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2774 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + | |
2775 | (ulp_num * MEM_DESCR_OFFSET); | |
2776 | if (mem_descr->mem_array[0].virtual_address) { | |
2777 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2778 | "BM_%d : hwi_init_async_pdu_ctx" | |
2779 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", | |
2780 | ulp_num, | |
2781 | mem_descr->mem_array[0]. | |
2782 | virtual_address); | |
2783 | } else | |
2784 | beiscsi_log(phba, KERN_WARNING, | |
2785 | BEISCSI_LOG_INIT, | |
2786 | "BM_%d : No Virtual address for ULP : %d\n", | |
2787 | ulp_num); | |
2788 | ||
2789 | pasync_ctx->async_header.ring_base = | |
2790 | mem_descr->mem_array[0].virtual_address; | |
6733b39a | 2791 | |
938f372c | 2792 | /* setup header buffer handles */ |
8a86e833 JK |
2793 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2794 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + | |
2795 | (ulp_num * MEM_DESCR_OFFSET); | |
2796 | if (mem_descr->mem_array[0].virtual_address) { | |
2797 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2798 | "BM_%d : hwi_init_async_pdu_ctx" | |
2799 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", | |
2800 | ulp_num, | |
2801 | mem_descr->mem_array[0]. | |
2802 | virtual_address); | |
2803 | } else | |
2804 | beiscsi_log(phba, KERN_WARNING, | |
2805 | BEISCSI_LOG_INIT, | |
2806 | "BM_%d : No Virtual address for ULP : %d\n", | |
2807 | ulp_num); | |
2808 | ||
2809 | pasync_ctx->async_header.handle_base = | |
2810 | mem_descr->mem_array[0].virtual_address; | |
8a86e833 JK |
2811 | INIT_LIST_HEAD(&pasync_ctx->async_header.free_list); |
2812 | ||
938f372c | 2813 | /* setup data buffer sgls */ |
8a86e833 JK |
2814 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2815 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + | |
2816 | (ulp_num * MEM_DESCR_OFFSET); | |
2817 | if (mem_descr->mem_array[0].virtual_address) { | |
2818 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2819 | "BM_%d : hwi_init_async_pdu_ctx" | |
2820 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", | |
2821 | ulp_num, | |
2822 | mem_descr->mem_array[0]. | |
2823 | virtual_address); | |
2824 | } else | |
2825 | beiscsi_log(phba, KERN_WARNING, | |
2826 | BEISCSI_LOG_INIT, | |
2827 | "BM_%d : No Virtual address for ULP : %d\n", | |
2828 | ulp_num); | |
2829 | ||
2830 | pasync_ctx->async_data.ring_base = | |
2831 | mem_descr->mem_array[0].virtual_address; | |
6733b39a | 2832 | |
938f372c | 2833 | /* setup data buffer handles */ |
8a86e833 JK |
2834 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2835 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + | |
2836 | (ulp_num * MEM_DESCR_OFFSET); | |
2837 | if (!mem_descr->mem_array[0].virtual_address) | |
2838 | beiscsi_log(phba, KERN_WARNING, | |
2839 | BEISCSI_LOG_INIT, | |
2840 | "BM_%d : No Virtual address for ULP : %d\n", | |
2841 | ulp_num); | |
99bc5d55 | 2842 | |
8a86e833 JK |
2843 | pasync_ctx->async_data.handle_base = |
2844 | mem_descr->mem_array[0].virtual_address; | |
8a86e833 JK |
2845 | INIT_LIST_HEAD(&pasync_ctx->async_data.free_list); |
2846 | ||
2847 | pasync_header_h = | |
938f372c | 2848 | (struct hd_async_handle *) |
8a86e833 JK |
2849 | pasync_ctx->async_header.handle_base; |
2850 | pasync_data_h = | |
938f372c | 2851 | (struct hd_async_handle *) |
8a86e833 JK |
2852 | pasync_ctx->async_data.handle_base; |
2853 | ||
938f372c | 2854 | /* setup data buffers */ |
8a86e833 JK |
2855 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2856 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + | |
2857 | (ulp_num * MEM_DESCR_OFFSET); | |
2858 | if (mem_descr->mem_array[0].virtual_address) { | |
2859 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2860 | "BM_%d : hwi_init_async_pdu_ctx" | |
2861 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", | |
2862 | ulp_num, | |
2863 | mem_descr->mem_array[0]. | |
2864 | virtual_address); | |
2865 | } else | |
2866 | beiscsi_log(phba, KERN_WARNING, | |
2867 | BEISCSI_LOG_INIT, | |
2868 | "BM_%d : No Virtual address for ULP : %d\n", | |
2869 | ulp_num); | |
2870 | ||
2871 | idx = 0; | |
938f372c | 2872 | pasync_ctx->async_data.buffer_size = p->defpdu_data_sz; |
dc63aac6 JK |
2873 | pasync_ctx->async_data.va_base = |
2874 | mem_descr->mem_array[idx].virtual_address; | |
2875 | pasync_ctx->async_data.pa_base.u.a64.address = | |
2876 | mem_descr->mem_array[idx]. | |
2877 | bus_address.u.a64.address; | |
2878 | ||
2879 | num_async_data = ((mem_descr->mem_array[idx].size) / | |
2880 | phba->params.defpdu_data_sz); | |
8a86e833 | 2881 | num_per_mem = 0; |
6733b39a | 2882 | |
8a86e833 JK |
2883 | for (index = 0; index < BEISCSI_GET_CID_COUNT |
2884 | (phba, ulp_num); index++) { | |
2885 | pasync_header_h->cri = -1; | |
938f372c JB |
2886 | pasync_header_h->is_header = 1; |
2887 | pasync_header_h->index = index; | |
8a86e833 JK |
2888 | INIT_LIST_HEAD(&pasync_header_h->link); |
2889 | pasync_header_h->pbuffer = | |
2890 | (void *)((unsigned long) | |
2891 | (pasync_ctx-> | |
2892 | async_header.va_base) + | |
2893 | (p->defpdu_hdr_sz * index)); | |
2894 | ||
2895 | pasync_header_h->pa.u.a64.address = | |
2896 | pasync_ctx->async_header.pa_base.u.a64. | |
2897 | address + (p->defpdu_hdr_sz * index); | |
2898 | ||
2899 | list_add_tail(&pasync_header_h->link, | |
2900 | &pasync_ctx->async_header. | |
2901 | free_list); | |
2902 | pasync_header_h++; | |
2903 | pasync_ctx->async_header.free_entries++; | |
8a86e833 | 2904 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
938f372c JB |
2905 | wq.list); |
2906 | pasync_ctx->async_entry[index].header = NULL; | |
2907 | ||
8a86e833 | 2908 | pasync_data_h->cri = -1; |
938f372c JB |
2909 | pasync_data_h->is_header = 0; |
2910 | pasync_data_h->index = index; | |
8a86e833 JK |
2911 | INIT_LIST_HEAD(&pasync_data_h->link); |
2912 | ||
2913 | if (!num_async_data) { | |
2914 | num_per_mem = 0; | |
2915 | idx++; | |
2916 | pasync_ctx->async_data.va_base = | |
2917 | mem_descr->mem_array[idx]. | |
2918 | virtual_address; | |
2919 | pasync_ctx->async_data.pa_base.u. | |
2920 | a64.address = | |
2921 | mem_descr->mem_array[idx]. | |
2922 | bus_address.u.a64.address; | |
2923 | num_async_data = | |
2924 | ((mem_descr->mem_array[idx]. | |
2925 | size) / | |
2926 | phba->params.defpdu_data_sz); | |
2927 | } | |
2928 | pasync_data_h->pbuffer = | |
2929 | (void *)((unsigned long) | |
2930 | (pasync_ctx->async_data.va_base) + | |
2931 | (p->defpdu_data_sz * num_per_mem)); | |
2932 | ||
2933 | pasync_data_h->pa.u.a64.address = | |
2934 | pasync_ctx->async_data.pa_base.u.a64. | |
2935 | address + (p->defpdu_data_sz * | |
2936 | num_per_mem); | |
2937 | num_per_mem++; | |
2938 | num_async_data--; | |
2939 | ||
2940 | list_add_tail(&pasync_data_h->link, | |
2941 | &pasync_ctx->async_data. | |
2942 | free_list); | |
2943 | pasync_data_h++; | |
2944 | pasync_ctx->async_data.free_entries++; | |
938f372c | 2945 | pasync_ctx->async_entry[index].data = NULL; |
8a86e833 | 2946 | } |
8a86e833 | 2947 | } |
6733b39a JK |
2948 | } |
2949 | ||
a7909b39 | 2950 | return 0; |
6733b39a JK |
2951 | } |
2952 | ||
2953 | static int | |
2954 | be_sgl_create_contiguous(void *virtual_address, | |
2955 | u64 physical_address, u32 length, | |
2956 | struct be_dma_mem *sgl) | |
2957 | { | |
2958 | WARN_ON(!virtual_address); | |
2959 | WARN_ON(!physical_address); | |
dd29dae0 | 2960 | WARN_ON(!length); |
6733b39a JK |
2961 | WARN_ON(!sgl); |
2962 | ||
2963 | sgl->va = virtual_address; | |
457ff3b7 | 2964 | sgl->dma = (unsigned long)physical_address; |
6733b39a JK |
2965 | sgl->size = length; |
2966 | ||
2967 | return 0; | |
2968 | } | |
2969 | ||
2970 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) | |
2971 | { | |
2972 | memset(sgl, 0, sizeof(*sgl)); | |
2973 | } | |
2974 | ||
2975 | static void | |
2976 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, | |
2977 | struct mem_array *pmem, struct be_dma_mem *sgl) | |
2978 | { | |
2979 | if (sgl->va) | |
2980 | be_sgl_destroy_contiguous(sgl); | |
2981 | ||
2982 | be_sgl_create_contiguous(pmem->virtual_address, | |
2983 | pmem->bus_address.u.a64.address, | |
2984 | pmem->size, sgl); | |
2985 | } | |
2986 | ||
2987 | static void | |
2988 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, | |
2989 | struct mem_array *pmem, struct be_dma_mem *sgl) | |
2990 | { | |
2991 | if (sgl->va) | |
2992 | be_sgl_destroy_contiguous(sgl); | |
2993 | ||
2994 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, | |
2995 | pmem->bus_address.u.a64.address, | |
2996 | pmem->size, sgl); | |
2997 | } | |
2998 | ||
2999 | static int be_fill_queue(struct be_queue_info *q, | |
3000 | u16 len, u16 entry_size, void *vaddress) | |
3001 | { | |
3002 | struct be_dma_mem *mem = &q->dma_mem; | |
3003 | ||
3004 | memset(q, 0, sizeof(*q)); | |
3005 | q->len = len; | |
3006 | q->entry_size = entry_size; | |
3007 | mem->size = len * entry_size; | |
3008 | mem->va = vaddress; | |
3009 | if (!mem->va) | |
3010 | return -ENOMEM; | |
3011 | memset(mem->va, 0, mem->size); | |
3012 | return 0; | |
3013 | } | |
3014 | ||
bfead3b2 | 3015 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
6733b39a JK |
3016 | struct hwi_context_memory *phwi_context) |
3017 | { | |
deeea8ed | 3018 | int ret = -ENOMEM, eq_for_mcc; |
bfead3b2 | 3019 | unsigned int i, num_eq_pages; |
6733b39a JK |
3020 | struct be_queue_info *eq; |
3021 | struct be_dma_mem *mem; | |
6733b39a | 3022 | void *eq_vaddress; |
bfead3b2 | 3023 | dma_addr_t paddr; |
6733b39a | 3024 | |
bfead3b2 JK |
3025 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
3026 | sizeof(struct be_eq_entry)); | |
6733b39a | 3027 | |
bfead3b2 JK |
3028 | if (phba->msix_enabled) |
3029 | eq_for_mcc = 1; | |
3030 | else | |
3031 | eq_for_mcc = 0; | |
3032 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { | |
3033 | eq = &phwi_context->be_eq[i].q; | |
3034 | mem = &eq->dma_mem; | |
3035 | phwi_context->be_eq[i].phba = phba; | |
3036 | eq_vaddress = pci_alloc_consistent(phba->pcidev, | |
deeea8ed CJ |
3037 | num_eq_pages * PAGE_SIZE, |
3038 | &paddr); | |
84a261ff PB |
3039 | if (!eq_vaddress) { |
3040 | ret = -ENOMEM; | |
bfead3b2 | 3041 | goto create_eq_error; |
84a261ff | 3042 | } |
bfead3b2 JK |
3043 | |
3044 | mem->va = eq_vaddress; | |
3045 | ret = be_fill_queue(eq, phba->params.num_eq_entries, | |
3046 | sizeof(struct be_eq_entry), eq_vaddress); | |
3047 | if (ret) { | |
99bc5d55 JSJ |
3048 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3049 | "BM_%d : be_fill_queue Failed for EQ\n"); | |
bfead3b2 JK |
3050 | goto create_eq_error; |
3051 | } | |
6733b39a | 3052 | |
bfead3b2 JK |
3053 | mem->dma = paddr; |
3054 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, | |
3055 | phwi_context->cur_eqd); | |
3056 | if (ret) { | |
99bc5d55 JSJ |
3057 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3058 | "BM_%d : beiscsi_cmd_eq_create" | |
3059 | "Failed for EQ\n"); | |
bfead3b2 JK |
3060 | goto create_eq_error; |
3061 | } | |
99bc5d55 JSJ |
3062 | |
3063 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
3064 | "BM_%d : eqid = %d\n", | |
3065 | phwi_context->be_eq[i].q.id); | |
6733b39a | 3066 | } |
6733b39a | 3067 | return 0; |
deeea8ed | 3068 | |
bfead3b2 | 3069 | create_eq_error: |
107dfcba | 3070 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
bfead3b2 JK |
3071 | eq = &phwi_context->be_eq[i].q; |
3072 | mem = &eq->dma_mem; | |
3073 | if (mem->va) | |
3074 | pci_free_consistent(phba->pcidev, num_eq_pages | |
3075 | * PAGE_SIZE, | |
3076 | mem->va, mem->dma); | |
3077 | } | |
3078 | return ret; | |
6733b39a JK |
3079 | } |
3080 | ||
bfead3b2 | 3081 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
6733b39a JK |
3082 | struct hwi_context_memory *phwi_context) |
3083 | { | |
bfead3b2 | 3084 | unsigned int i, num_cq_pages; |
6733b39a JK |
3085 | struct be_queue_info *cq, *eq; |
3086 | struct be_dma_mem *mem; | |
bfead3b2 | 3087 | struct be_eq_obj *pbe_eq; |
6733b39a | 3088 | void *cq_vaddress; |
deeea8ed | 3089 | int ret = -ENOMEM; |
bfead3b2 | 3090 | dma_addr_t paddr; |
6733b39a | 3091 | |
bfead3b2 JK |
3092 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
3093 | sizeof(struct sol_cqe)); | |
6733b39a | 3094 | |
bfead3b2 JK |
3095 | for (i = 0; i < phba->num_cpus; i++) { |
3096 | cq = &phwi_context->be_cq[i]; | |
3097 | eq = &phwi_context->be_eq[i].q; | |
3098 | pbe_eq = &phwi_context->be_eq[i]; | |
3099 | pbe_eq->cq = cq; | |
3100 | pbe_eq->phba = phba; | |
3101 | mem = &cq->dma_mem; | |
3102 | cq_vaddress = pci_alloc_consistent(phba->pcidev, | |
deeea8ed CJ |
3103 | num_cq_pages * PAGE_SIZE, |
3104 | &paddr); | |
29b33252 PB |
3105 | if (!cq_vaddress) { |
3106 | ret = -ENOMEM; | |
bfead3b2 | 3107 | goto create_cq_error; |
29b33252 | 3108 | } |
deeea8ed | 3109 | |
7da50879 | 3110 | ret = be_fill_queue(cq, phba->params.num_cq_entries, |
bfead3b2 JK |
3111 | sizeof(struct sol_cqe), cq_vaddress); |
3112 | if (ret) { | |
99bc5d55 JSJ |
3113 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3114 | "BM_%d : be_fill_queue Failed " | |
3115 | "for ISCSI CQ\n"); | |
bfead3b2 JK |
3116 | goto create_cq_error; |
3117 | } | |
3118 | ||
3119 | mem->dma = paddr; | |
3120 | ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false, | |
3121 | false, 0); | |
3122 | if (ret) { | |
99bc5d55 JSJ |
3123 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3124 | "BM_%d : beiscsi_cmd_eq_create" | |
3125 | "Failed for ISCSI CQ\n"); | |
bfead3b2 JK |
3126 | goto create_cq_error; |
3127 | } | |
99bc5d55 JSJ |
3128 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3129 | "BM_%d : iscsi cq_id is %d for eq_id %d\n" | |
3130 | "iSCSI CQ CREATED\n", cq->id, eq->id); | |
6733b39a | 3131 | } |
6733b39a | 3132 | return 0; |
bfead3b2 JK |
3133 | |
3134 | create_cq_error: | |
3135 | for (i = 0; i < phba->num_cpus; i++) { | |
3136 | cq = &phwi_context->be_cq[i]; | |
3137 | mem = &cq->dma_mem; | |
3138 | if (mem->va) | |
3139 | pci_free_consistent(phba->pcidev, num_cq_pages | |
3140 | * PAGE_SIZE, | |
3141 | mem->va, mem->dma); | |
3142 | } | |
3143 | return ret; | |
6733b39a JK |
3144 | } |
3145 | ||
3146 | static int | |
3147 | beiscsi_create_def_hdr(struct beiscsi_hba *phba, | |
3148 | struct hwi_context_memory *phwi_context, | |
3149 | struct hwi_controller *phwi_ctrlr, | |
8a86e833 | 3150 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
6733b39a JK |
3151 | { |
3152 | unsigned int idx; | |
3153 | int ret; | |
3154 | struct be_queue_info *dq, *cq; | |
3155 | struct be_dma_mem *mem; | |
3156 | struct be_mem_descriptor *mem_descr; | |
3157 | void *dq_vaddress; | |
3158 | ||
3159 | idx = 0; | |
8a86e833 | 3160 | dq = &phwi_context->be_def_hdrq[ulp_num]; |
bfead3b2 | 3161 | cq = &phwi_context->be_cq[0]; |
6733b39a JK |
3162 | mem = &dq->dma_mem; |
3163 | mem_descr = phba->init_mem; | |
8a86e833 JK |
3164 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
3165 | (ulp_num * MEM_DESCR_OFFSET); | |
6733b39a JK |
3166 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
3167 | ret = be_fill_queue(dq, mem_descr->mem_array[0].size / | |
3168 | sizeof(struct phys_addr), | |
3169 | sizeof(struct phys_addr), dq_vaddress); | |
3170 | if (ret) { | |
99bc5d55 | 3171 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
8a86e833 JK |
3172 | "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n", |
3173 | ulp_num); | |
3174 | ||
6733b39a JK |
3175 | return ret; |
3176 | } | |
457ff3b7 JK |
3177 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
3178 | bus_address.u.a64.address; | |
6733b39a JK |
3179 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq, |
3180 | def_pdu_ring_sz, | |
8a86e833 JK |
3181 | phba->params.defpdu_hdr_sz, |
3182 | BEISCSI_DEFQ_HDR, ulp_num); | |
6733b39a | 3183 | if (ret) { |
99bc5d55 | 3184 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
8a86e833 JK |
3185 | "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n", |
3186 | ulp_num); | |
3187 | ||
6733b39a JK |
3188 | return ret; |
3189 | } | |
99bc5d55 | 3190 | |
8a86e833 JK |
3191 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3192 | "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n", | |
3193 | ulp_num, | |
3194 | phwi_context->be_def_hdrq[ulp_num].id); | |
6733b39a JK |
3195 | return 0; |
3196 | } | |
3197 | ||
3198 | static int | |
3199 | beiscsi_create_def_data(struct beiscsi_hba *phba, | |
3200 | struct hwi_context_memory *phwi_context, | |
3201 | struct hwi_controller *phwi_ctrlr, | |
8a86e833 | 3202 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
6733b39a JK |
3203 | { |
3204 | unsigned int idx; | |
3205 | int ret; | |
3206 | struct be_queue_info *dataq, *cq; | |
3207 | struct be_dma_mem *mem; | |
3208 | struct be_mem_descriptor *mem_descr; | |
3209 | void *dq_vaddress; | |
3210 | ||
3211 | idx = 0; | |
8a86e833 | 3212 | dataq = &phwi_context->be_def_dataq[ulp_num]; |
bfead3b2 | 3213 | cq = &phwi_context->be_cq[0]; |
6733b39a JK |
3214 | mem = &dataq->dma_mem; |
3215 | mem_descr = phba->init_mem; | |
8a86e833 JK |
3216 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
3217 | (ulp_num * MEM_DESCR_OFFSET); | |
6733b39a JK |
3218 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
3219 | ret = be_fill_queue(dataq, mem_descr->mem_array[0].size / | |
3220 | sizeof(struct phys_addr), | |
3221 | sizeof(struct phys_addr), dq_vaddress); | |
3222 | if (ret) { | |
99bc5d55 | 3223 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
8a86e833 JK |
3224 | "BM_%d : be_fill_queue Failed for DEF PDU " |
3225 | "DATA on ULP : %d\n", | |
3226 | ulp_num); | |
3227 | ||
6733b39a JK |
3228 | return ret; |
3229 | } | |
457ff3b7 JK |
3230 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
3231 | bus_address.u.a64.address; | |
6733b39a JK |
3232 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq, |
3233 | def_pdu_ring_sz, | |
8a86e833 JK |
3234 | phba->params.defpdu_data_sz, |
3235 | BEISCSI_DEFQ_DATA, ulp_num); | |
6733b39a | 3236 | if (ret) { |
99bc5d55 JSJ |
3237 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3238 | "BM_%d be_cmd_create_default_pdu_queue" | |
8a86e833 JK |
3239 | " Failed for DEF PDU DATA on ULP : %d\n", |
3240 | ulp_num); | |
6733b39a JK |
3241 | return ret; |
3242 | } | |
8a86e833 | 3243 | |
99bc5d55 | 3244 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
8a86e833 JK |
3245 | "BM_%d : iscsi def data id on ULP : %d is %d\n", |
3246 | ulp_num, | |
3247 | phwi_context->be_def_dataq[ulp_num].id); | |
99bc5d55 | 3248 | |
99bc5d55 | 3249 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
8a86e833 JK |
3250 | "BM_%d : DEFAULT PDU DATA RING CREATED" |
3251 | "on ULP : %d\n", ulp_num); | |
6733b39a JK |
3252 | return 0; |
3253 | } | |
3254 | ||
15a90fe0 JK |
3255 | |
3256 | static int | |
3257 | beiscsi_post_template_hdr(struct beiscsi_hba *phba) | |
3258 | { | |
3259 | struct be_mem_descriptor *mem_descr; | |
3260 | struct mem_array *pm_arr; | |
3261 | struct be_dma_mem sgl; | |
a129d92f | 3262 | int status, ulp_num; |
15a90fe0 | 3263 | |
a129d92f JK |
3264 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
3265 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
3266 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; | |
3267 | mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 + | |
3268 | (ulp_num * MEM_DESCR_OFFSET); | |
3269 | pm_arr = mem_descr->mem_array; | |
15a90fe0 | 3270 | |
a129d92f JK |
3271 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
3272 | status = be_cmd_iscsi_post_template_hdr( | |
3273 | &phba->ctrl, &sgl); | |
15a90fe0 | 3274 | |
a129d92f JK |
3275 | if (status != 0) { |
3276 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
3277 | "BM_%d : Post Template HDR Failed for" | |
3278 | "ULP_%d\n", ulp_num); | |
3279 | return status; | |
3280 | } | |
3281 | ||
3282 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
3283 | "BM_%d : Template HDR Pages Posted for" | |
3284 | "ULP_%d\n", ulp_num); | |
15a90fe0 JK |
3285 | } |
3286 | } | |
15a90fe0 JK |
3287 | return 0; |
3288 | } | |
3289 | ||
6733b39a JK |
3290 | static int |
3291 | beiscsi_post_pages(struct beiscsi_hba *phba) | |
3292 | { | |
3293 | struct be_mem_descriptor *mem_descr; | |
3294 | struct mem_array *pm_arr; | |
3295 | unsigned int page_offset, i; | |
3296 | struct be_dma_mem sgl; | |
843ae752 | 3297 | int status, ulp_num = 0; |
6733b39a JK |
3298 | |
3299 | mem_descr = phba->init_mem; | |
3300 | mem_descr += HWI_MEM_SGE; | |
3301 | pm_arr = mem_descr->mem_array; | |
3302 | ||
90622db3 JK |
3303 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
3304 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) | |
3305 | break; | |
3306 | ||
6733b39a | 3307 | page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io * |
843ae752 | 3308 | phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE; |
6733b39a JK |
3309 | for (i = 0; i < mem_descr->num_elements; i++) { |
3310 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); | |
3311 | status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl, | |
3312 | page_offset, | |
3313 | (pm_arr->size / PAGE_SIZE)); | |
3314 | page_offset += pm_arr->size / PAGE_SIZE; | |
3315 | if (status != 0) { | |
99bc5d55 JSJ |
3316 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3317 | "BM_%d : post sgl failed.\n"); | |
6733b39a JK |
3318 | return status; |
3319 | } | |
3320 | pm_arr++; | |
3321 | } | |
99bc5d55 JSJ |
3322 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3323 | "BM_%d : POSTED PAGES\n"); | |
6733b39a JK |
3324 | return 0; |
3325 | } | |
3326 | ||
bfead3b2 JK |
3327 | static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) |
3328 | { | |
3329 | struct be_dma_mem *mem = &q->dma_mem; | |
c8b25598 | 3330 | if (mem->va) { |
bfead3b2 JK |
3331 | pci_free_consistent(phba->pcidev, mem->size, |
3332 | mem->va, mem->dma); | |
c8b25598 JK |
3333 | mem->va = NULL; |
3334 | } | |
bfead3b2 JK |
3335 | } |
3336 | ||
3337 | static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, | |
3338 | u16 len, u16 entry_size) | |
3339 | { | |
3340 | struct be_dma_mem *mem = &q->dma_mem; | |
3341 | ||
3342 | memset(q, 0, sizeof(*q)); | |
3343 | q->len = len; | |
3344 | q->entry_size = entry_size; | |
3345 | mem->size = len * entry_size; | |
7c845eb5 | 3346 | mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma); |
bfead3b2 | 3347 | if (!mem->va) |
d3ad2bb3 | 3348 | return -ENOMEM; |
bfead3b2 JK |
3349 | return 0; |
3350 | } | |
3351 | ||
6733b39a JK |
3352 | static int |
3353 | beiscsi_create_wrb_rings(struct beiscsi_hba *phba, | |
3354 | struct hwi_context_memory *phwi_context, | |
3355 | struct hwi_controller *phwi_ctrlr) | |
3356 | { | |
3357 | unsigned int wrb_mem_index, offset, size, num_wrb_rings; | |
3358 | u64 pa_addr_lo; | |
4eea99d5 | 3359 | unsigned int idx, num, i, ulp_num; |
6733b39a JK |
3360 | struct mem_array *pwrb_arr; |
3361 | void *wrb_vaddr; | |
3362 | struct be_dma_mem sgl; | |
3363 | struct be_mem_descriptor *mem_descr; | |
a7909b39 | 3364 | struct hwi_wrb_context *pwrb_context; |
6733b39a | 3365 | int status; |
4eea99d5 JK |
3366 | uint8_t ulp_count = 0, ulp_base_num = 0; |
3367 | uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 }; | |
6733b39a JK |
3368 | |
3369 | idx = 0; | |
3370 | mem_descr = phba->init_mem; | |
3371 | mem_descr += HWI_MEM_WRB; | |
3372 | pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl, | |
3373 | GFP_KERNEL); | |
3374 | if (!pwrb_arr) { | |
99bc5d55 JSJ |
3375 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3376 | "BM_%d : Memory alloc failed in create wrb ring.\n"); | |
6733b39a JK |
3377 | return -ENOMEM; |
3378 | } | |
3379 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; | |
3380 | pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address; | |
3381 | num_wrb_rings = mem_descr->mem_array[idx].size / | |
3382 | (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb)); | |
3383 | ||
3384 | for (num = 0; num < phba->params.cxns_per_ctrl; num++) { | |
3385 | if (num_wrb_rings) { | |
3386 | pwrb_arr[num].virtual_address = wrb_vaddr; | |
3387 | pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo; | |
3388 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * | |
3389 | sizeof(struct iscsi_wrb); | |
3390 | wrb_vaddr += pwrb_arr[num].size; | |
3391 | pa_addr_lo += pwrb_arr[num].size; | |
3392 | num_wrb_rings--; | |
3393 | } else { | |
3394 | idx++; | |
3395 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; | |
3396 | pa_addr_lo = mem_descr->mem_array[idx].\ | |
3397 | bus_address.u.a64.address; | |
3398 | num_wrb_rings = mem_descr->mem_array[idx].size / | |
3399 | (phba->params.wrbs_per_cxn * | |
3400 | sizeof(struct iscsi_wrb)); | |
3401 | pwrb_arr[num].virtual_address = wrb_vaddr; | |
3402 | pwrb_arr[num].bus_address.u.a64.address\ | |
3403 | = pa_addr_lo; | |
3404 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * | |
3405 | sizeof(struct iscsi_wrb); | |
3406 | wrb_vaddr += pwrb_arr[num].size; | |
3407 | pa_addr_lo += pwrb_arr[num].size; | |
3408 | num_wrb_rings--; | |
3409 | } | |
3410 | } | |
4eea99d5 JK |
3411 | |
3412 | /* Get the ULP Count */ | |
3413 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) | |
3414 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
3415 | ulp_count++; | |
3416 | ulp_base_num = ulp_num; | |
3417 | cid_count_ulp[ulp_num] = | |
3418 | BEISCSI_GET_CID_COUNT(phba, ulp_num); | |
3419 | } | |
3420 | ||
6733b39a JK |
3421 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
3422 | wrb_mem_index = 0; | |
3423 | offset = 0; | |
3424 | size = 0; | |
3425 | ||
4eea99d5 JK |
3426 | if (ulp_count > 1) { |
3427 | ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT; | |
3428 | ||
3429 | if (!cid_count_ulp[ulp_base_num]) | |
3430 | ulp_base_num = (ulp_base_num + 1) % | |
3431 | BEISCSI_ULP_COUNT; | |
3432 | ||
3433 | cid_count_ulp[ulp_base_num]--; | |
3434 | } | |
3435 | ||
3436 | ||
6733b39a JK |
3437 | hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl); |
3438 | status = be_cmd_wrbq_create(&phba->ctrl, &sgl, | |
4eea99d5 JK |
3439 | &phwi_context->be_wrbq[i], |
3440 | &phwi_ctrlr->wrb_context[i], | |
3441 | ulp_base_num); | |
6733b39a | 3442 | if (status != 0) { |
99bc5d55 JSJ |
3443 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3444 | "BM_%d : wrbq create failed."); | |
1462b8ff | 3445 | kfree(pwrb_arr); |
6733b39a JK |
3446 | return status; |
3447 | } | |
a7909b39 | 3448 | pwrb_context = &phwi_ctrlr->wrb_context[i]; |
a7909b39 | 3449 | BE_SET_CID_TO_CRI(i, pwrb_context->cid); |
6733b39a JK |
3450 | } |
3451 | kfree(pwrb_arr); | |
3452 | return 0; | |
3453 | } | |
3454 | ||
3455 | static void free_wrb_handles(struct beiscsi_hba *phba) | |
3456 | { | |
3457 | unsigned int index; | |
3458 | struct hwi_controller *phwi_ctrlr; | |
3459 | struct hwi_wrb_context *pwrb_context; | |
3460 | ||
3461 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 | 3462 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
6733b39a JK |
3463 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
3464 | kfree(pwrb_context->pwrb_handle_base); | |
3465 | kfree(pwrb_context->pwrb_handle_basestd); | |
3466 | } | |
3467 | } | |
3468 | ||
bfead3b2 JK |
3469 | static void be_mcc_queues_destroy(struct beiscsi_hba *phba) |
3470 | { | |
bfead3b2 | 3471 | struct be_ctrl_info *ctrl = &phba->ctrl; |
d1d5ca88 JB |
3472 | struct be_dma_mem *ptag_mem; |
3473 | struct be_queue_info *q; | |
3474 | int i, tag; | |
bfead3b2 JK |
3475 | |
3476 | q = &phba->ctrl.mcc_obj.q; | |
d1d5ca88 JB |
3477 | for (i = 0; i < MAX_MCC_CMD; i++) { |
3478 | tag = i + 1; | |
3479 | if (!test_bit(MCC_TAG_STATE_RUNNING, | |
3480 | &ctrl->ptag_state[tag].tag_state)) | |
3481 | continue; | |
3482 | ||
3483 | if (test_bit(MCC_TAG_STATE_TIMEOUT, | |
3484 | &ctrl->ptag_state[tag].tag_state)) { | |
3485 | ptag_mem = &ctrl->ptag_state[tag].tag_mem_state; | |
3486 | if (ptag_mem->size) { | |
3487 | pci_free_consistent(ctrl->pdev, | |
3488 | ptag_mem->size, | |
3489 | ptag_mem->va, | |
3490 | ptag_mem->dma); | |
3491 | ptag_mem->size = 0; | |
3492 | } | |
3493 | continue; | |
3494 | } | |
3495 | /** | |
3496 | * If MCC is still active and waiting then wake up the process. | |
3497 | * We are here only because port is going offline. The process | |
3498 | * sees that (BEISCSI_HBA_ONLINE is cleared) and EIO error is | |
3499 | * returned for the operation and allocated memory cleaned up. | |
3500 | */ | |
3501 | if (waitqueue_active(&ctrl->mcc_wait[tag])) { | |
3502 | ctrl->mcc_tag_status[tag] = MCC_STATUS_FAILED; | |
3503 | ctrl->mcc_tag_status[tag] |= CQE_VALID_MASK; | |
3504 | wake_up_interruptible(&ctrl->mcc_wait[tag]); | |
3505 | /* | |
3506 | * Control tag info gets reinitialized in enable | |
3507 | * so wait for the process to clear running state. | |
3508 | */ | |
3509 | while (test_bit(MCC_TAG_STATE_RUNNING, | |
3510 | &ctrl->ptag_state[tag].tag_state)) | |
3511 | schedule_timeout_uninterruptible(HZ); | |
3512 | } | |
3513 | /** | |
3514 | * For MCC with tag_states MCC_TAG_STATE_ASYNC and | |
3515 | * MCC_TAG_STATE_IGNORE nothing needs to done. | |
3516 | */ | |
3517 | } | |
4e2bdf7a | 3518 | if (q->created) { |
bfead3b2 | 3519 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ); |
4e2bdf7a JSJ |
3520 | be_queue_free(phba, q); |
3521 | } | |
bfead3b2 JK |
3522 | |
3523 | q = &phba->ctrl.mcc_obj.cq; | |
4e2bdf7a | 3524 | if (q->created) { |
bfead3b2 | 3525 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
4e2bdf7a JSJ |
3526 | be_queue_free(phba, q); |
3527 | } | |
bfead3b2 JK |
3528 | } |
3529 | ||
bfead3b2 JK |
3530 | static int be_mcc_queues_create(struct beiscsi_hba *phba, |
3531 | struct hwi_context_memory *phwi_context) | |
3532 | { | |
3533 | struct be_queue_info *q, *cq; | |
3534 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
3535 | ||
3536 | /* Alloc MCC compl queue */ | |
3537 | cq = &phba->ctrl.mcc_obj.cq; | |
3538 | if (be_queue_alloc(phba, cq, MCC_CQ_LEN, | |
3539 | sizeof(struct be_mcc_compl))) | |
3540 | goto err; | |
3541 | /* Ask BE to create MCC compl queue; */ | |
3542 | if (phba->msix_enabled) { | |
3543 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq | |
3544 | [phba->num_cpus].q, false, true, 0)) | |
3545 | goto mcc_cq_free; | |
3546 | } else { | |
3547 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q, | |
3548 | false, true, 0)) | |
3549 | goto mcc_cq_free; | |
3550 | } | |
3551 | ||
3552 | /* Alloc MCC queue */ | |
3553 | q = &phba->ctrl.mcc_obj.q; | |
3554 | if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) | |
3555 | goto mcc_cq_destroy; | |
3556 | ||
3557 | /* Ask BE to create MCC queue */ | |
35e66019 | 3558 | if (beiscsi_cmd_mccq_create(phba, q, cq)) |
bfead3b2 JK |
3559 | goto mcc_q_free; |
3560 | ||
3561 | return 0; | |
3562 | ||
3563 | mcc_q_free: | |
3564 | be_queue_free(phba, q); | |
3565 | mcc_cq_destroy: | |
3566 | beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ); | |
3567 | mcc_cq_free: | |
3568 | be_queue_free(phba, cq); | |
3569 | err: | |
d3ad2bb3 | 3570 | return -ENOMEM; |
bfead3b2 JK |
3571 | } |
3572 | ||
107dfcba JSJ |
3573 | /** |
3574 | * find_num_cpus()- Get the CPU online count | |
3575 | * @phba: ptr to priv structure | |
3576 | * | |
3577 | * CPU count is used for creating EQ. | |
3578 | **/ | |
3579 | static void find_num_cpus(struct beiscsi_hba *phba) | |
bfead3b2 JK |
3580 | { |
3581 | int num_cpus = 0; | |
3582 | ||
3583 | num_cpus = num_online_cpus(); | |
bfead3b2 | 3584 | |
22abeef0 JSJ |
3585 | switch (phba->generation) { |
3586 | case BE_GEN2: | |
3587 | case BE_GEN3: | |
3588 | phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ? | |
3589 | BEISCSI_MAX_NUM_CPUS : num_cpus; | |
3590 | break; | |
3591 | case BE_GEN4: | |
68c26a3a JK |
3592 | /* |
3593 | * If eqid_count == 1 fall back to | |
3594 | * INTX mechanism | |
3595 | **/ | |
3596 | if (phba->fw_config.eqid_count == 1) { | |
3597 | enable_msix = 0; | |
3598 | phba->num_cpus = 1; | |
3599 | return; | |
3600 | } | |
3601 | ||
3602 | phba->num_cpus = | |
3603 | (num_cpus > (phba->fw_config.eqid_count - 1)) ? | |
3604 | (phba->fw_config.eqid_count - 1) : num_cpus; | |
22abeef0 JSJ |
3605 | break; |
3606 | default: | |
3607 | phba->num_cpus = 1; | |
3608 | } | |
6733b39a JK |
3609 | } |
3610 | ||
d1d5ca88 JB |
3611 | static void hwi_purge_eq(struct beiscsi_hba *phba) |
3612 | { | |
3613 | struct hwi_controller *phwi_ctrlr; | |
3614 | struct hwi_context_memory *phwi_context; | |
3615 | struct be_queue_info *eq; | |
3616 | struct be_eq_entry *eqe = NULL; | |
3617 | int i, eq_msix; | |
3618 | unsigned int num_processed; | |
3619 | ||
3620 | if (beiscsi_hba_in_error(phba)) | |
3621 | return; | |
3622 | ||
3623 | phwi_ctrlr = phba->phwi_ctrlr; | |
3624 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
3625 | if (phba->msix_enabled) | |
3626 | eq_msix = 1; | |
3627 | else | |
3628 | eq_msix = 0; | |
3629 | ||
3630 | for (i = 0; i < (phba->num_cpus + eq_msix); i++) { | |
3631 | eq = &phwi_context->be_eq[i].q; | |
3632 | eqe = queue_tail_node(eq); | |
3633 | num_processed = 0; | |
3634 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] | |
3635 | & EQE_VALID_MASK) { | |
3636 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); | |
3637 | queue_tail_inc(eq); | |
3638 | eqe = queue_tail_node(eq); | |
3639 | num_processed++; | |
3640 | } | |
3641 | ||
3642 | if (num_processed) | |
3643 | hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1); | |
3644 | } | |
3645 | } | |
3646 | ||
3647 | static void hwi_cleanup_port(struct beiscsi_hba *phba) | |
3648 | { | |
3649 | struct be_queue_info *q; | |
3650 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
3651 | struct hwi_controller *phwi_ctrlr; | |
3652 | struct hwi_context_memory *phwi_context; | |
938f372c | 3653 | struct hd_async_context *pasync_ctx; |
d1d5ca88 JB |
3654 | int i, eq_for_mcc, ulp_num; |
3655 | ||
3656 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) | |
3657 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) | |
3658 | beiscsi_cmd_iscsi_cleanup(phba, ulp_num); | |
3659 | ||
3660 | /** | |
3661 | * Purge all EQ entries that may have been left out. This is to | |
3662 | * workaround a problem we've seen occasionally where driver gets an | |
3663 | * interrupt with EQ entry bit set after stopping the controller. | |
3664 | */ | |
3665 | hwi_purge_eq(phba); | |
3666 | ||
3667 | phwi_ctrlr = phba->phwi_ctrlr; | |
3668 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
3669 | ||
3670 | be_cmd_iscsi_remove_template_hdr(ctrl); | |
3671 | ||
3672 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { | |
3673 | q = &phwi_context->be_wrbq[i]; | |
3674 | if (q->created) | |
3675 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ); | |
3676 | } | |
3677 | kfree(phwi_context->be_wrbq); | |
3678 | free_wrb_handles(phba); | |
3679 | ||
3680 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { | |
3681 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
3682 | ||
3683 | q = &phwi_context->be_def_hdrq[ulp_num]; | |
3684 | if (q->created) | |
3685 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); | |
3686 | ||
3687 | q = &phwi_context->be_def_dataq[ulp_num]; | |
3688 | if (q->created) | |
3689 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); | |
3690 | ||
3691 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; | |
3692 | } | |
3693 | } | |
3694 | ||
3695 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); | |
3696 | ||
3697 | for (i = 0; i < (phba->num_cpus); i++) { | |
3698 | q = &phwi_context->be_cq[i]; | |
3699 | if (q->created) { | |
3700 | be_queue_free(phba, q); | |
3701 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); | |
3702 | } | |
3703 | } | |
3704 | ||
3705 | be_mcc_queues_destroy(phba); | |
3706 | if (phba->msix_enabled) | |
3707 | eq_for_mcc = 1; | |
3708 | else | |
3709 | eq_for_mcc = 0; | |
3710 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { | |
3711 | q = &phwi_context->be_eq[i].q; | |
3712 | if (q->created) { | |
3713 | be_queue_free(phba, q); | |
3714 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ); | |
3715 | } | |
3716 | } | |
4ee1ec42 JB |
3717 | /* this ensures complete FW cleanup */ |
3718 | beiscsi_cmd_function_reset(phba); | |
d1d5ca88 JB |
3719 | /* last communication, indicate driver is unloading */ |
3720 | beiscsi_cmd_special_wrb(&phba->ctrl, 0); | |
3721 | } | |
4ee1ec42 | 3722 | |
6733b39a JK |
3723 | static int hwi_init_port(struct beiscsi_hba *phba) |
3724 | { | |
3725 | struct hwi_controller *phwi_ctrlr; | |
3726 | struct hwi_context_memory *phwi_context; | |
3727 | unsigned int def_pdu_ring_sz; | |
3728 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
8a86e833 | 3729 | int status, ulp_num; |
6733b39a | 3730 | |
6733b39a | 3731 | phwi_ctrlr = phba->phwi_ctrlr; |
6733b39a | 3732 | phwi_context = phwi_ctrlr->phwi_ctxt; |
73af08e1 | 3733 | phwi_context->max_eqd = 128; |
bfead3b2 | 3734 | phwi_context->min_eqd = 0; |
1b7a7ddc | 3735 | phwi_context->cur_eqd = 32; |
4d2ee1e6 | 3736 | /* set port optic state to unknown */ |
53aefe25 | 3737 | phba->optic_state = 0xff; |
bfead3b2 JK |
3738 | |
3739 | status = beiscsi_create_eqs(phba, phwi_context); | |
6733b39a | 3740 | if (status != 0) { |
99bc5d55 JSJ |
3741 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3742 | "BM_%d : EQ not created\n"); | |
6733b39a JK |
3743 | goto error; |
3744 | } | |
3745 | ||
bfead3b2 JK |
3746 | status = be_mcc_queues_create(phba, phwi_context); |
3747 | if (status != 0) | |
3748 | goto error; | |
3749 | ||
480195c2 | 3750 | status = beiscsi_check_supported_fw(ctrl, phba); |
6733b39a | 3751 | if (status != 0) { |
99bc5d55 JSJ |
3752 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3753 | "BM_%d : Unsupported fw version\n"); | |
6733b39a JK |
3754 | goto error; |
3755 | } | |
3756 | ||
bfead3b2 | 3757 | status = beiscsi_create_cqs(phba, phwi_context); |
6733b39a | 3758 | if (status != 0) { |
99bc5d55 JSJ |
3759 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3760 | "BM_%d : CQ not created\n"); | |
6733b39a JK |
3761 | goto error; |
3762 | } | |
3763 | ||
8a86e833 JK |
3764 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
3765 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
8a86e833 JK |
3766 | def_pdu_ring_sz = |
3767 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
3768 | sizeof(struct phys_addr); | |
3769 | ||
3770 | status = beiscsi_create_def_hdr(phba, phwi_context, | |
3771 | phwi_ctrlr, | |
3772 | def_pdu_ring_sz, | |
3773 | ulp_num); | |
3774 | if (status != 0) { | |
3775 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
3776 | "BM_%d : Default Header not created for ULP : %d\n", | |
3777 | ulp_num); | |
3778 | goto error; | |
3779 | } | |
3780 | ||
3781 | status = beiscsi_create_def_data(phba, phwi_context, | |
3782 | phwi_ctrlr, | |
3783 | def_pdu_ring_sz, | |
3784 | ulp_num); | |
3785 | if (status != 0) { | |
3786 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
3787 | "BM_%d : Default Data not created for ULP : %d\n", | |
3788 | ulp_num); | |
3789 | goto error; | |
3790 | } | |
f79929de JB |
3791 | /** |
3792 | * Now that the default PDU rings have been created, | |
3793 | * let EP know about it. | |
3794 | * Call beiscsi_cmd_iscsi_cleanup before posting? | |
3795 | */ | |
938f372c JB |
3796 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR, |
3797 | ulp_num); | |
3798 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA, | |
3799 | ulp_num); | |
8a86e833 | 3800 | } |
6733b39a JK |
3801 | } |
3802 | ||
3803 | status = beiscsi_post_pages(phba); | |
3804 | if (status != 0) { | |
99bc5d55 JSJ |
3805 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3806 | "BM_%d : Post SGL Pages Failed\n"); | |
6733b39a JK |
3807 | goto error; |
3808 | } | |
3809 | ||
15a90fe0 JK |
3810 | status = beiscsi_post_template_hdr(phba); |
3811 | if (status != 0) { | |
3812 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
3813 | "BM_%d : Template HDR Posting for CXN Failed\n"); | |
3814 | } | |
3815 | ||
6733b39a JK |
3816 | status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr); |
3817 | if (status != 0) { | |
99bc5d55 JSJ |
3818 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3819 | "BM_%d : WRB Rings not created\n"); | |
6733b39a JK |
3820 | goto error; |
3821 | } | |
3822 | ||
8a86e833 JK |
3823 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
3824 | uint16_t async_arr_idx = 0; | |
3825 | ||
3826 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
3827 | uint16_t cri = 0; | |
938f372c | 3828 | struct hd_async_context *pasync_ctx; |
8a86e833 JK |
3829 | |
3830 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX( | |
3831 | phwi_ctrlr, ulp_num); | |
3832 | for (cri = 0; cri < | |
3833 | phba->params.cxns_per_ctrl; cri++) { | |
3834 | if (ulp_num == BEISCSI_GET_ULP_FROM_CRI | |
3835 | (phwi_ctrlr, cri)) | |
3836 | pasync_ctx->cid_to_async_cri_map[ | |
3837 | phwi_ctrlr->wrb_context[cri].cid] = | |
3838 | async_arr_idx++; | |
3839 | } | |
938f372c JB |
3840 | /** |
3841 | * Now that the default PDU rings have been created, | |
3842 | * let EP know about it. | |
3843 | */ | |
3844 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR, | |
3845 | ulp_num); | |
3846 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA, | |
3847 | ulp_num); | |
8a86e833 JK |
3848 | } |
3849 | } | |
3850 | ||
99bc5d55 JSJ |
3851 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3852 | "BM_%d : hwi_init_port success\n"); | |
6733b39a JK |
3853 | return 0; |
3854 | ||
3855 | error: | |
99bc5d55 JSJ |
3856 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3857 | "BM_%d : hwi_init_port failed"); | |
4d2ee1e6 | 3858 | hwi_cleanup_port(phba); |
a49e06d5 | 3859 | return status; |
6733b39a JK |
3860 | } |
3861 | ||
6733b39a JK |
3862 | static int hwi_init_controller(struct beiscsi_hba *phba) |
3863 | { | |
3864 | struct hwi_controller *phwi_ctrlr; | |
3865 | ||
3866 | phwi_ctrlr = phba->phwi_ctrlr; | |
3867 | if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) { | |
3868 | phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba-> | |
3869 | init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address; | |
99bc5d55 JSJ |
3870 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3871 | "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n", | |
3872 | phwi_ctrlr->phwi_ctxt); | |
6733b39a | 3873 | } else { |
99bc5d55 JSJ |
3874 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3875 | "BM_%d : HWI_MEM_ADDN_CONTEXT is more " | |
3876 | "than one element.Failing to load\n"); | |
6733b39a JK |
3877 | return -ENOMEM; |
3878 | } | |
3879 | ||
3880 | iscsi_init_global_templates(phba); | |
3ec78271 JK |
3881 | if (beiscsi_init_wrb_handle(phba)) |
3882 | return -ENOMEM; | |
3883 | ||
a7909b39 JK |
3884 | if (hwi_init_async_pdu_ctx(phba)) { |
3885 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
3886 | "BM_%d : hwi_init_async_pdu_ctx failed\n"); | |
3887 | return -ENOMEM; | |
3888 | } | |
3889 | ||
6733b39a | 3890 | if (hwi_init_port(phba) != 0) { |
99bc5d55 JSJ |
3891 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3892 | "BM_%d : hwi_init_controller failed\n"); | |
3893 | ||
6733b39a JK |
3894 | return -ENOMEM; |
3895 | } | |
3896 | return 0; | |
3897 | } | |
3898 | ||
3899 | static void beiscsi_free_mem(struct beiscsi_hba *phba) | |
3900 | { | |
3901 | struct be_mem_descriptor *mem_descr; | |
3902 | int i, j; | |
3903 | ||
3904 | mem_descr = phba->init_mem; | |
3905 | i = 0; | |
3906 | j = 0; | |
3907 | for (i = 0; i < SE_MEM_MAX; i++) { | |
3908 | for (j = mem_descr->num_elements; j > 0; j--) { | |
3909 | pci_free_consistent(phba->pcidev, | |
3910 | mem_descr->mem_array[j - 1].size, | |
3911 | mem_descr->mem_array[j - 1].virtual_address, | |
457ff3b7 JK |
3912 | (unsigned long)mem_descr->mem_array[j - 1]. |
3913 | bus_address.u.a64.address); | |
6733b39a | 3914 | } |
8a86e833 | 3915 | |
6733b39a JK |
3916 | kfree(mem_descr->mem_array); |
3917 | mem_descr++; | |
3918 | } | |
3919 | kfree(phba->init_mem); | |
a7909b39 | 3920 | kfree(phba->phwi_ctrlr->wrb_context); |
6733b39a JK |
3921 | kfree(phba->phwi_ctrlr); |
3922 | } | |
3923 | ||
3924 | static int beiscsi_init_controller(struct beiscsi_hba *phba) | |
3925 | { | |
3926 | int ret = -ENOMEM; | |
3927 | ||
3928 | ret = beiscsi_get_memory(phba); | |
3929 | if (ret < 0) { | |
99bc5d55 JSJ |
3930 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3931 | "BM_%d : beiscsi_dev_probe -" | |
3932 | "Failed in beiscsi_alloc_memory\n"); | |
6733b39a JK |
3933 | return ret; |
3934 | } | |
3935 | ||
3936 | ret = hwi_init_controller(phba); | |
3937 | if (ret) | |
3938 | goto free_init; | |
99bc5d55 JSJ |
3939 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
3940 | "BM_%d : Return success from beiscsi_init_controller"); | |
3941 | ||
6733b39a JK |
3942 | return 0; |
3943 | ||
3944 | free_init: | |
3945 | beiscsi_free_mem(phba); | |
a49e06d5 | 3946 | return ret; |
6733b39a JK |
3947 | } |
3948 | ||
3949 | static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) | |
3950 | { | |
3951 | struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg; | |
3952 | struct sgl_handle *psgl_handle; | |
3953 | struct iscsi_sge *pfrag; | |
90622db3 JK |
3954 | unsigned int arr_index, i, idx; |
3955 | unsigned int ulp_icd_start, ulp_num = 0; | |
6733b39a JK |
3956 | |
3957 | phba->io_sgl_hndl_avbl = 0; | |
3958 | phba->eh_sgl_hndl_avbl = 0; | |
bfead3b2 | 3959 | |
6733b39a JK |
3960 | mem_descr_sglh = phba->init_mem; |
3961 | mem_descr_sglh += HWI_MEM_SGLH; | |
3962 | if (1 == mem_descr_sglh->num_elements) { | |
3963 | phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * | |
3964 | phba->params.ios_per_ctrl, | |
3965 | GFP_KERNEL); | |
3966 | if (!phba->io_sgl_hndl_base) { | |
99bc5d55 JSJ |
3967 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3968 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
6733b39a JK |
3969 | return -ENOMEM; |
3970 | } | |
3971 | phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * | |
3972 | (phba->params.icds_per_ctrl - | |
3973 | phba->params.ios_per_ctrl), | |
3974 | GFP_KERNEL); | |
3975 | if (!phba->eh_sgl_hndl_base) { | |
3976 | kfree(phba->io_sgl_hndl_base); | |
99bc5d55 JSJ |
3977 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3978 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
6733b39a JK |
3979 | return -ENOMEM; |
3980 | } | |
3981 | } else { | |
99bc5d55 JSJ |
3982 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3983 | "BM_%d : HWI_MEM_SGLH is more than one element." | |
3984 | "Failing to load\n"); | |
6733b39a JK |
3985 | return -ENOMEM; |
3986 | } | |
3987 | ||
3988 | arr_index = 0; | |
3989 | idx = 0; | |
3990 | while (idx < mem_descr_sglh->num_elements) { | |
3991 | psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address; | |
3992 | ||
3993 | for (i = 0; i < (mem_descr_sglh->mem_array[idx].size / | |
3994 | sizeof(struct sgl_handle)); i++) { | |
3995 | if (arr_index < phba->params.ios_per_ctrl) { | |
3996 | phba->io_sgl_hndl_base[arr_index] = psgl_handle; | |
3997 | phba->io_sgl_hndl_avbl++; | |
3998 | arr_index++; | |
3999 | } else { | |
4000 | phba->eh_sgl_hndl_base[arr_index - | |
4001 | phba->params.ios_per_ctrl] = | |
4002 | psgl_handle; | |
4003 | arr_index++; | |
4004 | phba->eh_sgl_hndl_avbl++; | |
4005 | } | |
4006 | psgl_handle++; | |
4007 | } | |
4008 | idx++; | |
4009 | } | |
99bc5d55 JSJ |
4010 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
4011 | "BM_%d : phba->io_sgl_hndl_avbl=%d" | |
4012 | "phba->eh_sgl_hndl_avbl=%d\n", | |
4013 | phba->io_sgl_hndl_avbl, | |
4014 | phba->eh_sgl_hndl_avbl); | |
4015 | ||
6733b39a JK |
4016 | mem_descr_sg = phba->init_mem; |
4017 | mem_descr_sg += HWI_MEM_SGE; | |
99bc5d55 JSJ |
4018 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
4019 | "\n BM_%d : mem_descr_sg->num_elements=%d\n", | |
4020 | mem_descr_sg->num_elements); | |
4021 | ||
90622db3 JK |
4022 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
4023 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) | |
4024 | break; | |
4025 | ||
4026 | ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; | |
4027 | ||
6733b39a JK |
4028 | arr_index = 0; |
4029 | idx = 0; | |
4030 | while (idx < mem_descr_sg->num_elements) { | |
4031 | pfrag = mem_descr_sg->mem_array[idx].virtual_address; | |
4032 | ||
4033 | for (i = 0; | |
4034 | i < (mem_descr_sg->mem_array[idx].size) / | |
4035 | (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io); | |
4036 | i++) { | |
4037 | if (arr_index < phba->params.ios_per_ctrl) | |
4038 | psgl_handle = phba->io_sgl_hndl_base[arr_index]; | |
4039 | else | |
4040 | psgl_handle = phba->eh_sgl_hndl_base[arr_index - | |
4041 | phba->params.ios_per_ctrl]; | |
4042 | psgl_handle->pfrag = pfrag; | |
4043 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0); | |
4044 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); | |
4045 | pfrag += phba->params.num_sge_per_io; | |
90622db3 | 4046 | psgl_handle->sgl_index = ulp_icd_start + arr_index++; |
6733b39a JK |
4047 | } |
4048 | idx++; | |
4049 | } | |
4050 | phba->io_sgl_free_index = 0; | |
4051 | phba->io_sgl_alloc_index = 0; | |
4052 | phba->eh_sgl_free_index = 0; | |
4053 | phba->eh_sgl_alloc_index = 0; | |
4054 | return 0; | |
4055 | } | |
4056 | ||
4057 | static int hba_setup_cid_tbls(struct beiscsi_hba *phba) | |
4058 | { | |
0a3db7c0 JK |
4059 | int ret; |
4060 | uint16_t i, ulp_num; | |
4061 | struct ulp_cid_info *ptr_cid_info = NULL; | |
6733b39a | 4062 | |
0a3db7c0 JK |
4063 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
4064 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { | |
4065 | ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info), | |
4066 | GFP_KERNEL); | |
4067 | ||
4068 | if (!ptr_cid_info) { | |
4069 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
4070 | "BM_%d : Failed to allocate memory" | |
4071 | "for ULP_CID_INFO for ULP : %d\n", | |
4072 | ulp_num); | |
4073 | ret = -ENOMEM; | |
4074 | goto free_memory; | |
4075 | ||
4076 | } | |
4077 | ||
4078 | /* Allocate memory for CID array */ | |
4079 | ptr_cid_info->cid_array = kzalloc(sizeof(void *) * | |
4080 | BEISCSI_GET_CID_COUNT(phba, | |
4081 | ulp_num), GFP_KERNEL); | |
4082 | if (!ptr_cid_info->cid_array) { | |
4083 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
4084 | "BM_%d : Failed to allocate memory" | |
4085 | "for CID_ARRAY for ULP : %d\n", | |
4086 | ulp_num); | |
4087 | kfree(ptr_cid_info); | |
4088 | ptr_cid_info = NULL; | |
4089 | ret = -ENOMEM; | |
4090 | ||
4091 | goto free_memory; | |
4092 | } | |
4093 | ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT( | |
4094 | phba, ulp_num); | |
4095 | ||
4096 | /* Save the cid_info_array ptr */ | |
4097 | phba->cid_array_info[ulp_num] = ptr_cid_info; | |
4098 | } | |
6733b39a | 4099 | } |
c2462288 | 4100 | phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) * |
a7909b39 | 4101 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
6733b39a | 4102 | if (!phba->ep_array) { |
99bc5d55 JSJ |
4103 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
4104 | "BM_%d : Failed to allocate memory in " | |
4105 | "hba_setup_cid_tbls\n"); | |
0a3db7c0 JK |
4106 | ret = -ENOMEM; |
4107 | ||
4108 | goto free_memory; | |
6733b39a | 4109 | } |
a7909b39 JK |
4110 | |
4111 | phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) * | |
4112 | phba->params.cxns_per_ctrl, GFP_KERNEL); | |
4113 | if (!phba->conn_table) { | |
4114 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
4115 | "BM_%d : Failed to allocate memory in" | |
4116 | "hba_setup_cid_tbls\n"); | |
4117 | ||
a7909b39 | 4118 | kfree(phba->ep_array); |
a7909b39 | 4119 | phba->ep_array = NULL; |
0a3db7c0 | 4120 | ret = -ENOMEM; |
5f2d25ef TH |
4121 | |
4122 | goto free_memory; | |
6733b39a | 4123 | } |
a7909b39 | 4124 | |
0a3db7c0 JK |
4125 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
4126 | ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num; | |
4127 | ||
4128 | ptr_cid_info = phba->cid_array_info[ulp_num]; | |
4129 | ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] = | |
4130 | phba->phwi_ctrlr->wrb_context[i].cid; | |
4131 | ||
4132 | } | |
4133 | ||
4134 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { | |
4135 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { | |
4136 | ptr_cid_info = phba->cid_array_info[ulp_num]; | |
a7909b39 | 4137 | |
0a3db7c0 JK |
4138 | ptr_cid_info->cid_alloc = 0; |
4139 | ptr_cid_info->cid_free = 0; | |
4140 | } | |
4141 | } | |
6733b39a | 4142 | return 0; |
0a3db7c0 JK |
4143 | |
4144 | free_memory: | |
4145 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { | |
4146 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { | |
4147 | ptr_cid_info = phba->cid_array_info[ulp_num]; | |
4148 | ||
4149 | if (ptr_cid_info) { | |
4150 | kfree(ptr_cid_info->cid_array); | |
4151 | kfree(ptr_cid_info); | |
4152 | phba->cid_array_info[ulp_num] = NULL; | |
4153 | } | |
4154 | } | |
4155 | } | |
4156 | ||
4157 | return ret; | |
6733b39a JK |
4158 | } |
4159 | ||
238f6b72 | 4160 | static void hwi_enable_intr(struct beiscsi_hba *phba) |
6733b39a JK |
4161 | { |
4162 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
4163 | struct hwi_controller *phwi_ctrlr; | |
4164 | struct hwi_context_memory *phwi_context; | |
4165 | struct be_queue_info *eq; | |
4166 | u8 __iomem *addr; | |
bfead3b2 | 4167 | u32 reg, i; |
6733b39a JK |
4168 | u32 enabled; |
4169 | ||
4170 | phwi_ctrlr = phba->phwi_ctrlr; | |
4171 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
4172 | ||
6733b39a JK |
4173 | addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg + |
4174 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET); | |
4175 | reg = ioread32(addr); | |
6733b39a JK |
4176 | |
4177 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; | |
4178 | if (!enabled) { | |
4179 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; | |
99bc5d55 JSJ |
4180 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
4181 | "BM_%d : reg =x%08x addr=%p\n", reg, addr); | |
6733b39a | 4182 | iowrite32(reg, addr); |
665d6d94 JK |
4183 | } |
4184 | ||
4185 | if (!phba->msix_enabled) { | |
4186 | eq = &phwi_context->be_eq[0].q; | |
99bc5d55 JSJ |
4187 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
4188 | "BM_%d : eq->id=%d\n", eq->id); | |
4189 | ||
665d6d94 JK |
4190 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
4191 | } else { | |
4192 | for (i = 0; i <= phba->num_cpus; i++) { | |
4193 | eq = &phwi_context->be_eq[i].q; | |
99bc5d55 JSJ |
4194 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
4195 | "BM_%d : eq->id=%d\n", eq->id); | |
bfead3b2 JK |
4196 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
4197 | } | |
c03af1ae | 4198 | } |
6733b39a JK |
4199 | } |
4200 | ||
4201 | static void hwi_disable_intr(struct beiscsi_hba *phba) | |
4202 | { | |
4203 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
4204 | ||
4205 | u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; | |
4206 | u32 reg = ioread32(addr); | |
4207 | ||
4208 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; | |
4209 | if (enabled) { | |
4210 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; | |
4211 | iowrite32(reg, addr); | |
4212 | } else | |
99bc5d55 JSJ |
4213 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
4214 | "BM_%d : In hwi_disable_intr, Already Disabled\n"); | |
6733b39a JK |
4215 | } |
4216 | ||
4217 | static int beiscsi_init_port(struct beiscsi_hba *phba) | |
4218 | { | |
4219 | int ret; | |
4220 | ||
4221 | ret = beiscsi_init_controller(phba); | |
4222 | if (ret < 0) { | |
99bc5d55 JSJ |
4223 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
4224 | "BM_%d : beiscsi_dev_probe - Failed in" | |
4225 | "beiscsi_init_controller\n"); | |
6733b39a JK |
4226 | return ret; |
4227 | } | |
4228 | ret = beiscsi_init_sgl_handle(phba); | |
4229 | if (ret < 0) { | |
99bc5d55 JSJ |
4230 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
4231 | "BM_%d : beiscsi_dev_probe - Failed in" | |
4232 | "beiscsi_init_sgl_handle\n"); | |
6733b39a JK |
4233 | goto do_cleanup_ctrlr; |
4234 | } | |
4235 | ||
deeea8ed CJ |
4236 | ret = hba_setup_cid_tbls(phba); |
4237 | if (ret < 0) { | |
99bc5d55 JSJ |
4238 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
4239 | "BM_%d : Failed in hba_setup_cid_tbls\n"); | |
6733b39a JK |
4240 | kfree(phba->io_sgl_hndl_base); |
4241 | kfree(phba->eh_sgl_hndl_base); | |
4242 | goto do_cleanup_ctrlr; | |
4243 | } | |
4244 | ||
4245 | return ret; | |
4246 | ||
4247 | do_cleanup_ctrlr: | |
4d2ee1e6 | 4248 | hwi_cleanup_port(phba); |
6733b39a JK |
4249 | return ret; |
4250 | } | |
4251 | ||
4d2ee1e6 | 4252 | static void beiscsi_cleanup_port(struct beiscsi_hba *phba) |
6733b39a | 4253 | { |
0a3db7c0 | 4254 | struct ulp_cid_info *ptr_cid_info = NULL; |
f79929de | 4255 | int ulp_num; |
6733b39a | 4256 | |
6733b39a JK |
4257 | kfree(phba->io_sgl_hndl_base); |
4258 | kfree(phba->eh_sgl_hndl_base); | |
6733b39a | 4259 | kfree(phba->ep_array); |
a7909b39 | 4260 | kfree(phba->conn_table); |
0a3db7c0 JK |
4261 | |
4262 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { | |
4263 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { | |
4264 | ptr_cid_info = phba->cid_array_info[ulp_num]; | |
4265 | ||
4266 | if (ptr_cid_info) { | |
4267 | kfree(ptr_cid_info->cid_array); | |
4268 | kfree(ptr_cid_info); | |
4269 | phba->cid_array_info[ulp_num] = NULL; | |
4270 | } | |
4271 | } | |
4272 | } | |
6733b39a JK |
4273 | } |
4274 | ||
43f388b0 JK |
4275 | /** |
4276 | * beiscsi_free_mgmt_task_handles()- Free driver CXN resources | |
4277 | * @beiscsi_conn: ptr to the conn to be cleaned up | |
4a4a11b9 | 4278 | * @task: ptr to iscsi_task resource to be freed. |
43f388b0 JK |
4279 | * |
4280 | * Free driver mgmt resources binded to CXN. | |
4281 | **/ | |
4282 | void | |
4a4a11b9 JK |
4283 | beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn, |
4284 | struct iscsi_task *task) | |
43f388b0 JK |
4285 | { |
4286 | struct beiscsi_io_task *io_task; | |
4287 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4288 | struct hwi_wrb_context *pwrb_context; | |
4289 | struct hwi_controller *phwi_ctrlr; | |
a7909b39 JK |
4290 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
4291 | beiscsi_conn->beiscsi_conn_cid); | |
43f388b0 JK |
4292 | |
4293 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 JK |
4294 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
4295 | ||
4a4a11b9 | 4296 | io_task = task->dd_data; |
43f388b0 JK |
4297 | |
4298 | if (io_task->pwrb_handle) { | |
e1f9d31e | 4299 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
43f388b0 JK |
4300 | io_task->pwrb_handle = NULL; |
4301 | } | |
4302 | ||
4303 | if (io_task->psgl_handle) { | |
e1f9d31e | 4304 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
43f388b0 JK |
4305 | io_task->psgl_handle = NULL; |
4306 | } | |
4307 | ||
eb1c4692 | 4308 | if (io_task->mtask_addr) { |
43f388b0 JK |
4309 | pci_unmap_single(phba->pcidev, |
4310 | io_task->mtask_addr, | |
4311 | io_task->mtask_data_count, | |
4312 | PCI_DMA_TODEVICE); | |
eb1c4692 JSJ |
4313 | io_task->mtask_addr = 0; |
4314 | } | |
43f388b0 JK |
4315 | } |
4316 | ||
d629c471 JSJ |
4317 | /** |
4318 | * beiscsi_cleanup_task()- Free driver resources of the task | |
4319 | * @task: ptr to the iscsi task | |
4320 | * | |
4321 | **/ | |
1282ab76 MC |
4322 | static void beiscsi_cleanup_task(struct iscsi_task *task) |
4323 | { | |
4324 | struct beiscsi_io_task *io_task = task->dd_data; | |
4325 | struct iscsi_conn *conn = task->conn; | |
4326 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
4327 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4328 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; | |
4329 | struct hwi_wrb_context *pwrb_context; | |
4330 | struct hwi_controller *phwi_ctrlr; | |
a7909b39 JK |
4331 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
4332 | beiscsi_conn->beiscsi_conn_cid); | |
1282ab76 MC |
4333 | |
4334 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 | 4335 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
1282ab76 MC |
4336 | |
4337 | if (io_task->cmd_bhs) { | |
4338 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, | |
4339 | io_task->bhs_pa.u.a64.address); | |
4340 | io_task->cmd_bhs = NULL; | |
e1f9d31e | 4341 | task->hdr = NULL; |
1282ab76 MC |
4342 | } |
4343 | ||
4344 | if (task->sc) { | |
4345 | if (io_task->pwrb_handle) { | |
4346 | free_wrb_handle(phba, pwrb_context, | |
4347 | io_task->pwrb_handle); | |
4348 | io_task->pwrb_handle = NULL; | |
4349 | } | |
4350 | ||
4351 | if (io_task->psgl_handle) { | |
1282ab76 | 4352 | free_io_sgl_handle(phba, io_task->psgl_handle); |
1282ab76 MC |
4353 | io_task->psgl_handle = NULL; |
4354 | } | |
da334977 JK |
4355 | |
4356 | if (io_task->scsi_cmnd) { | |
9122e991 JB |
4357 | if (io_task->num_sg) |
4358 | scsi_dma_unmap(io_task->scsi_cmnd); | |
da334977 JK |
4359 | io_task->scsi_cmnd = NULL; |
4360 | } | |
1282ab76 | 4361 | } else { |
43f388b0 | 4362 | if (!beiscsi_conn->login_in_progress) |
4a4a11b9 | 4363 | beiscsi_free_mgmt_task_handles(beiscsi_conn, task); |
1282ab76 MC |
4364 | } |
4365 | } | |
4366 | ||
6733b39a JK |
4367 | void |
4368 | beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, | |
4369 | struct beiscsi_offload_params *params) | |
4370 | { | |
4371 | struct wrb_handle *pwrb_handle; | |
340c99e9 | 4372 | struct hwi_wrb_context *pwrb_context = NULL; |
6733b39a | 4373 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1282ab76 MC |
4374 | struct iscsi_task *task = beiscsi_conn->task; |
4375 | struct iscsi_session *session = task->conn->session; | |
6733b39a JK |
4376 | u32 doorbell = 0; |
4377 | ||
4378 | /* | |
4379 | * We can always use 0 here because it is reserved by libiscsi for | |
4380 | * login/startup related tasks. | |
4381 | */ | |
1282ab76 | 4382 | beiscsi_conn->login_in_progress = 0; |
659743b0 | 4383 | spin_lock_bh(&session->back_lock); |
1282ab76 | 4384 | beiscsi_cleanup_task(task); |
659743b0 | 4385 | spin_unlock_bh(&session->back_lock); |
1282ab76 | 4386 | |
340c99e9 JSJ |
4387 | pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, |
4388 | &pwrb_context); | |
6733b39a | 4389 | |
acb9693c | 4390 | /* Check for the adapter family */ |
2c9dfd36 | 4391 | if (is_chip_be2_be3r(phba)) |
acb9693c | 4392 | beiscsi_offload_cxn_v0(params, pwrb_handle, |
340c99e9 JSJ |
4393 | phba->init_mem, |
4394 | pwrb_context); | |
2c9dfd36 | 4395 | else |
340c99e9 JSJ |
4396 | beiscsi_offload_cxn_v2(params, pwrb_handle, |
4397 | pwrb_context); | |
6733b39a | 4398 | |
acb9693c JSJ |
4399 | be_dws_le_to_cpu(pwrb_handle->pwrb, |
4400 | sizeof(struct iscsi_target_context_update_wrb)); | |
6733b39a JK |
4401 | |
4402 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; | |
32951dd8 | 4403 | doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK) |
bfead3b2 | 4404 | << DB_DEF_PDU_WRB_INDEX_SHIFT; |
6733b39a | 4405 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
1e4be6ff JK |
4406 | iowrite32(doorbell, phba->db_va + |
4407 | beiscsi_conn->doorbell_offset); | |
cb564c6b JB |
4408 | |
4409 | /* | |
4410 | * There is no completion for CONTEXT_UPDATE. The completion of next | |
4411 | * WRB posted guarantees FW's processing and DMA'ing of it. | |
4412 | * Use beiscsi_put_wrb_handle to put it back in the pool which makes | |
4413 | * sure zero'ing or reuse of the WRB only after wrbs_per_cxn. | |
4414 | */ | |
4415 | beiscsi_put_wrb_handle(pwrb_context, pwrb_handle, | |
4416 | phba->params.wrbs_per_cxn); | |
4417 | beiscsi_log(phba, KERN_INFO, | |
4418 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
4419 | "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n", | |
4420 | pwrb_handle, pwrb_context->free_index, | |
4421 | pwrb_context->wrb_handles_available); | |
6733b39a JK |
4422 | } |
4423 | ||
4424 | static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt, | |
4425 | int *index, int *age) | |
4426 | { | |
bfead3b2 | 4427 | *index = (int)itt; |
6733b39a JK |
4428 | if (age) |
4429 | *age = conn->session->age; | |
4430 | } | |
4431 | ||
4432 | /** | |
4433 | * beiscsi_alloc_pdu - allocates pdu and related resources | |
4434 | * @task: libiscsi task | |
4435 | * @opcode: opcode of pdu for task | |
4436 | * | |
4437 | * This is called with the session lock held. It will allocate | |
4438 | * the wrb and sgl if needed for the command. And it will prep | |
4439 | * the pdu's itt. beiscsi_parse_pdu will later translate | |
4440 | * the pdu itt to the libiscsi task itt. | |
4441 | */ | |
4442 | static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode) | |
4443 | { | |
4444 | struct beiscsi_io_task *io_task = task->dd_data; | |
4445 | struct iscsi_conn *conn = task->conn; | |
4446 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
4447 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4448 | struct hwi_wrb_context *pwrb_context; | |
4449 | struct hwi_controller *phwi_ctrlr; | |
4450 | itt_t itt; | |
a7909b39 | 4451 | uint16_t cri_index = 0; |
2afc95bf JK |
4452 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
4453 | dma_addr_t paddr; | |
6733b39a | 4454 | |
2afc95bf | 4455 | io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool, |
bc7accec | 4456 | GFP_ATOMIC, &paddr); |
2afc95bf JK |
4457 | if (!io_task->cmd_bhs) |
4458 | return -ENOMEM; | |
2afc95bf | 4459 | io_task->bhs_pa.u.a64.address = paddr; |
bfead3b2 | 4460 | io_task->libiscsi_itt = (itt_t)task->itt; |
6733b39a JK |
4461 | io_task->conn = beiscsi_conn; |
4462 | ||
4463 | task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; | |
4464 | task->hdr_max = sizeof(struct be_cmd_bhs); | |
d2cecf0d | 4465 | io_task->psgl_handle = NULL; |
3ec78271 | 4466 | io_task->pwrb_handle = NULL; |
6733b39a JK |
4467 | |
4468 | if (task->sc) { | |
6733b39a | 4469 | io_task->psgl_handle = alloc_io_sgl_handle(phba); |
8359c79b JSJ |
4470 | if (!io_task->psgl_handle) { |
4471 | beiscsi_log(phba, KERN_ERR, | |
4472 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
4473 | "BM_%d : Alloc of IO_SGL_ICD Failed" | |
4474 | "for the CID : %d\n", | |
4475 | beiscsi_conn->beiscsi_conn_cid); | |
2afc95bf | 4476 | goto free_hndls; |
8359c79b | 4477 | } |
d2cecf0d | 4478 | io_task->pwrb_handle = alloc_wrb_handle(phba, |
340c99e9 JSJ |
4479 | beiscsi_conn->beiscsi_conn_cid, |
4480 | &io_task->pwrb_context); | |
8359c79b JSJ |
4481 | if (!io_task->pwrb_handle) { |
4482 | beiscsi_log(phba, KERN_ERR, | |
4483 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
4484 | "BM_%d : Alloc of WRB_HANDLE Failed" | |
4485 | "for the CID : %d\n", | |
4486 | beiscsi_conn->beiscsi_conn_cid); | |
d2cecf0d | 4487 | goto free_io_hndls; |
8359c79b | 4488 | } |
6733b39a JK |
4489 | } else { |
4490 | io_task->scsi_cmnd = NULL; | |
d7aea67b | 4491 | if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { |
43f388b0 | 4492 | beiscsi_conn->task = task; |
6733b39a | 4493 | if (!beiscsi_conn->login_in_progress) { |
6733b39a JK |
4494 | io_task->psgl_handle = (struct sgl_handle *) |
4495 | alloc_mgmt_sgl_handle(phba); | |
8359c79b JSJ |
4496 | if (!io_task->psgl_handle) { |
4497 | beiscsi_log(phba, KERN_ERR, | |
4498 | BEISCSI_LOG_IO | | |
4499 | BEISCSI_LOG_CONFIG, | |
4500 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" | |
4501 | "for the CID : %d\n", | |
4502 | beiscsi_conn-> | |
4503 | beiscsi_conn_cid); | |
2afc95bf | 4504 | goto free_hndls; |
8359c79b | 4505 | } |
2afc95bf | 4506 | |
6733b39a JK |
4507 | beiscsi_conn->login_in_progress = 1; |
4508 | beiscsi_conn->plogin_sgl_handle = | |
4509 | io_task->psgl_handle; | |
d2cecf0d JK |
4510 | io_task->pwrb_handle = |
4511 | alloc_wrb_handle(phba, | |
340c99e9 JSJ |
4512 | beiscsi_conn->beiscsi_conn_cid, |
4513 | &io_task->pwrb_context); | |
8359c79b JSJ |
4514 | if (!io_task->pwrb_handle) { |
4515 | beiscsi_log(phba, KERN_ERR, | |
4516 | BEISCSI_LOG_IO | | |
4517 | BEISCSI_LOG_CONFIG, | |
4518 | "BM_%d : Alloc of WRB_HANDLE Failed" | |
4519 | "for the CID : %d\n", | |
4520 | beiscsi_conn-> | |
4521 | beiscsi_conn_cid); | |
4522 | goto free_mgmt_hndls; | |
4523 | } | |
d2cecf0d JK |
4524 | beiscsi_conn->plogin_wrb_handle = |
4525 | io_task->pwrb_handle; | |
4526 | ||
6733b39a JK |
4527 | } else { |
4528 | io_task->psgl_handle = | |
4529 | beiscsi_conn->plogin_sgl_handle; | |
d2cecf0d JK |
4530 | io_task->pwrb_handle = |
4531 | beiscsi_conn->plogin_wrb_handle; | |
6733b39a JK |
4532 | } |
4533 | } else { | |
6733b39a | 4534 | io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); |
8359c79b JSJ |
4535 | if (!io_task->psgl_handle) { |
4536 | beiscsi_log(phba, KERN_ERR, | |
4537 | BEISCSI_LOG_IO | | |
4538 | BEISCSI_LOG_CONFIG, | |
4539 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" | |
4540 | "for the CID : %d\n", | |
4541 | beiscsi_conn-> | |
4542 | beiscsi_conn_cid); | |
2afc95bf | 4543 | goto free_hndls; |
8359c79b | 4544 | } |
d2cecf0d JK |
4545 | io_task->pwrb_handle = |
4546 | alloc_wrb_handle(phba, | |
340c99e9 JSJ |
4547 | beiscsi_conn->beiscsi_conn_cid, |
4548 | &io_task->pwrb_context); | |
8359c79b JSJ |
4549 | if (!io_task->pwrb_handle) { |
4550 | beiscsi_log(phba, KERN_ERR, | |
4551 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
4552 | "BM_%d : Alloc of WRB_HANDLE Failed" | |
4553 | "for the CID : %d\n", | |
4554 | beiscsi_conn->beiscsi_conn_cid); | |
d2cecf0d | 4555 | goto free_mgmt_hndls; |
8359c79b | 4556 | } |
d2cecf0d | 4557 | |
6733b39a JK |
4558 | } |
4559 | } | |
bfead3b2 JK |
4560 | itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> |
4561 | wrb_index << 16) | (unsigned int) | |
4562 | (io_task->psgl_handle->sgl_index)); | |
32951dd8 | 4563 | io_task->pwrb_handle->pio_handle = task; |
bfead3b2 | 4564 | |
6733b39a JK |
4565 | io_task->cmd_bhs->iscsi_hdr.itt = itt; |
4566 | return 0; | |
2afc95bf | 4567 | |
d2cecf0d | 4568 | free_io_hndls: |
d2cecf0d | 4569 | free_io_sgl_handle(phba, io_task->psgl_handle); |
d2cecf0d JK |
4570 | goto free_hndls; |
4571 | free_mgmt_hndls: | |
d2cecf0d | 4572 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
a7909b39 | 4573 | io_task->psgl_handle = NULL; |
2afc95bf JK |
4574 | free_hndls: |
4575 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 JK |
4576 | cri_index = BE_GET_CRI_FROM_CID( |
4577 | beiscsi_conn->beiscsi_conn_cid); | |
4578 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; | |
d2cecf0d JK |
4579 | if (io_task->pwrb_handle) |
4580 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); | |
2afc95bf JK |
4581 | io_task->pwrb_handle = NULL; |
4582 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, | |
4583 | io_task->bhs_pa.u.a64.address); | |
1282ab76 | 4584 | io_task->cmd_bhs = NULL; |
2afc95bf | 4585 | return -ENOMEM; |
6733b39a | 4586 | } |
0825b8ee | 4587 | static int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg, |
09a1093a JSJ |
4588 | unsigned int num_sg, unsigned int xferlen, |
4589 | unsigned int writedir) | |
4590 | { | |
4591 | ||
4592 | struct beiscsi_io_task *io_task = task->dd_data; | |
4593 | struct iscsi_conn *conn = task->conn; | |
4594 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
4595 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4596 | struct iscsi_wrb *pwrb = NULL; | |
4597 | unsigned int doorbell = 0; | |
4598 | ||
4599 | pwrb = io_task->pwrb_handle->pwrb; | |
09a1093a | 4600 | |
09a1093a JSJ |
4601 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
4602 | ||
4603 | if (writedir) { | |
4604 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, | |
4605 | INI_WR_CMD); | |
4606 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1); | |
4607 | } else { | |
4608 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, | |
4609 | INI_RD_CMD); | |
4610 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0); | |
4611 | } | |
4612 | ||
4613 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2, | |
4614 | type, pwrb); | |
4615 | ||
4616 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb, | |
4617 | cpu_to_be16(*(unsigned short *) | |
4618 | &io_task->cmd_bhs->iscsi_hdr.lun)); | |
4619 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen); | |
4620 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, | |
4621 | io_task->pwrb_handle->wrb_index); | |
4622 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, | |
4623 | be32_to_cpu(task->cmdsn)); | |
4624 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, | |
4625 | io_task->psgl_handle->sgl_index); | |
4626 | ||
4627 | hwi_write_sgl_v2(pwrb, sg, num_sg, io_task); | |
4628 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, | |
340c99e9 JSJ |
4629 | io_task->pwrb_handle->wrb_index); |
4630 | if (io_task->pwrb_context->plast_wrb) | |
4631 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, | |
4632 | io_task->pwrb_context->plast_wrb, | |
4633 | io_task->pwrb_handle->wrb_index); | |
4634 | io_task->pwrb_context->plast_wrb = pwrb; | |
09a1093a JSJ |
4635 | |
4636 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); | |
4637 | ||
4638 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; | |
4639 | doorbell |= (io_task->pwrb_handle->wrb_index & | |
4640 | DB_DEF_PDU_WRB_INDEX_MASK) << | |
4641 | DB_DEF_PDU_WRB_INDEX_SHIFT; | |
4642 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; | |
1e4be6ff JK |
4643 | iowrite32(doorbell, phba->db_va + |
4644 | beiscsi_conn->doorbell_offset); | |
09a1093a JSJ |
4645 | return 0; |
4646 | } | |
6733b39a | 4647 | |
6733b39a JK |
4648 | static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, |
4649 | unsigned int num_sg, unsigned int xferlen, | |
4650 | unsigned int writedir) | |
4651 | { | |
4652 | ||
4653 | struct beiscsi_io_task *io_task = task->dd_data; | |
4654 | struct iscsi_conn *conn = task->conn; | |
4655 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
4656 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4657 | struct iscsi_wrb *pwrb = NULL; | |
4658 | unsigned int doorbell = 0; | |
4659 | ||
4660 | pwrb = io_task->pwrb_handle->pwrb; | |
6733b39a JK |
4661 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
4662 | ||
4663 | if (writedir) { | |
32951dd8 JK |
4664 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
4665 | INI_WR_CMD); | |
6733b39a | 4666 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); |
6733b39a | 4667 | } else { |
32951dd8 JK |
4668 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
4669 | INI_RD_CMD); | |
6733b39a JK |
4670 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
4671 | } | |
6733b39a | 4672 | |
09a1093a JSJ |
4673 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb, |
4674 | type, pwrb); | |
4675 | ||
6733b39a | 4676 | AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, |
dc63aac6 JK |
4677 | cpu_to_be16(*(unsigned short *) |
4678 | &io_task->cmd_bhs->iscsi_hdr.lun)); | |
6733b39a JK |
4679 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); |
4680 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, | |
4681 | io_task->pwrb_handle->wrb_index); | |
4682 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, | |
4683 | be32_to_cpu(task->cmdsn)); | |
4684 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, | |
4685 | io_task->psgl_handle->sgl_index); | |
4686 | ||
4687 | hwi_write_sgl(pwrb, sg, num_sg, io_task); | |
4688 | ||
4689 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, | |
340c99e9 JSJ |
4690 | io_task->pwrb_handle->wrb_index); |
4691 | if (io_task->pwrb_context->plast_wrb) | |
4692 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, | |
4693 | io_task->pwrb_context->plast_wrb, | |
4694 | io_task->pwrb_handle->wrb_index); | |
4695 | io_task->pwrb_context->plast_wrb = pwrb; | |
4696 | ||
6733b39a JK |
4697 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
4698 | ||
4699 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; | |
32951dd8 | 4700 | doorbell |= (io_task->pwrb_handle->wrb_index & |
6733b39a JK |
4701 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
4702 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; | |
4703 | ||
1e4be6ff JK |
4704 | iowrite32(doorbell, phba->db_va + |
4705 | beiscsi_conn->doorbell_offset); | |
6733b39a JK |
4706 | return 0; |
4707 | } | |
4708 | ||
4709 | static int beiscsi_mtask(struct iscsi_task *task) | |
4710 | { | |
dafab8e0 | 4711 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
4712 | struct iscsi_conn *conn = task->conn; |
4713 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
4714 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
4715 | struct iscsi_wrb *pwrb = NULL; | |
4716 | unsigned int doorbell = 0; | |
dafab8e0 | 4717 | unsigned int cid; |
09a1093a | 4718 | unsigned int pwrb_typeoffset = 0; |
e0493627 | 4719 | int ret = 0; |
6733b39a | 4720 | |
bfead3b2 | 4721 | cid = beiscsi_conn->beiscsi_conn_cid; |
6733b39a | 4722 | pwrb = io_task->pwrb_handle->pwrb; |
09a1093a | 4723 | |
2c9dfd36 | 4724 | if (is_chip_be2_be3r(phba)) { |
09a1093a JSJ |
4725 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
4726 | be32_to_cpu(task->cmdsn)); | |
4727 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, | |
4728 | io_task->pwrb_handle->wrb_index); | |
4729 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, | |
4730 | io_task->psgl_handle->sgl_index); | |
4731 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, | |
4732 | task->data_count); | |
4733 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, | |
340c99e9 JSJ |
4734 | io_task->pwrb_handle->wrb_index); |
4735 | if (io_task->pwrb_context->plast_wrb) | |
4736 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, | |
4737 | io_task->pwrb_context->plast_wrb, | |
4738 | io_task->pwrb_handle->wrb_index); | |
4739 | io_task->pwrb_context->plast_wrb = pwrb; | |
4740 | ||
09a1093a | 4741 | pwrb_typeoffset = BE_WRB_TYPE_OFFSET; |
2c9dfd36 JK |
4742 | } else { |
4743 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, | |
4744 | be32_to_cpu(task->cmdsn)); | |
4745 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, | |
4746 | io_task->pwrb_handle->wrb_index); | |
4747 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, | |
4748 | io_task->psgl_handle->sgl_index); | |
4749 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, | |
4750 | task->data_count); | |
4751 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, | |
340c99e9 JSJ |
4752 | io_task->pwrb_handle->wrb_index); |
4753 | if (io_task->pwrb_context->plast_wrb) | |
4754 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, | |
4755 | io_task->pwrb_context->plast_wrb, | |
4756 | io_task->pwrb_handle->wrb_index); | |
4757 | io_task->pwrb_context->plast_wrb = pwrb; | |
4758 | ||
2c9dfd36 | 4759 | pwrb_typeoffset = SKH_WRB_TYPE_OFFSET; |
09a1093a JSJ |
4760 | } |
4761 | ||
dafab8e0 | 4762 | |
6733b39a JK |
4763 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { |
4764 | case ISCSI_OP_LOGIN: | |
6733b39a | 4765 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); |
09a1093a | 4766 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
e0493627 | 4767 | ret = hwi_write_buffer(pwrb, task); |
6733b39a JK |
4768 | break; |
4769 | case ISCSI_OP_NOOP_OUT: | |
1390b01b | 4770 | if (task->hdr->ttt != ISCSI_RESERVED_TAG) { |
09a1093a | 4771 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
2c9dfd36 JK |
4772 | if (is_chip_be2_be3r(phba)) |
4773 | AMAP_SET_BITS(struct amap_iscsi_wrb, | |
09a1093a JSJ |
4774 | dmsg, pwrb, 1); |
4775 | else | |
2c9dfd36 | 4776 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
09a1093a | 4777 | dmsg, pwrb, 1); |
1390b01b | 4778 | } else { |
09a1093a | 4779 | ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset); |
2c9dfd36 JK |
4780 | if (is_chip_be2_be3r(phba)) |
4781 | AMAP_SET_BITS(struct amap_iscsi_wrb, | |
09a1093a JSJ |
4782 | dmsg, pwrb, 0); |
4783 | else | |
2c9dfd36 | 4784 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
09a1093a | 4785 | dmsg, pwrb, 0); |
1390b01b | 4786 | } |
e0493627 | 4787 | ret = hwi_write_buffer(pwrb, task); |
6733b39a JK |
4788 | break; |
4789 | case ISCSI_OP_TEXT: | |
09a1093a | 4790 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
e0493627 | 4791 | ret = hwi_write_buffer(pwrb, task); |
6733b39a JK |
4792 | break; |
4793 | case ISCSI_OP_SCSI_TMFUNC: | |
09a1093a | 4794 | ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset); |
e0493627 | 4795 | ret = hwi_write_buffer(pwrb, task); |
6733b39a JK |
4796 | break; |
4797 | case ISCSI_OP_LOGOUT: | |
09a1093a | 4798 | ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset); |
e0493627 | 4799 | ret = hwi_write_buffer(pwrb, task); |
6733b39a JK |
4800 | break; |
4801 | ||
4802 | default: | |
99bc5d55 JSJ |
4803 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
4804 | "BM_%d : opcode =%d Not supported\n", | |
4805 | task->hdr->opcode & ISCSI_OPCODE_MASK); | |
4806 | ||
6733b39a JK |
4807 | return -EINVAL; |
4808 | } | |
4809 | ||
e0493627 AK |
4810 | if (ret) |
4811 | return ret; | |
4812 | ||
09a1093a | 4813 | /* Set the task type */ |
2c9dfd36 JK |
4814 | io_task->wrb_type = (is_chip_be2_be3r(phba)) ? |
4815 | AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) : | |
4816 | AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb); | |
6733b39a | 4817 | |
bfead3b2 | 4818 | doorbell |= cid & DB_WRB_POST_CID_MASK; |
32951dd8 | 4819 | doorbell |= (io_task->pwrb_handle->wrb_index & |
6733b39a JK |
4820 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
4821 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; | |
1e4be6ff JK |
4822 | iowrite32(doorbell, phba->db_va + |
4823 | beiscsi_conn->doorbell_offset); | |
6733b39a JK |
4824 | return 0; |
4825 | } | |
4826 | ||
4827 | static int beiscsi_task_xmit(struct iscsi_task *task) | |
4828 | { | |
6733b39a JK |
4829 | struct beiscsi_io_task *io_task = task->dd_data; |
4830 | struct scsi_cmnd *sc = task->sc; | |
1868379b | 4831 | struct beiscsi_hba *phba; |
6733b39a JK |
4832 | struct scatterlist *sg; |
4833 | int num_sg; | |
4834 | unsigned int writedir = 0, xferlen = 0; | |
4835 | ||
9122e991 JB |
4836 | phba = io_task->conn->phba; |
4837 | /** | |
4838 | * HBA in error includes BEISCSI_HBA_FW_TIMEOUT. IO path might be | |
4839 | * operational if FW still gets heartbeat from EP FW. Is management | |
4840 | * path really needed to continue further? | |
4841 | */ | |
d1d5ca88 | 4842 | if (!beiscsi_hba_is_online(phba)) |
9122e991 JB |
4843 | return -EIO; |
4844 | ||
1868379b JB |
4845 | if (!io_task->conn->login_in_progress) |
4846 | task->hdr->exp_statsn = 0; | |
09a1093a | 4847 | |
6733b39a JK |
4848 | if (!sc) |
4849 | return beiscsi_mtask(task); | |
4850 | ||
4851 | io_task->scsi_cmnd = sc; | |
9122e991 | 4852 | io_task->num_sg = 0; |
6733b39a JK |
4853 | num_sg = scsi_dma_map(sc); |
4854 | if (num_sg < 0) { | |
afb96058 JK |
4855 | beiscsi_log(phba, KERN_ERR, |
4856 | BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI, | |
4857 | "BM_%d : scsi_dma_map Failed " | |
4858 | "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n", | |
4859 | be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt), | |
4860 | io_task->libiscsi_itt, scsi_bufflen(sc)); | |
99bc5d55 | 4861 | |
6733b39a JK |
4862 | return num_sg; |
4863 | } | |
9122e991 JB |
4864 | /** |
4865 | * For scsi cmd task, check num_sg before unmapping in cleanup_task. | |
4866 | * For management task, cleanup_task checks mtask_addr before unmapping. | |
4867 | */ | |
4868 | io_task->num_sg = num_sg; | |
6733b39a JK |
4869 | xferlen = scsi_bufflen(sc); |
4870 | sg = scsi_sglist(sc); | |
99bc5d55 | 4871 | if (sc->sc_data_direction == DMA_TO_DEVICE) |
6733b39a | 4872 | writedir = 1; |
99bc5d55 | 4873 | else |
6733b39a | 4874 | writedir = 0; |
99bc5d55 | 4875 | |
09a1093a | 4876 | return phba->iotask_fn(task, sg, num_sg, xferlen, writedir); |
6733b39a JK |
4877 | } |
4878 | ||
ffce3e2e JK |
4879 | /** |
4880 | * beiscsi_bsg_request - handle bsg request from ISCSI transport | |
4881 | * @job: job to handle | |
4882 | */ | |
4883 | static int beiscsi_bsg_request(struct bsg_job *job) | |
4884 | { | |
4885 | struct Scsi_Host *shost; | |
4886 | struct beiscsi_hba *phba; | |
4887 | struct iscsi_bsg_request *bsg_req = job->request; | |
4888 | int rc = -EINVAL; | |
4889 | unsigned int tag; | |
4890 | struct be_dma_mem nonemb_cmd; | |
4891 | struct be_cmd_resp_hdr *resp; | |
4892 | struct iscsi_bsg_reply *bsg_reply = job->reply; | |
4893 | unsigned short status, extd_status; | |
4894 | ||
4895 | shost = iscsi_job_to_shost(job); | |
4896 | phba = iscsi_host_priv(shost); | |
4897 | ||
d1d5ca88 | 4898 | if (!beiscsi_hba_is_online(phba)) { |
9122e991 JB |
4899 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
4900 | "BM_%d : HBA in error 0x%lx\n", phba->state); | |
4901 | return -ENXIO; | |
4902 | } | |
4903 | ||
ffce3e2e JK |
4904 | switch (bsg_req->msgcode) { |
4905 | case ISCSI_BSG_HST_VENDOR: | |
4906 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, | |
4907 | job->request_payload.payload_len, | |
4908 | &nonemb_cmd.dma); | |
4909 | if (nonemb_cmd.va == NULL) { | |
99bc5d55 JSJ |
4910 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
4911 | "BM_%d : Failed to allocate memory for " | |
4912 | "beiscsi_bsg_request\n"); | |
8359c79b | 4913 | return -ENOMEM; |
ffce3e2e JK |
4914 | } |
4915 | tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, | |
4916 | &nonemb_cmd); | |
4917 | if (!tag) { | |
99bc5d55 | 4918 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
8359c79b | 4919 | "BM_%d : MBX Tag Allocation Failed\n"); |
99bc5d55 | 4920 | |
ffce3e2e JK |
4921 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
4922 | nonemb_cmd.va, nonemb_cmd.dma); | |
4923 | return -EAGAIN; | |
e175defe JSJ |
4924 | } |
4925 | ||
4926 | rc = wait_event_interruptible_timeout( | |
4927 | phba->ctrl.mcc_wait[tag], | |
67296ad9 | 4928 | phba->ctrl.mcc_tag_status[tag], |
e175defe JSJ |
4929 | msecs_to_jiffies( |
4930 | BEISCSI_HOST_MBX_TIMEOUT)); | |
d1d5ca88 JB |
4931 | |
4932 | if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { | |
4933 | clear_bit(MCC_TAG_STATE_RUNNING, | |
4934 | &phba->ctrl.ptag_state[tag].tag_state); | |
4935 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, | |
4936 | nonemb_cmd.va, nonemb_cmd.dma); | |
4937 | return -EIO; | |
4938 | } | |
67296ad9 JB |
4939 | extd_status = (phba->ctrl.mcc_tag_status[tag] & |
4940 | CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT; | |
4941 | status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK; | |
090e2184 | 4942 | free_mcc_wrb(&phba->ctrl, tag); |
ffce3e2e JK |
4943 | resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; |
4944 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
4945 | job->reply_payload.sg_cnt, | |
4946 | nonemb_cmd.va, (resp->response_length | |
4947 | + sizeof(*resp))); | |
4948 | bsg_reply->reply_payload_rcv_len = resp->response_length; | |
4949 | bsg_reply->result = status; | |
4950 | bsg_job_done(job, bsg_reply->result, | |
4951 | bsg_reply->reply_payload_rcv_len); | |
4952 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, | |
4953 | nonemb_cmd.va, nonemb_cmd.dma); | |
4954 | if (status || extd_status) { | |
99bc5d55 | 4955 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
8359c79b | 4956 | "BM_%d : MBX Cmd Failed" |
99bc5d55 JSJ |
4957 | " status = %d extd_status = %d\n", |
4958 | status, extd_status); | |
4959 | ||
ffce3e2e | 4960 | return -EIO; |
8359c79b JSJ |
4961 | } else { |
4962 | rc = 0; | |
ffce3e2e JK |
4963 | } |
4964 | break; | |
4965 | ||
4966 | default: | |
99bc5d55 JSJ |
4967 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
4968 | "BM_%d : Unsupported bsg command: 0x%x\n", | |
4969 | bsg_req->msgcode); | |
ffce3e2e JK |
4970 | break; |
4971 | } | |
4972 | ||
4973 | return rc; | |
4974 | } | |
4975 | ||
0825b8ee | 4976 | static void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
99bc5d55 JSJ |
4977 | { |
4978 | /* Set the logging parameter */ | |
4979 | beiscsi_log_enable_init(phba, beiscsi_log_enable); | |
4980 | } | |
4981 | ||
d1d5ca88 | 4982 | void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle) |
6733b39a | 4983 | { |
d1d5ca88 JB |
4984 | if (phba->boot_struct.boot_kset) |
4985 | return; | |
50a4b824 JB |
4986 | |
4987 | /* skip if boot work is already in progress */ | |
4988 | if (test_and_set_bit(BEISCSI_HBA_BOOT_WORK, &phba->state)) | |
4989 | return; | |
4990 | ||
4991 | phba->boot_struct.retry = 3; | |
4992 | phba->boot_struct.tag = 0; | |
4993 | phba->boot_struct.s_handle = s_handle; | |
4994 | phba->boot_struct.action = BEISCSI_BOOT_GET_SHANDLE; | |
4995 | schedule_work(&phba->boot_work); | |
4996 | } | |
4997 | ||
4998 | static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf) | |
4999 | { | |
5000 | struct beiscsi_hba *phba = data; | |
5001 | struct mgmt_session_info *boot_sess = &phba->boot_struct.boot_sess; | |
5002 | struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0]; | |
5003 | char *str = buf; | |
5004 | int rc = -EPERM; | |
5005 | ||
5006 | switch (type) { | |
5007 | case ISCSI_BOOT_TGT_NAME: | |
5008 | rc = sprintf(buf, "%.*s\n", | |
5009 | (int)strlen(boot_sess->target_name), | |
5010 | (char *)&boot_sess->target_name); | |
5011 | break; | |
5012 | case ISCSI_BOOT_TGT_IP_ADDR: | |
5013 | if (boot_conn->dest_ipaddr.ip_type == BEISCSI_IP_TYPE_V4) | |
5014 | rc = sprintf(buf, "%pI4\n", | |
5015 | (char *)&boot_conn->dest_ipaddr.addr); | |
5016 | else | |
5017 | rc = sprintf(str, "%pI6\n", | |
5018 | (char *)&boot_conn->dest_ipaddr.addr); | |
5019 | break; | |
5020 | case ISCSI_BOOT_TGT_PORT: | |
5021 | rc = sprintf(str, "%d\n", boot_conn->dest_port); | |
5022 | break; | |
5023 | ||
5024 | case ISCSI_BOOT_TGT_CHAP_NAME: | |
5025 | rc = sprintf(str, "%.*s\n", | |
5026 | boot_conn->negotiated_login_options.auth_data.chap. | |
5027 | target_chap_name_length, | |
5028 | (char *)&boot_conn->negotiated_login_options. | |
5029 | auth_data.chap.target_chap_name); | |
5030 | break; | |
5031 | case ISCSI_BOOT_TGT_CHAP_SECRET: | |
5032 | rc = sprintf(str, "%.*s\n", | |
5033 | boot_conn->negotiated_login_options.auth_data.chap. | |
5034 | target_secret_length, | |
5035 | (char *)&boot_conn->negotiated_login_options. | |
5036 | auth_data.chap.target_secret); | |
5037 | break; | |
5038 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: | |
5039 | rc = sprintf(str, "%.*s\n", | |
5040 | boot_conn->negotiated_login_options.auth_data.chap. | |
5041 | intr_chap_name_length, | |
5042 | (char *)&boot_conn->negotiated_login_options. | |
5043 | auth_data.chap.intr_chap_name); | |
5044 | break; | |
5045 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: | |
5046 | rc = sprintf(str, "%.*s\n", | |
5047 | boot_conn->negotiated_login_options.auth_data.chap. | |
5048 | intr_secret_length, | |
5049 | (char *)&boot_conn->negotiated_login_options. | |
5050 | auth_data.chap.intr_secret); | |
5051 | break; | |
5052 | case ISCSI_BOOT_TGT_FLAGS: | |
5053 | rc = sprintf(str, "2\n"); | |
5054 | break; | |
5055 | case ISCSI_BOOT_TGT_NIC_ASSOC: | |
5056 | rc = sprintf(str, "0\n"); | |
5057 | break; | |
5058 | } | |
5059 | return rc; | |
5060 | } | |
5061 | ||
5062 | static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf) | |
5063 | { | |
5064 | struct beiscsi_hba *phba = data; | |
5065 | char *str = buf; | |
5066 | int rc = -EPERM; | |
5067 | ||
5068 | switch (type) { | |
5069 | case ISCSI_BOOT_INI_INITIATOR_NAME: | |
5070 | rc = sprintf(str, "%s\n", | |
5071 | phba->boot_struct.boot_sess.initiator_iscsiname); | |
5072 | break; | |
5073 | } | |
5074 | return rc; | |
5075 | } | |
5076 | ||
5077 | static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf) | |
5078 | { | |
5079 | struct beiscsi_hba *phba = data; | |
5080 | char *str = buf; | |
5081 | int rc = -EPERM; | |
5082 | ||
5083 | switch (type) { | |
5084 | case ISCSI_BOOT_ETH_FLAGS: | |
5085 | rc = sprintf(str, "2\n"); | |
5086 | break; | |
5087 | case ISCSI_BOOT_ETH_INDEX: | |
5088 | rc = sprintf(str, "0\n"); | |
5089 | break; | |
5090 | case ISCSI_BOOT_ETH_MAC: | |
5091 | rc = beiscsi_get_macaddr(str, phba); | |
5092 | break; | |
5093 | } | |
5094 | return rc; | |
5095 | } | |
5096 | ||
50a4b824 JB |
5097 | static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type) |
5098 | { | |
5099 | umode_t rc = 0; | |
5100 | ||
5101 | switch (type) { | |
5102 | case ISCSI_BOOT_TGT_NAME: | |
5103 | case ISCSI_BOOT_TGT_IP_ADDR: | |
5104 | case ISCSI_BOOT_TGT_PORT: | |
5105 | case ISCSI_BOOT_TGT_CHAP_NAME: | |
5106 | case ISCSI_BOOT_TGT_CHAP_SECRET: | |
5107 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: | |
5108 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: | |
5109 | case ISCSI_BOOT_TGT_NIC_ASSOC: | |
5110 | case ISCSI_BOOT_TGT_FLAGS: | |
5111 | rc = S_IRUGO; | |
5112 | break; | |
5113 | } | |
5114 | return rc; | |
5115 | } | |
5116 | ||
5117 | static umode_t beiscsi_ini_get_attr_visibility(void *data, int type) | |
5118 | { | |
5119 | umode_t rc = 0; | |
5120 | ||
5121 | switch (type) { | |
5122 | case ISCSI_BOOT_INI_INITIATOR_NAME: | |
5123 | rc = S_IRUGO; | |
5124 | break; | |
5125 | } | |
5126 | return rc; | |
5127 | } | |
5128 | ||
50a4b824 JB |
5129 | static umode_t beiscsi_eth_get_attr_visibility(void *data, int type) |
5130 | { | |
5131 | umode_t rc = 0; | |
5132 | ||
5133 | switch (type) { | |
5134 | case ISCSI_BOOT_ETH_FLAGS: | |
5135 | case ISCSI_BOOT_ETH_MAC: | |
5136 | case ISCSI_BOOT_ETH_INDEX: | |
5137 | rc = S_IRUGO; | |
5138 | break; | |
5139 | } | |
5140 | return rc; | |
5141 | } | |
5142 | ||
5143 | static void beiscsi_boot_kobj_release(void *data) | |
5144 | { | |
5145 | struct beiscsi_hba *phba = data; | |
5146 | ||
5147 | scsi_host_put(phba->shost); | |
5148 | } | |
5149 | ||
5150 | static int beiscsi_boot_create_kset(struct beiscsi_hba *phba) | |
5151 | { | |
5152 | struct boot_struct *bs = &phba->boot_struct; | |
5153 | struct iscsi_boot_kobj *boot_kobj; | |
5154 | ||
5155 | if (bs->boot_kset) { | |
5156 | __beiscsi_log(phba, KERN_ERR, | |
5157 | "BM_%d: boot_kset already created\n"); | |
5158 | return 0; | |
5159 | } | |
5160 | ||
5161 | bs->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no); | |
5162 | if (!bs->boot_kset) { | |
5163 | __beiscsi_log(phba, KERN_ERR, | |
5164 | "BM_%d: boot_kset alloc failed\n"); | |
5165 | return -ENOMEM; | |
5166 | } | |
5167 | ||
5168 | /* get shost ref because the show function will refer phba */ | |
5169 | if (!scsi_host_get(phba->shost)) | |
5170 | goto free_kset; | |
5171 | ||
5172 | boot_kobj = iscsi_boot_create_target(bs->boot_kset, 0, phba, | |
5173 | beiscsi_show_boot_tgt_info, | |
5174 | beiscsi_tgt_get_attr_visibility, | |
5175 | beiscsi_boot_kobj_release); | |
5176 | if (!boot_kobj) | |
5177 | goto put_shost; | |
5178 | ||
5179 | if (!scsi_host_get(phba->shost)) | |
5180 | goto free_kset; | |
5181 | ||
5182 | boot_kobj = iscsi_boot_create_initiator(bs->boot_kset, 0, phba, | |
5183 | beiscsi_show_boot_ini_info, | |
5184 | beiscsi_ini_get_attr_visibility, | |
5185 | beiscsi_boot_kobj_release); | |
5186 | if (!boot_kobj) | |
5187 | goto put_shost; | |
5188 | ||
5189 | if (!scsi_host_get(phba->shost)) | |
5190 | goto free_kset; | |
5191 | ||
5192 | boot_kobj = iscsi_boot_create_ethernet(bs->boot_kset, 0, phba, | |
5193 | beiscsi_show_boot_eth_info, | |
5194 | beiscsi_eth_get_attr_visibility, | |
5195 | beiscsi_boot_kobj_release); | |
5196 | if (!boot_kobj) | |
5197 | goto put_shost; | |
5198 | ||
5199 | return 0; | |
5200 | ||
5201 | put_shost: | |
5202 | scsi_host_put(phba->shost); | |
5203 | free_kset: | |
5204 | iscsi_boot_destroy_kset(bs->boot_kset); | |
5205 | bs->boot_kset = NULL; | |
5206 | return -ENOMEM; | |
5207 | } | |
5208 | ||
5209 | static void beiscsi_boot_work(struct work_struct *work) | |
5210 | { | |
5211 | struct beiscsi_hba *phba = | |
5212 | container_of(work, struct beiscsi_hba, boot_work); | |
5213 | struct boot_struct *bs = &phba->boot_struct; | |
5214 | unsigned int tag = 0; | |
5215 | ||
d1d5ca88 | 5216 | if (!beiscsi_hba_is_online(phba)) |
50a4b824 JB |
5217 | return; |
5218 | ||
5219 | beiscsi_log(phba, KERN_INFO, | |
5220 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, | |
5221 | "BM_%d : %s action %d\n", | |
5222 | __func__, phba->boot_struct.action); | |
5223 | ||
5224 | switch (phba->boot_struct.action) { | |
5225 | case BEISCSI_BOOT_REOPEN_SESS: | |
5226 | tag = beiscsi_boot_reopen_sess(phba); | |
5227 | break; | |
5228 | case BEISCSI_BOOT_GET_SHANDLE: | |
5229 | tag = __beiscsi_boot_get_shandle(phba, 1); | |
5230 | break; | |
5231 | case BEISCSI_BOOT_GET_SINFO: | |
5232 | tag = beiscsi_boot_get_sinfo(phba); | |
5233 | break; | |
5234 | case BEISCSI_BOOT_LOGOUT_SESS: | |
5235 | tag = beiscsi_boot_logout_sess(phba); | |
5236 | break; | |
5237 | case BEISCSI_BOOT_CREATE_KSET: | |
5238 | beiscsi_boot_create_kset(phba); | |
5239 | /** | |
5240 | * updated boot_kset is made visible to all before | |
5241 | * ending the boot work. | |
5242 | */ | |
5243 | mb(); | |
5244 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); | |
5245 | return; | |
5246 | } | |
5247 | if (!tag) { | |
5248 | if (bs->retry--) | |
5249 | schedule_work(&phba->boot_work); | |
5250 | else | |
5251 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); | |
5252 | } | |
5253 | } | |
5254 | ||
10bcd47d JB |
5255 | static void beiscsi_eqd_update_work(struct work_struct *work) |
5256 | { | |
5257 | struct hwi_context_memory *phwi_context; | |
73af08e1 | 5258 | struct be_set_eqd set_eqd[MAX_CPUS]; |
73af08e1 | 5259 | struct hwi_controller *phwi_ctrlr; |
10bcd47d JB |
5260 | struct be_eq_obj *pbe_eq; |
5261 | struct beiscsi_hba *phba; | |
5262 | unsigned int pps, delta; | |
5263 | struct be_aic_obj *aic; | |
73af08e1 | 5264 | int eqd, i, num = 0; |
10bcd47d | 5265 | unsigned long now; |
73af08e1 | 5266 | |
10bcd47d | 5267 | phba = container_of(work, struct beiscsi_hba, eqd_update.work); |
d1d5ca88 | 5268 | if (!beiscsi_hba_is_online(phba)) |
9122e991 JB |
5269 | return; |
5270 | ||
73af08e1 JK |
5271 | phwi_ctrlr = phba->phwi_ctrlr; |
5272 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
5273 | ||
5274 | for (i = 0; i <= phba->num_cpus; i++) { | |
5275 | aic = &phba->aic_obj[i]; | |
5276 | pbe_eq = &phwi_context->be_eq[i]; | |
5277 | now = jiffies; | |
10bcd47d | 5278 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
73af08e1 | 5279 | pbe_eq->cq_count < aic->eq_prev) { |
10bcd47d | 5280 | aic->jiffies = now; |
73af08e1 JK |
5281 | aic->eq_prev = pbe_eq->cq_count; |
5282 | continue; | |
5283 | } | |
10bcd47d | 5284 | delta = jiffies_to_msecs(now - aic->jiffies); |
73af08e1 JK |
5285 | pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta); |
5286 | eqd = (pps / 1500) << 2; | |
5287 | ||
5288 | if (eqd < 8) | |
5289 | eqd = 0; | |
5290 | eqd = min_t(u32, eqd, phwi_context->max_eqd); | |
5291 | eqd = max_t(u32, eqd, phwi_context->min_eqd); | |
5292 | ||
10bcd47d | 5293 | aic->jiffies = now; |
73af08e1 JK |
5294 | aic->eq_prev = pbe_eq->cq_count; |
5295 | ||
5296 | if (eqd != aic->prev_eqd) { | |
5297 | set_eqd[num].delay_multiplier = (eqd * 65)/100; | |
5298 | set_eqd[num].eq_id = pbe_eq->q.id; | |
5299 | aic->prev_eqd = eqd; | |
5300 | num++; | |
5301 | } | |
5302 | } | |
10bcd47d JB |
5303 | if (num) |
5304 | /* completion of this is ignored */ | |
5305 | beiscsi_modify_eq_delay(phba, set_eqd, num); | |
73af08e1 | 5306 | |
10bcd47d JB |
5307 | schedule_delayed_work(&phba->eqd_update, |
5308 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); | |
7a158003 JSJ |
5309 | } |
5310 | ||
d1d5ca88 JB |
5311 | static void beiscsi_msix_enable(struct beiscsi_hba *phba) |
5312 | { | |
5313 | int i, status; | |
5314 | ||
5315 | for (i = 0; i <= phba->num_cpus; i++) | |
5316 | phba->msix_entries[i].entry = i; | |
5317 | ||
5318 | status = pci_enable_msix_range(phba->pcidev, phba->msix_entries, | |
5319 | phba->num_cpus + 1, phba->num_cpus + 1); | |
5320 | if (status > 0) | |
5321 | phba->msix_enabled = true; | |
5322 | } | |
5323 | ||
5324 | static void beiscsi_hw_tpe_check(unsigned long ptr) | |
5325 | { | |
5326 | struct beiscsi_hba *phba; | |
5327 | u32 wait; | |
5328 | ||
5329 | phba = (struct beiscsi_hba *)ptr; | |
5330 | /* if not TPE, do nothing */ | |
5331 | if (!beiscsi_detect_tpe(phba)) | |
5332 | return; | |
5333 | ||
5334 | /* wait default 4000ms before recovering */ | |
5335 | wait = 4000; | |
5336 | if (phba->ue2rp > BEISCSI_UE_DETECT_INTERVAL) | |
5337 | wait = phba->ue2rp - BEISCSI_UE_DETECT_INTERVAL; | |
5338 | queue_delayed_work(phba->wq, &phba->recover_port, | |
5339 | msecs_to_jiffies(wait)); | |
5340 | } | |
5341 | ||
5342 | static void beiscsi_hw_health_check(unsigned long ptr) | |
5343 | { | |
5344 | struct beiscsi_hba *phba; | |
5345 | ||
5346 | phba = (struct beiscsi_hba *)ptr; | |
5347 | beiscsi_detect_ue(phba); | |
5348 | if (beiscsi_detect_ue(phba)) { | |
5349 | __beiscsi_log(phba, KERN_ERR, | |
5350 | "BM_%d : port in error: %lx\n", phba->state); | |
10e1a44a JB |
5351 | /* sessions are no longer valid, so first fail the sessions */ |
5352 | queue_work(phba->wq, &phba->sess_work); | |
5353 | ||
5354 | /* detect UER supported */ | |
d1d5ca88 JB |
5355 | if (!test_bit(BEISCSI_HBA_UER_SUPP, &phba->state)) |
5356 | return; | |
5357 | /* modify this timer to check TPE */ | |
5358 | phba->hw_check.function = beiscsi_hw_tpe_check; | |
5359 | } | |
5360 | ||
5361 | mod_timer(&phba->hw_check, | |
5362 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); | |
5363 | } | |
5364 | ||
5365 | /* | |
5366 | * beiscsi_enable_port()- Enables the disabled port. | |
5367 | * Only port resources freed in disable function are reallocated. | |
5368 | * This is called in HBA error handling path. | |
5369 | * | |
5370 | * @phba: Instance of driver private structure | |
5371 | * | |
5372 | **/ | |
5373 | static int beiscsi_enable_port(struct beiscsi_hba *phba) | |
5374 | { | |
5375 | struct hwi_context_memory *phwi_context; | |
5376 | struct hwi_controller *phwi_ctrlr; | |
5377 | struct be_eq_obj *pbe_eq; | |
5378 | int ret, i; | |
5379 | ||
5380 | if (test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { | |
5381 | __beiscsi_log(phba, KERN_ERR, | |
5382 | "BM_%d : %s : port is online %lx\n", | |
5383 | __func__, phba->state); | |
5384 | return 0; | |
5385 | } | |
5386 | ||
5387 | ret = beiscsi_init_sliport(phba); | |
5388 | if (ret) | |
5389 | return ret; | |
5390 | ||
5391 | if (enable_msix) | |
5392 | find_num_cpus(phba); | |
5393 | else | |
5394 | phba->num_cpus = 1; | |
5395 | if (enable_msix) { | |
5396 | beiscsi_msix_enable(phba); | |
5397 | if (!phba->msix_enabled) | |
5398 | phba->num_cpus = 1; | |
5399 | } | |
5400 | ||
5401 | beiscsi_get_params(phba); | |
5402 | /* Re-enable UER. If different TPE occurs then it is recoverable. */ | |
5403 | beiscsi_set_uer_feature(phba); | |
5404 | ||
5405 | phba->shost->max_id = phba->params.cxns_per_ctrl; | |
5406 | phba->shost->can_queue = phba->params.ios_per_ctrl; | |
5407 | ret = hwi_init_controller(phba); | |
5408 | if (ret) { | |
5409 | __beiscsi_log(phba, KERN_ERR, | |
5410 | "BM_%d : init controller failed %d\n", ret); | |
5411 | goto disable_msix; | |
5412 | } | |
5413 | ||
5414 | for (i = 0; i < MAX_MCC_CMD; i++) { | |
5415 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); | |
5416 | phba->ctrl.mcc_tag[i] = i + 1; | |
5417 | phba->ctrl.mcc_tag_status[i + 1] = 0; | |
5418 | phba->ctrl.mcc_tag_available++; | |
5419 | } | |
5420 | ||
5421 | phwi_ctrlr = phba->phwi_ctrlr; | |
5422 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
5423 | for (i = 0; i < phba->num_cpus; i++) { | |
5424 | pbe_eq = &phwi_context->be_eq[i]; | |
5425 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); | |
5426 | } | |
5427 | ||
5428 | i = (phba->msix_enabled) ? i : 0; | |
5429 | /* Work item for MCC handling */ | |
5430 | pbe_eq = &phwi_context->be_eq[i]; | |
5431 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); | |
5432 | ||
5433 | ret = beiscsi_init_irqs(phba); | |
5434 | if (ret < 0) { | |
5435 | __beiscsi_log(phba, KERN_ERR, | |
5436 | "BM_%d : setup IRQs failed %d\n", ret); | |
5437 | goto cleanup_port; | |
5438 | } | |
5439 | hwi_enable_intr(phba); | |
5440 | /* port operational: clear all error bits */ | |
5441 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); | |
5442 | __beiscsi_log(phba, KERN_INFO, | |
5443 | "BM_%d : port online: 0x%lx\n", phba->state); | |
5444 | ||
5445 | /* start hw_check timer and eqd_update work */ | |
5446 | schedule_delayed_work(&phba->eqd_update, | |
5447 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); | |
5448 | ||
5449 | /** | |
5450 | * Timer function gets modified for TPE detection. | |
5451 | * Always reinit to do health check first. | |
5452 | */ | |
5453 | phba->hw_check.function = beiscsi_hw_health_check; | |
5454 | mod_timer(&phba->hw_check, | |
5455 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); | |
5456 | return 0; | |
5457 | ||
5458 | cleanup_port: | |
5459 | for (i = 0; i < phba->num_cpus; i++) { | |
5460 | pbe_eq = &phwi_context->be_eq[i]; | |
5461 | irq_poll_disable(&pbe_eq->iopoll); | |
5462 | } | |
5463 | hwi_cleanup_port(phba); | |
5464 | ||
5465 | disable_msix: | |
5466 | if (phba->msix_enabled) | |
5467 | pci_disable_msix(phba->pcidev); | |
5468 | ||
5469 | return ret; | |
5470 | } | |
5471 | ||
5472 | /* | |
5473 | * beiscsi_disable_port()- Disable port and cleanup driver resources. | |
5474 | * This is called in HBA error handling and driver removal. | |
5475 | * @phba: Instance Priv structure | |
5476 | * @unload: indicate driver is unloading | |
5477 | * | |
5478 | * Free the OS and HW resources held by the driver | |
5479 | **/ | |
5480 | static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload) | |
5481 | { | |
5482 | struct hwi_context_memory *phwi_context; | |
5483 | struct hwi_controller *phwi_ctrlr; | |
5484 | struct be_eq_obj *pbe_eq; | |
5485 | unsigned int i, msix_vec; | |
5486 | ||
5487 | if (!test_and_clear_bit(BEISCSI_HBA_ONLINE, &phba->state)) | |
5488 | return; | |
5489 | ||
5490 | phwi_ctrlr = phba->phwi_ctrlr; | |
5491 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
5492 | hwi_disable_intr(phba); | |
5493 | if (phba->msix_enabled) { | |
5494 | for (i = 0; i <= phba->num_cpus; i++) { | |
5495 | msix_vec = phba->msix_entries[i].vector; | |
5496 | free_irq(msix_vec, &phwi_context->be_eq[i]); | |
5497 | kfree(phba->msi_name[i]); | |
5498 | } | |
5499 | } else | |
5500 | if (phba->pcidev->irq) | |
5501 | free_irq(phba->pcidev->irq, phba); | |
5502 | pci_disable_msix(phba->pcidev); | |
5503 | ||
5504 | for (i = 0; i < phba->num_cpus; i++) { | |
5505 | pbe_eq = &phwi_context->be_eq[i]; | |
5506 | irq_poll_disable(&pbe_eq->iopoll); | |
5507 | } | |
5508 | cancel_delayed_work_sync(&phba->eqd_update); | |
5509 | cancel_work_sync(&phba->boot_work); | |
5510 | /* WQ might be running cancel queued mcc_work if we are not exiting */ | |
5511 | if (!unload && beiscsi_hba_in_error(phba)) { | |
5512 | pbe_eq = &phwi_context->be_eq[i]; | |
5513 | cancel_work_sync(&pbe_eq->mcc_work); | |
5514 | } | |
5515 | hwi_cleanup_port(phba); | |
5516 | } | |
5517 | ||
10e1a44a JB |
5518 | static void beiscsi_sess_work(struct work_struct *work) |
5519 | { | |
5520 | struct beiscsi_hba *phba; | |
5521 | ||
5522 | phba = container_of(work, struct beiscsi_hba, sess_work); | |
5523 | /* | |
5524 | * This work gets scheduled only in case of HBA error. | |
5525 | * Old sessions are gone so need to be re-established. | |
5526 | * iscsi_session_failure needs process context hence this work. | |
5527 | */ | |
5528 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); | |
5529 | } | |
5530 | ||
d1d5ca88 JB |
5531 | static void beiscsi_recover_port(struct work_struct *work) |
5532 | { | |
5533 | struct beiscsi_hba *phba; | |
5534 | ||
5535 | phba = container_of(work, struct beiscsi_hba, recover_port.work); | |
d1d5ca88 JB |
5536 | beiscsi_disable_port(phba, 0); |
5537 | beiscsi_enable_port(phba); | |
5538 | } | |
3567f36a JK |
5539 | |
5540 | static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev, | |
5541 | pci_channel_state_t state) | |
5542 | { | |
5543 | struct beiscsi_hba *phba = NULL; | |
5544 | ||
5545 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); | |
9122e991 | 5546 | set_bit(BEISCSI_HBA_PCI_ERR, &phba->state); |
3567f36a JK |
5547 | |
5548 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
5549 | "BM_%d : EEH error detected\n"); | |
5550 | ||
d1d5ca88 JB |
5551 | /* first stop UE detection when PCI error detected */ |
5552 | del_timer_sync(&phba->hw_check); | |
5553 | cancel_delayed_work_sync(&phba->recover_port); | |
5554 | ||
10e1a44a JB |
5555 | /* sessions are no longer valid, so first fail the sessions */ |
5556 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); | |
d1d5ca88 | 5557 | beiscsi_disable_port(phba, 0); |
3567f36a JK |
5558 | |
5559 | if (state == pci_channel_io_perm_failure) { | |
5560 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
5561 | "BM_%d : EEH : State PERM Failure"); | |
5562 | return PCI_ERS_RESULT_DISCONNECT; | |
5563 | } | |
5564 | ||
5565 | pci_disable_device(pdev); | |
5566 | ||
5567 | /* The error could cause the FW to trigger a flash debug dump. | |
5568 | * Resetting the card while flash dump is in progress | |
5569 | * can cause it not to recover; wait for it to finish. | |
5570 | * Wait only for first function as it is needed only once per | |
5571 | * adapter. | |
5572 | **/ | |
5573 | if (pdev->devfn == 0) | |
5574 | ssleep(30); | |
5575 | ||
5576 | return PCI_ERS_RESULT_NEED_RESET; | |
5577 | } | |
5578 | ||
5579 | static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev) | |
5580 | { | |
5581 | struct beiscsi_hba *phba = NULL; | |
5582 | int status = 0; | |
5583 | ||
5584 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); | |
5585 | ||
5586 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
5587 | "BM_%d : EEH Reset\n"); | |
5588 | ||
5589 | status = pci_enable_device(pdev); | |
5590 | if (status) | |
5591 | return PCI_ERS_RESULT_DISCONNECT; | |
5592 | ||
5593 | pci_set_master(pdev); | |
5594 | pci_set_power_state(pdev, PCI_D0); | |
5595 | pci_restore_state(pdev); | |
5596 | ||
4d2ee1e6 JB |
5597 | status = beiscsi_check_fw_rdy(phba); |
5598 | if (status) { | |
3567f36a JK |
5599 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
5600 | "BM_%d : EEH Reset Completed\n"); | |
5601 | } else { | |
5602 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, | |
5603 | "BM_%d : EEH Reset Completion Failure\n"); | |
5604 | return PCI_ERS_RESULT_DISCONNECT; | |
5605 | } | |
5606 | ||
5607 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
5608 | return PCI_ERS_RESULT_RECOVERED; | |
5609 | } | |
5610 | ||
5611 | static void beiscsi_eeh_resume(struct pci_dev *pdev) | |
5612 | { | |
d1d5ca88 JB |
5613 | struct beiscsi_hba *phba; |
5614 | int ret; | |
3567f36a JK |
5615 | |
5616 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); | |
5617 | pci_save_state(pdev); | |
5618 | ||
d1d5ca88 | 5619 | ret = beiscsi_enable_port(phba); |
4d2ee1e6 | 5620 | if (ret) |
d1d5ca88 JB |
5621 | __beiscsi_log(phba, KERN_ERR, |
5622 | "BM_%d : AER EEH resume failed\n"); | |
3567f36a JK |
5623 | } |
5624 | ||
6f039790 GKH |
5625 | static int beiscsi_dev_probe(struct pci_dev *pcidev, |
5626 | const struct pci_device_id *id) | |
6733b39a JK |
5627 | { |
5628 | struct beiscsi_hba *phba = NULL; | |
bfead3b2 JK |
5629 | struct hwi_controller *phwi_ctrlr; |
5630 | struct hwi_context_memory *phwi_context; | |
5631 | struct be_eq_obj *pbe_eq; | |
50a4b824 | 5632 | unsigned int s_handle; |
deeea8ed | 5633 | int ret, i; |
6733b39a JK |
5634 | |
5635 | ret = beiscsi_enable_pci(pcidev); | |
5636 | if (ret < 0) { | |
99bc5d55 JSJ |
5637 | dev_err(&pcidev->dev, |
5638 | "beiscsi_dev_probe - Failed to enable pci device\n"); | |
6733b39a JK |
5639 | return ret; |
5640 | } | |
5641 | ||
5642 | phba = beiscsi_hba_alloc(pcidev); | |
5643 | if (!phba) { | |
99bc5d55 JSJ |
5644 | dev_err(&pcidev->dev, |
5645 | "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n"); | |
deeea8ed | 5646 | ret = -ENOMEM; |
6733b39a JK |
5647 | goto disable_pci; |
5648 | } | |
5649 | ||
3567f36a JK |
5650 | /* Enable EEH reporting */ |
5651 | ret = pci_enable_pcie_error_reporting(pcidev); | |
5652 | if (ret) | |
5653 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, | |
5654 | "BM_%d : PCIe Error Reporting " | |
5655 | "Enabling Failed\n"); | |
5656 | ||
5657 | pci_save_state(pcidev); | |
5658 | ||
99bc5d55 JSJ |
5659 | /* Initialize Driver configuration Paramters */ |
5660 | beiscsi_hba_attrs_init(phba); | |
5661 | ||
6c83185a | 5662 | phba->mac_addr_set = false; |
e175defe | 5663 | |
f98c96b0 JK |
5664 | switch (pcidev->device) { |
5665 | case BE_DEVICE_ID1: | |
5666 | case OC_DEVICE_ID1: | |
5667 | case OC_DEVICE_ID2: | |
5668 | phba->generation = BE_GEN2; | |
09a1093a | 5669 | phba->iotask_fn = beiscsi_iotask; |
f98c96b0 JK |
5670 | break; |
5671 | case BE_DEVICE_ID2: | |
5672 | case OC_DEVICE_ID3: | |
5673 | phba->generation = BE_GEN3; | |
09a1093a | 5674 | phba->iotask_fn = beiscsi_iotask; |
f98c96b0 | 5675 | break; |
139a1b1e JSJ |
5676 | case OC_SKH_ID1: |
5677 | phba->generation = BE_GEN4; | |
09a1093a | 5678 | phba->iotask_fn = beiscsi_iotask_v2; |
bf9131cb | 5679 | break; |
f98c96b0 JK |
5680 | default: |
5681 | phba->generation = 0; | |
5682 | } | |
5683 | ||
6733b39a JK |
5684 | ret = be_ctrl_init(phba, pcidev); |
5685 | if (ret) { | |
99bc5d55 | 5686 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
4d2ee1e6 | 5687 | "BM_%d : be_ctrl_init failed\n"); |
6733b39a JK |
5688 | goto hba_free; |
5689 | } | |
5690 | ||
4d2ee1e6 JB |
5691 | ret = beiscsi_init_sliport(phba); |
5692 | if (ret) | |
4d4d1ef8 | 5693 | goto hba_free; |
e9b91193 | 5694 | |
6733b39a JK |
5695 | spin_lock_init(&phba->io_sgl_lock); |
5696 | spin_lock_init(&phba->mgmt_sgl_lock); | |
8f09a3b9 | 5697 | spin_lock_init(&phba->async_pdu_lock); |
480195c2 | 5698 | ret = beiscsi_get_fw_config(&phba->ctrl, phba); |
7da50879 | 5699 | if (ret != 0) { |
99bc5d55 JSJ |
5700 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
5701 | "BM_%d : Error getting fw config\n"); | |
7da50879 JK |
5702 | goto free_port; |
5703 | } | |
480195c2 | 5704 | beiscsi_get_port_name(&phba->ctrl, phba); |
4570f161 | 5705 | beiscsi_get_params(phba); |
6694095b | 5706 | beiscsi_set_uer_feature(phba); |
68c26a3a JK |
5707 | |
5708 | if (enable_msix) | |
5709 | find_num_cpus(phba); | |
5710 | else | |
5711 | phba->num_cpus = 1; | |
5712 | ||
5713 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
5714 | "BM_%d : num_cpus = %d\n", | |
5715 | phba->num_cpus); | |
5716 | ||
5717 | if (enable_msix) { | |
5718 | beiscsi_msix_enable(phba); | |
5719 | if (!phba->msix_enabled) | |
5720 | phba->num_cpus = 1; | |
5721 | } | |
5722 | ||
843ae752 | 5723 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
aa874f07 | 5724 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
6733b39a JK |
5725 | ret = beiscsi_init_port(phba); |
5726 | if (ret < 0) { | |
99bc5d55 JSJ |
5727 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
5728 | "BM_%d : beiscsi_dev_probe-" | |
5729 | "Failed in beiscsi_init_port\n"); | |
6733b39a JK |
5730 | goto free_port; |
5731 | } | |
5732 | ||
3567f36a | 5733 | for (i = 0; i < MAX_MCC_CMD; i++) { |
756d29c8 JK |
5734 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
5735 | phba->ctrl.mcc_tag[i] = i + 1; | |
67296ad9 | 5736 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
756d29c8 | 5737 | phba->ctrl.mcc_tag_available++; |
1957aa7f | 5738 | memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0, |
8fc01eaa | 5739 | sizeof(struct be_dma_mem)); |
756d29c8 JK |
5740 | } |
5741 | ||
5742 | phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; | |
5743 | ||
72fb46a9 | 5744 | snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq", |
6733b39a | 5745 | phba->shost->host_no); |
d8537548 | 5746 | phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name); |
6733b39a | 5747 | if (!phba->wq) { |
99bc5d55 JSJ |
5748 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
5749 | "BM_%d : beiscsi_dev_probe-" | |
5750 | "Failed to allocate work queue\n"); | |
deeea8ed | 5751 | ret = -ENOMEM; |
6733b39a JK |
5752 | goto free_twq; |
5753 | } | |
5754 | ||
10bcd47d | 5755 | INIT_DELAYED_WORK(&phba->eqd_update, beiscsi_eqd_update_work); |
6733b39a | 5756 | |
bfead3b2 JK |
5757 | phwi_ctrlr = phba->phwi_ctrlr; |
5758 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
72fb46a9 | 5759 | |
89f8b33c | 5760 | for (i = 0; i < phba->num_cpus; i++) { |
72fb46a9 | 5761 | pbe_eq = &phwi_context->be_eq[i]; |
d1d5ca88 | 5762 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); |
6733b39a | 5763 | } |
72fb46a9 | 5764 | |
89f8b33c JA |
5765 | i = (phba->msix_enabled) ? i : 0; |
5766 | /* Work item for MCC handling */ | |
5767 | pbe_eq = &phwi_context->be_eq[i]; | |
a3095016 | 5768 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); |
89f8b33c | 5769 | |
6733b39a JK |
5770 | ret = beiscsi_init_irqs(phba); |
5771 | if (ret < 0) { | |
99bc5d55 JSJ |
5772 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
5773 | "BM_%d : beiscsi_dev_probe-" | |
5774 | "Failed to beiscsi_init_irqs\n"); | |
6733b39a JK |
5775 | goto free_blkenbld; |
5776 | } | |
238f6b72 | 5777 | hwi_enable_intr(phba); |
f457a46f | 5778 | |
d1d5ca88 JB |
5779 | ret = iscsi_host_add(phba->shost, &phba->pcidev->dev); |
5780 | if (ret) | |
0598b8af JK |
5781 | goto free_blkenbld; |
5782 | ||
d1d5ca88 JB |
5783 | /* set online bit after port is operational */ |
5784 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); | |
5785 | __beiscsi_log(phba, KERN_INFO, | |
5786 | "BM_%d : port online: 0x%lx\n", phba->state); | |
5787 | ||
50a4b824 JB |
5788 | INIT_WORK(&phba->boot_work, beiscsi_boot_work); |
5789 | ret = beiscsi_boot_get_shandle(phba, &s_handle); | |
5790 | if (ret > 0) { | |
5791 | beiscsi_start_boot_work(phba, s_handle); | |
5792 | /** | |
5793 | * Set this bit after starting the work to let | |
5794 | * probe handle it first. | |
5795 | * ASYNC event can too schedule this work. | |
f457a46f | 5796 | */ |
50a4b824 JB |
5797 | set_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state); |
5798 | } | |
f457a46f | 5799 | |
96b48b92 | 5800 | beiscsi_iface_create_default(phba); |
10bcd47d JB |
5801 | schedule_delayed_work(&phba->eqd_update, |
5802 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); | |
d1d5ca88 | 5803 | |
10e1a44a | 5804 | INIT_WORK(&phba->sess_work, beiscsi_sess_work); |
d1d5ca88 | 5805 | INIT_DELAYED_WORK(&phba->recover_port, beiscsi_recover_port); |
10bcd47d JB |
5806 | /** |
5807 | * Start UE detection here. UE before this will cause stall in probe | |
5808 | * and eventually fail the probe. | |
5809 | */ | |
5810 | init_timer(&phba->hw_check); | |
5811 | phba->hw_check.function = beiscsi_hw_health_check; | |
5812 | phba->hw_check.data = (unsigned long)phba; | |
5813 | mod_timer(&phba->hw_check, | |
5814 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); | |
99bc5d55 JSJ |
5815 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
5816 | "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n"); | |
6733b39a JK |
5817 | return 0; |
5818 | ||
6733b39a JK |
5819 | free_blkenbld: |
5820 | destroy_workqueue(phba->wq); | |
89f8b33c JA |
5821 | for (i = 0; i < phba->num_cpus; i++) { |
5822 | pbe_eq = &phwi_context->be_eq[i]; | |
511cbce2 | 5823 | irq_poll_disable(&pbe_eq->iopoll); |
89f8b33c | 5824 | } |
6733b39a | 5825 | free_twq: |
d1d5ca88 | 5826 | hwi_cleanup_port(phba); |
4d2ee1e6 | 5827 | beiscsi_cleanup_port(phba); |
6733b39a JK |
5828 | beiscsi_free_mem(phba); |
5829 | free_port: | |
5830 | pci_free_consistent(phba->pcidev, | |
5831 | phba->ctrl.mbox_mem_alloced.size, | |
5832 | phba->ctrl.mbox_mem_alloced.va, | |
5833 | phba->ctrl.mbox_mem_alloced.dma); | |
5834 | beiscsi_unmap_pci_function(phba); | |
5835 | hba_free: | |
238f6b72 JK |
5836 | if (phba->msix_enabled) |
5837 | pci_disable_msix(phba->pcidev); | |
6733b39a JK |
5838 | pci_dev_put(phba->pcidev); |
5839 | iscsi_host_free(phba->shost); | |
2e7cee02 | 5840 | pci_set_drvdata(pcidev, NULL); |
6733b39a | 5841 | disable_pci: |
e307f3ac | 5842 | pci_release_regions(pcidev); |
6733b39a JK |
5843 | pci_disable_device(pcidev); |
5844 | return ret; | |
5845 | } | |
5846 | ||
d1d5ca88 JB |
5847 | static void beiscsi_remove(struct pci_dev *pcidev) |
5848 | { | |
5849 | struct beiscsi_hba *phba = NULL; | |
5850 | ||
5851 | phba = pci_get_drvdata(pcidev); | |
5852 | if (!phba) { | |
5853 | dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n"); | |
5854 | return; | |
5855 | } | |
5856 | ||
5857 | /* first stop UE detection before unloading */ | |
5858 | del_timer_sync(&phba->hw_check); | |
5859 | cancel_delayed_work_sync(&phba->recover_port); | |
10e1a44a | 5860 | cancel_work_sync(&phba->sess_work); |
d1d5ca88 JB |
5861 | |
5862 | beiscsi_iface_destroy_default(phba); | |
5863 | iscsi_host_remove(phba->shost); | |
5864 | beiscsi_disable_port(phba, 1); | |
5865 | ||
5866 | /* after cancelling boot_work */ | |
5867 | iscsi_boot_destroy_kset(phba->boot_struct.boot_kset); | |
5868 | ||
5869 | /* free all resources */ | |
5870 | destroy_workqueue(phba->wq); | |
5871 | beiscsi_cleanup_port(phba); | |
5872 | beiscsi_free_mem(phba); | |
5873 | ||
5874 | /* ctrl uninit */ | |
5875 | beiscsi_unmap_pci_function(phba); | |
5876 | pci_free_consistent(phba->pcidev, | |
5877 | phba->ctrl.mbox_mem_alloced.size, | |
5878 | phba->ctrl.mbox_mem_alloced.va, | |
5879 | phba->ctrl.mbox_mem_alloced.dma); | |
5880 | ||
5881 | pci_dev_put(phba->pcidev); | |
5882 | iscsi_host_free(phba->shost); | |
5883 | pci_disable_pcie_error_reporting(pcidev); | |
5884 | pci_set_drvdata(pcidev, NULL); | |
5885 | pci_release_regions(pcidev); | |
5886 | pci_disable_device(pcidev); | |
5887 | } | |
5888 | ||
5889 | ||
3567f36a JK |
5890 | static struct pci_error_handlers beiscsi_eeh_handlers = { |
5891 | .error_detected = beiscsi_eeh_err_detected, | |
5892 | .slot_reset = beiscsi_eeh_reset, | |
5893 | .resume = beiscsi_eeh_resume, | |
5894 | }; | |
5895 | ||
6733b39a JK |
5896 | struct iscsi_transport beiscsi_iscsi_transport = { |
5897 | .owner = THIS_MODULE, | |
5898 | .name = DRV_NAME, | |
9db0fb3a | 5899 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO | |
6733b39a | 5900 | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, |
6733b39a JK |
5901 | .create_session = beiscsi_session_create, |
5902 | .destroy_session = beiscsi_session_destroy, | |
5903 | .create_conn = beiscsi_conn_create, | |
5904 | .bind_conn = beiscsi_conn_bind, | |
5905 | .destroy_conn = iscsi_conn_teardown, | |
96b48b92 JB |
5906 | .attr_is_visible = beiscsi_attr_is_visible, |
5907 | .set_iface_param = beiscsi_iface_set_param, | |
5908 | .get_iface_param = beiscsi_iface_get_param, | |
6733b39a | 5909 | .set_param = beiscsi_set_param, |
c7f7fd5b | 5910 | .get_conn_param = iscsi_conn_get_param, |
6733b39a JK |
5911 | .get_session_param = iscsi_session_get_param, |
5912 | .get_host_param = beiscsi_get_host_param, | |
5913 | .start_conn = beiscsi_conn_start, | |
fa95d206 | 5914 | .stop_conn = iscsi_conn_stop, |
6733b39a JK |
5915 | .send_pdu = iscsi_conn_send_pdu, |
5916 | .xmit_task = beiscsi_task_xmit, | |
5917 | .cleanup_task = beiscsi_cleanup_task, | |
5918 | .alloc_pdu = beiscsi_alloc_pdu, | |
5919 | .parse_pdu_itt = beiscsi_parse_pdu, | |
5920 | .get_stats = beiscsi_conn_get_stats, | |
c7f7fd5b | 5921 | .get_ep_param = beiscsi_ep_get_param, |
6733b39a JK |
5922 | .ep_connect = beiscsi_ep_connect, |
5923 | .ep_poll = beiscsi_ep_poll, | |
5924 | .ep_disconnect = beiscsi_ep_disconnect, | |
5925 | .session_recovery_timedout = iscsi_session_recovery_timedout, | |
ffce3e2e | 5926 | .bsg_request = beiscsi_bsg_request, |
6733b39a JK |
5927 | }; |
5928 | ||
5929 | static struct pci_driver beiscsi_pci_driver = { | |
5930 | .name = DRV_NAME, | |
5931 | .probe = beiscsi_dev_probe, | |
5932 | .remove = beiscsi_remove, | |
3567f36a JK |
5933 | .id_table = beiscsi_pci_id_table, |
5934 | .err_handler = &beiscsi_eeh_handlers | |
6733b39a JK |
5935 | }; |
5936 | ||
5937 | static int __init beiscsi_module_init(void) | |
5938 | { | |
5939 | int ret; | |
5940 | ||
5941 | beiscsi_scsi_transport = | |
5942 | iscsi_register_transport(&beiscsi_iscsi_transport); | |
5943 | if (!beiscsi_scsi_transport) { | |
99bc5d55 JSJ |
5944 | printk(KERN_ERR |
5945 | "beiscsi_module_init - Unable to register beiscsi transport.\n"); | |
f55a24f2 | 5946 | return -ENOMEM; |
6733b39a | 5947 | } |
99bc5d55 JSJ |
5948 | printk(KERN_INFO "In beiscsi_module_init, tt=%p\n", |
5949 | &beiscsi_iscsi_transport); | |
6733b39a JK |
5950 | |
5951 | ret = pci_register_driver(&beiscsi_pci_driver); | |
5952 | if (ret) { | |
99bc5d55 JSJ |
5953 | printk(KERN_ERR |
5954 | "beiscsi_module_init - Unable to register beiscsi pci driver.\n"); | |
6733b39a JK |
5955 | goto unregister_iscsi_transport; |
5956 | } | |
5957 | return 0; | |
5958 | ||
5959 | unregister_iscsi_transport: | |
5960 | iscsi_unregister_transport(&beiscsi_iscsi_transport); | |
5961 | return ret; | |
5962 | } | |
5963 | ||
5964 | static void __exit beiscsi_module_exit(void) | |
5965 | { | |
5966 | pci_unregister_driver(&beiscsi_pci_driver); | |
5967 | iscsi_unregister_transport(&beiscsi_iscsi_transport); | |
5968 | } | |
5969 | ||
5970 | module_init(beiscsi_module_init); | |
5971 | module_exit(beiscsi_module_exit); |