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)\ | |
64 | ssize_t \ | |
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)\ | |
77 | int \ | |
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) \ | |
96 | ssize_t \ | |
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) \ | |
115 | int \ | |
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 | { | |
221 | struct iscsi_cls_session *cls_session; | |
222 | struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr; | |
223 | struct beiscsi_io_task *aborted_io_task; | |
224 | struct iscsi_conn *conn; | |
225 | struct beiscsi_conn *beiscsi_conn; | |
226 | struct beiscsi_hba *phba; | |
227 | struct iscsi_session *session; | |
228 | struct invalidate_command_table *inv_tbl; | |
3cbb7a74 | 229 | struct be_dma_mem nonemb_cmd; |
4183122d | 230 | unsigned int cid, tag, num_invalidate; |
1957aa7f | 231 | int rc; |
4183122d JK |
232 | |
233 | cls_session = starget_to_session(scsi_target(sc->device)); | |
234 | session = cls_session->dd_data; | |
235 | ||
659743b0 | 236 | spin_lock_bh(&session->frwd_lock); |
4183122d JK |
237 | if (!aborted_task || !aborted_task->sc) { |
238 | /* we raced */ | |
659743b0 | 239 | spin_unlock_bh(&session->frwd_lock); |
4183122d JK |
240 | return SUCCESS; |
241 | } | |
242 | ||
243 | aborted_io_task = aborted_task->dd_data; | |
244 | if (!aborted_io_task->scsi_cmnd) { | |
245 | /* raced or invalid command */ | |
659743b0 | 246 | spin_unlock_bh(&session->frwd_lock); |
4183122d JK |
247 | return SUCCESS; |
248 | } | |
659743b0 | 249 | spin_unlock_bh(&session->frwd_lock); |
7626c06b JK |
250 | /* Invalidate WRB Posted for this Task */ |
251 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, | |
252 | aborted_io_task->pwrb_handle->pwrb, | |
253 | 1); | |
254 | ||
4183122d JK |
255 | conn = aborted_task->conn; |
256 | beiscsi_conn = conn->dd_data; | |
257 | phba = beiscsi_conn->phba; | |
258 | ||
259 | /* invalidate iocb */ | |
260 | cid = beiscsi_conn->beiscsi_conn_cid; | |
261 | inv_tbl = phba->inv_tbl; | |
262 | memset(inv_tbl, 0x0, sizeof(*inv_tbl)); | |
263 | inv_tbl->cid = cid; | |
264 | inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index; | |
265 | num_invalidate = 1; | |
3cbb7a74 JK |
266 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
267 | sizeof(struct invalidate_commands_params_in), | |
268 | &nonemb_cmd.dma); | |
269 | if (nonemb_cmd.va == NULL) { | |
99bc5d55 JSJ |
270 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
271 | "BM_%d : Failed to allocate memory for" | |
272 | "mgmt_invalidate_icds\n"); | |
3cbb7a74 JK |
273 | return FAILED; |
274 | } | |
275 | nonemb_cmd.size = sizeof(struct invalidate_commands_params_in); | |
276 | ||
277 | tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, | |
278 | cid, &nonemb_cmd); | |
4183122d | 279 | if (!tag) { |
99bc5d55 JSJ |
280 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
281 | "BM_%d : mgmt_invalidate_icds could not be" | |
282 | "submitted\n"); | |
3cbb7a74 JK |
283 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
284 | nonemb_cmd.va, nonemb_cmd.dma); | |
285 | ||
4183122d | 286 | return FAILED; |
4183122d | 287 | } |
e175defe | 288 | |
88840332 | 289 | rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); |
1957aa7f JK |
290 | if (rc != -EBUSY) |
291 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, | |
292 | nonemb_cmd.va, nonemb_cmd.dma); | |
293 | ||
4183122d JK |
294 | return iscsi_eh_abort(sc); |
295 | } | |
296 | ||
297 | static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) | |
298 | { | |
299 | struct iscsi_task *abrt_task; | |
300 | struct beiscsi_io_task *abrt_io_task; | |
301 | struct iscsi_conn *conn; | |
302 | struct beiscsi_conn *beiscsi_conn; | |
303 | struct beiscsi_hba *phba; | |
304 | struct iscsi_session *session; | |
305 | struct iscsi_cls_session *cls_session; | |
306 | struct invalidate_command_table *inv_tbl; | |
3cbb7a74 | 307 | struct be_dma_mem nonemb_cmd; |
4183122d | 308 | unsigned int cid, tag, i, num_invalidate; |
1957aa7f | 309 | int rc; |
4183122d JK |
310 | |
311 | /* invalidate iocbs */ | |
312 | cls_session = starget_to_session(scsi_target(sc->device)); | |
313 | session = cls_session->dd_data; | |
659743b0 | 314 | spin_lock_bh(&session->frwd_lock); |
db7f7709 | 315 | if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { |
659743b0 | 316 | spin_unlock_bh(&session->frwd_lock); |
db7f7709 JK |
317 | return FAILED; |
318 | } | |
4183122d JK |
319 | conn = session->leadconn; |
320 | beiscsi_conn = conn->dd_data; | |
321 | phba = beiscsi_conn->phba; | |
322 | cid = beiscsi_conn->beiscsi_conn_cid; | |
323 | inv_tbl = phba->inv_tbl; | |
324 | memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN); | |
325 | num_invalidate = 0; | |
326 | for (i = 0; i < conn->session->cmds_max; i++) { | |
327 | abrt_task = conn->session->cmds[i]; | |
328 | abrt_io_task = abrt_task->dd_data; | |
329 | if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE) | |
330 | continue; | |
331 | ||
126e964a | 332 | if (sc->device->lun != abrt_task->sc->device->lun) |
4183122d JK |
333 | continue; |
334 | ||
7626c06b JK |
335 | /* Invalidate WRB Posted for this Task */ |
336 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, | |
337 | abrt_io_task->pwrb_handle->pwrb, | |
338 | 1); | |
339 | ||
4183122d JK |
340 | inv_tbl->cid = cid; |
341 | inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index; | |
342 | num_invalidate++; | |
343 | inv_tbl++; | |
344 | } | |
659743b0 | 345 | spin_unlock_bh(&session->frwd_lock); |
4183122d JK |
346 | inv_tbl = phba->inv_tbl; |
347 | ||
3cbb7a74 JK |
348 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
349 | sizeof(struct invalidate_commands_params_in), | |
350 | &nonemb_cmd.dma); | |
351 | if (nonemb_cmd.va == NULL) { | |
99bc5d55 JSJ |
352 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
353 | "BM_%d : Failed to allocate memory for" | |
354 | "mgmt_invalidate_icds\n"); | |
3cbb7a74 JK |
355 | return FAILED; |
356 | } | |
357 | nonemb_cmd.size = sizeof(struct invalidate_commands_params_in); | |
358 | memset(nonemb_cmd.va, 0, nonemb_cmd.size); | |
359 | tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, | |
360 | cid, &nonemb_cmd); | |
4183122d | 361 | if (!tag) { |
99bc5d55 JSJ |
362 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
363 | "BM_%d : mgmt_invalidate_icds could not be" | |
364 | " submitted\n"); | |
3cbb7a74 JK |
365 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
366 | nonemb_cmd.va, nonemb_cmd.dma); | |
4183122d | 367 | return FAILED; |
4183122d | 368 | } |
e175defe | 369 | |
88840332 | 370 | rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); |
1957aa7f JK |
371 | if (rc != -EBUSY) |
372 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, | |
373 | nonemb_cmd.va, nonemb_cmd.dma); | |
4183122d | 374 | return iscsi_eh_device_reset(sc); |
4183122d JK |
375 | } |
376 | ||
bfead3b2 | 377 | /*------------------- PCI Driver operations and data ----------------- */ |
9baa3c34 | 378 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
bfead3b2 | 379 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
f98c96b0 | 380 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
bfead3b2 JK |
381 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
382 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, | |
383 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, | |
139a1b1e | 384 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
bfead3b2 JK |
385 | { 0 } |
386 | }; | |
387 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); | |
388 | ||
99bc5d55 | 389 | |
6733b39a JK |
390 | static struct scsi_host_template beiscsi_sht = { |
391 | .module = THIS_MODULE, | |
c4f39bda | 392 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
6733b39a JK |
393 | .proc_name = DRV_NAME, |
394 | .queuecommand = iscsi_queuecommand, | |
db5ed4df | 395 | .change_queue_depth = scsi_change_queue_depth, |
6733b39a JK |
396 | .slave_configure = beiscsi_slave_configure, |
397 | .target_alloc = iscsi_target_alloc, | |
4183122d JK |
398 | .eh_abort_handler = beiscsi_eh_abort, |
399 | .eh_device_reset_handler = beiscsi_eh_device_reset, | |
309ce156 | 400 | .eh_target_reset_handler = iscsi_eh_session_reset, |
99bc5d55 | 401 | .shost_attrs = beiscsi_attrs, |
6733b39a JK |
402 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
403 | .can_queue = BE2_IO_DEPTH, | |
404 | .this_id = -1, | |
405 | .max_sectors = BEISCSI_MAX_SECTORS, | |
406 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, | |
407 | .use_clustering = ENABLE_CLUSTERING, | |
ffce3e2e | 408 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
c40ecc12 | 409 | .track_queue_depth = 1, |
6733b39a | 410 | }; |
6733b39a | 411 | |
bfead3b2 | 412 | static struct scsi_transport_template *beiscsi_scsi_transport; |
6733b39a JK |
413 | |
414 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) | |
415 | { | |
416 | struct beiscsi_hba *phba; | |
417 | struct Scsi_Host *shost; | |
418 | ||
419 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); | |
420 | if (!shost) { | |
99bc5d55 JSJ |
421 | dev_err(&pcidev->dev, |
422 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); | |
6733b39a JK |
423 | return NULL; |
424 | } | |
6733b39a JK |
425 | shost->max_id = BE2_MAX_SESSIONS; |
426 | shost->max_channel = 0; | |
427 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; | |
428 | shost->max_lun = BEISCSI_NUM_MAX_LUN; | |
429 | shost->transportt = beiscsi_scsi_transport; | |
6733b39a JK |
430 | phba = iscsi_host_priv(shost); |
431 | memset(phba, 0, sizeof(*phba)); | |
432 | phba->shost = shost; | |
433 | phba->pcidev = pci_dev_get(pcidev); | |
2807afb7 | 434 | pci_set_drvdata(pcidev, phba); |
0e43895e | 435 | phba->interface_handle = 0xFFFFFFFF; |
6733b39a | 436 | |
6733b39a | 437 | return phba; |
6733b39a JK |
438 | } |
439 | ||
440 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) | |
441 | { | |
442 | if (phba->csr_va) { | |
443 | iounmap(phba->csr_va); | |
444 | phba->csr_va = NULL; | |
445 | } | |
446 | if (phba->db_va) { | |
447 | iounmap(phba->db_va); | |
448 | phba->db_va = NULL; | |
449 | } | |
450 | if (phba->pci_va) { | |
451 | iounmap(phba->pci_va); | |
452 | phba->pci_va = NULL; | |
453 | } | |
454 | } | |
455 | ||
456 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, | |
457 | struct pci_dev *pcidev) | |
458 | { | |
459 | u8 __iomem *addr; | |
f98c96b0 | 460 | int pcicfg_reg; |
6733b39a JK |
461 | |
462 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), | |
463 | pci_resource_len(pcidev, 2)); | |
464 | if (addr == NULL) | |
465 | return -ENOMEM; | |
466 | phba->ctrl.csr = addr; | |
467 | phba->csr_va = addr; | |
468 | phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2); | |
469 | ||
470 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); | |
471 | if (addr == NULL) | |
472 | goto pci_map_err; | |
473 | phba->ctrl.db = addr; | |
474 | phba->db_va = addr; | |
475 | phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4); | |
476 | ||
f98c96b0 JK |
477 | if (phba->generation == BE_GEN2) |
478 | pcicfg_reg = 1; | |
479 | else | |
480 | pcicfg_reg = 0; | |
481 | ||
482 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), | |
483 | pci_resource_len(pcidev, pcicfg_reg)); | |
484 | ||
6733b39a JK |
485 | if (addr == NULL) |
486 | goto pci_map_err; | |
487 | phba->ctrl.pcicfg = addr; | |
488 | phba->pci_va = addr; | |
f98c96b0 | 489 | phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg); |
6733b39a JK |
490 | return 0; |
491 | ||
492 | pci_map_err: | |
493 | beiscsi_unmap_pci_function(phba); | |
494 | return -ENOMEM; | |
495 | } | |
496 | ||
497 | static int beiscsi_enable_pci(struct pci_dev *pcidev) | |
498 | { | |
499 | int ret; | |
500 | ||
501 | ret = pci_enable_device(pcidev); | |
502 | if (ret) { | |
99bc5d55 JSJ |
503 | dev_err(&pcidev->dev, |
504 | "beiscsi_enable_pci - enable device failed\n"); | |
6733b39a JK |
505 | return ret; |
506 | } | |
507 | ||
e307f3ac JSJ |
508 | ret = pci_request_regions(pcidev, DRV_NAME); |
509 | if (ret) { | |
510 | dev_err(&pcidev->dev, | |
511 | "beiscsi_enable_pci - request region failed\n"); | |
512 | goto pci_dev_disable; | |
513 | } | |
514 | ||
bfead3b2 | 515 | pci_set_master(pcidev); |
6c57625b JK |
516 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64)); |
517 | if (ret) { | |
518 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)); | |
519 | if (ret) { | |
520 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); | |
e307f3ac | 521 | goto pci_region_release; |
6c57625b JK |
522 | } else { |
523 | ret = pci_set_consistent_dma_mask(pcidev, | |
524 | DMA_BIT_MASK(32)); | |
525 | } | |
526 | } else { | |
527 | ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); | |
6733b39a JK |
528 | if (ret) { |
529 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); | |
e307f3ac | 530 | goto pci_region_release; |
6733b39a JK |
531 | } |
532 | } | |
533 | return 0; | |
e307f3ac JSJ |
534 | |
535 | pci_region_release: | |
536 | pci_release_regions(pcidev); | |
537 | pci_dev_disable: | |
538 | pci_disable_device(pcidev); | |
539 | ||
540 | return ret; | |
6733b39a JK |
541 | } |
542 | ||
543 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) | |
544 | { | |
545 | struct be_ctrl_info *ctrl = &phba->ctrl; | |
546 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; | |
547 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; | |
548 | int status = 0; | |
549 | ||
550 | ctrl->pdev = pdev; | |
551 | status = beiscsi_map_pci_bars(phba, pdev); | |
552 | if (status) | |
553 | return status; | |
6733b39a JK |
554 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
555 | mbox_mem_alloc->va = pci_alloc_consistent(pdev, | |
556 | mbox_mem_alloc->size, | |
557 | &mbox_mem_alloc->dma); | |
558 | if (!mbox_mem_alloc->va) { | |
559 | beiscsi_unmap_pci_function(phba); | |
a49e06d5 | 560 | return -ENOMEM; |
6733b39a JK |
561 | } |
562 | ||
563 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); | |
564 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); | |
565 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); | |
566 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); | |
c03a50f7 | 567 | mutex_init(&ctrl->mbox_lock); |
bfead3b2 | 568 | spin_lock_init(&phba->ctrl.mcc_lock); |
bfead3b2 | 569 | |
6733b39a JK |
570 | return status; |
571 | } | |
572 | ||
843ae752 JK |
573 | /** |
574 | * beiscsi_get_params()- Set the config paramters | |
575 | * @phba: ptr device priv structure | |
576 | **/ | |
6733b39a JK |
577 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
578 | { | |
843ae752 JK |
579 | uint32_t total_cid_count = 0; |
580 | uint32_t total_icd_count = 0; | |
581 | uint8_t ulp_num = 0; | |
582 | ||
583 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + | |
584 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); | |
585 | ||
cf987b79 JK |
586 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
587 | uint32_t align_mask = 0; | |
588 | uint32_t icd_post_per_page = 0; | |
589 | uint32_t icd_count_unavailable = 0; | |
590 | uint32_t icd_start = 0, icd_count = 0; | |
591 | uint32_t icd_start_align = 0, icd_count_align = 0; | |
592 | ||
843ae752 | 593 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
cf987b79 JK |
594 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
595 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; | |
596 | ||
597 | /* Get ICD count that can be posted on each page */ | |
598 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * | |
599 | sizeof(struct iscsi_sge))); | |
600 | align_mask = (icd_post_per_page - 1); | |
601 | ||
602 | /* Check if icd_start is aligned ICD per page posting */ | |
603 | if (icd_start % icd_post_per_page) { | |
604 | icd_start_align = ((icd_start + | |
605 | icd_post_per_page) & | |
606 | ~(align_mask)); | |
607 | phba->fw_config. | |
608 | iscsi_icd_start[ulp_num] = | |
609 | icd_start_align; | |
610 | } | |
611 | ||
612 | icd_count_align = (icd_count & ~align_mask); | |
613 | ||
614 | /* ICD discarded in the process of alignment */ | |
615 | if (icd_start_align) | |
616 | icd_count_unavailable = ((icd_start_align - | |
617 | icd_start) + | |
618 | (icd_count - | |
619 | icd_count_align)); | |
620 | ||
621 | /* Updated ICD count available */ | |
622 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - | |
623 | icd_count_unavailable); | |
624 | ||
625 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
626 | "BM_%d : Aligned ICD values\n" | |
627 | "\t ICD Start : %d\n" | |
628 | "\t ICD Count : %d\n" | |
629 | "\t ICD Discarded : %d\n", | |
630 | phba->fw_config. | |
631 | iscsi_icd_start[ulp_num], | |
632 | phba->fw_config. | |
633 | iscsi_icd_count[ulp_num], | |
634 | icd_count_unavailable); | |
843ae752 JK |
635 | break; |
636 | } | |
cf987b79 | 637 | } |
843ae752 | 638 | |
cf987b79 | 639 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
843ae752 JK |
640 | phba->params.ios_per_ctrl = (total_icd_count - |
641 | (total_cid_count + | |
642 | BE2_TMFS + BE2_NOPOUT_REQ)); | |
643 | phba->params.cxns_per_ctrl = total_cid_count; | |
644 | phba->params.asyncpdus_per_ctrl = total_cid_count; | |
645 | phba->params.icds_per_ctrl = total_icd_count; | |
6733b39a JK |
646 | phba->params.num_sge_per_io = BE2_SGE; |
647 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; | |
648 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; | |
649 | phba->params.eq_timer = 64; | |
843ae752 JK |
650 | phba->params.num_eq_entries = 1024; |
651 | phba->params.num_cq_entries = 1024; | |
6733b39a JK |
652 | phba->params.wrbs_per_cxn = 256; |
653 | } | |
654 | ||
655 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, | |
656 | unsigned int id, unsigned int clr_interrupt, | |
657 | unsigned int num_processed, | |
658 | unsigned char rearm, unsigned char event) | |
659 | { | |
660 | u32 val = 0; | |
e08b3c8b | 661 | |
6733b39a JK |
662 | if (rearm) |
663 | val |= 1 << DB_EQ_REARM_SHIFT; | |
664 | if (clr_interrupt) | |
665 | val |= 1 << DB_EQ_CLR_SHIFT; | |
666 | if (event) | |
667 | val |= 1 << DB_EQ_EVNT_SHIFT; | |
e08b3c8b | 668 | |
6733b39a | 669 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
e08b3c8b JK |
670 | /* Setting lower order EQ_ID Bits */ |
671 | val |= (id & DB_EQ_RING_ID_LOW_MASK); | |
672 | ||
673 | /* Setting Higher order EQ_ID Bits */ | |
674 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & | |
675 | DB_EQ_RING_ID_HIGH_MASK) | |
676 | << DB_EQ_HIGH_SET_SHIFT); | |
677 | ||
6733b39a JK |
678 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
679 | } | |
680 | ||
bfead3b2 JK |
681 | /** |
682 | * be_isr_mcc - The isr routine of the driver. | |
683 | * @irq: Not used | |
684 | * @dev_id: Pointer to host adapter structure | |
685 | */ | |
686 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) | |
687 | { | |
688 | struct beiscsi_hba *phba; | |
a3095016 | 689 | struct be_eq_entry *eqe; |
bfead3b2 JK |
690 | struct be_queue_info *eq; |
691 | struct be_queue_info *mcc; | |
a3095016 | 692 | unsigned int mcc_events; |
bfead3b2 | 693 | struct be_eq_obj *pbe_eq; |
bfead3b2 JK |
694 | |
695 | pbe_eq = dev_id; | |
696 | eq = &pbe_eq->q; | |
697 | phba = pbe_eq->phba; | |
698 | mcc = &phba->ctrl.mcc_obj.cq; | |
699 | eqe = queue_tail_node(eq); | |
bfead3b2 | 700 | |
a3095016 | 701 | mcc_events = 0; |
bfead3b2 JK |
702 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
703 | & EQE_VALID_MASK) { | |
704 | if (((eqe->dw[offsetof(struct amap_eq_entry, | |
705 | resource_id) / 32] & | |
706 | EQE_RESID_MASK) >> 16) == mcc->id) { | |
a3095016 | 707 | mcc_events++; |
bfead3b2 JK |
708 | } |
709 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); | |
710 | queue_tail_inc(eq); | |
711 | eqe = queue_tail_node(eq); | |
bfead3b2 | 712 | } |
bfead3b2 | 713 | |
a3095016 JB |
714 | if (mcc_events) { |
715 | queue_work(phba->wq, &pbe_eq->mcc_work); | |
716 | hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1); | |
717 | } | |
bfead3b2 JK |
718 | return IRQ_HANDLED; |
719 | } | |
720 | ||
721 | /** | |
722 | * be_isr_msix - The isr routine of the driver. | |
723 | * @irq: Not used | |
724 | * @dev_id: Pointer to host adapter structure | |
725 | */ | |
726 | static irqreturn_t be_isr_msix(int irq, void *dev_id) | |
727 | { | |
728 | struct beiscsi_hba *phba; | |
bfead3b2 | 729 | struct be_queue_info *eq; |
bfead3b2 | 730 | struct be_eq_obj *pbe_eq; |
bfead3b2 JK |
731 | |
732 | pbe_eq = dev_id; | |
733 | eq = &pbe_eq->q; | |
bfead3b2 JK |
734 | |
735 | phba = pbe_eq->phba; | |
1094cf68 JB |
736 | /* disable interrupt till iopoll completes */ |
737 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); | |
738 | irq_poll_sched(&pbe_eq->iopoll); | |
72fb46a9 JSJ |
739 | |
740 | return IRQ_HANDLED; | |
bfead3b2 JK |
741 | } |
742 | ||
6733b39a JK |
743 | /** |
744 | * be_isr - The isr routine of the driver. | |
745 | * @irq: Not used | |
746 | * @dev_id: Pointer to host adapter structure | |
747 | */ | |
748 | static irqreturn_t be_isr(int irq, void *dev_id) | |
749 | { | |
750 | struct beiscsi_hba *phba; | |
751 | struct hwi_controller *phwi_ctrlr; | |
752 | struct hwi_context_memory *phwi_context; | |
a3095016 | 753 | struct be_eq_entry *eqe; |
6733b39a | 754 | struct be_queue_info *eq; |
bfead3b2 | 755 | struct be_queue_info *mcc; |
a3095016 | 756 | unsigned int mcc_events, io_events; |
6733b39a | 757 | struct be_ctrl_info *ctrl; |
bfead3b2 | 758 | struct be_eq_obj *pbe_eq; |
a3095016 | 759 | int isr, rearm; |
6733b39a JK |
760 | |
761 | phba = dev_id; | |
6eab04a8 | 762 | ctrl = &phba->ctrl; |
bfead3b2 JK |
763 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
764 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); | |
765 | if (!isr) | |
766 | return IRQ_NONE; | |
6733b39a JK |
767 | |
768 | phwi_ctrlr = phba->phwi_ctrlr; | |
769 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
bfead3b2 JK |
770 | pbe_eq = &phwi_context->be_eq[0]; |
771 | ||
772 | eq = &phwi_context->be_eq[0].q; | |
773 | mcc = &phba->ctrl.mcc_obj.cq; | |
6733b39a | 774 | eqe = queue_tail_node(eq); |
6733b39a | 775 | |
a3095016 JB |
776 | io_events = 0; |
777 | mcc_events = 0; | |
89f8b33c JA |
778 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
779 | & EQE_VALID_MASK) { | |
780 | if (((eqe->dw[offsetof(struct amap_eq_entry, | |
a3095016 JB |
781 | resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id) |
782 | mcc_events++; | |
783 | else | |
784 | io_events++; | |
89f8b33c JA |
785 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
786 | queue_tail_inc(eq); | |
787 | eqe = queue_tail_node(eq); | |
788 | } | |
a3095016 | 789 | if (!io_events && !mcc_events) |
89f8b33c | 790 | return IRQ_NONE; |
a3095016 JB |
791 | |
792 | /* no need to rearm if interrupt is only for IOs */ | |
793 | rearm = 0; | |
794 | if (mcc_events) { | |
795 | queue_work(phba->wq, &pbe_eq->mcc_work); | |
796 | /* rearm for MCCQ */ | |
797 | rearm = 1; | |
798 | } | |
799 | if (io_events) | |
800 | irq_poll_sched(&pbe_eq->iopoll); | |
801 | hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1); | |
802 | return IRQ_HANDLED; | |
6733b39a JK |
803 | } |
804 | ||
1094cf68 | 805 | |
6733b39a JK |
806 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
807 | { | |
808 | struct pci_dev *pcidev = phba->pcidev; | |
bfead3b2 JK |
809 | struct hwi_controller *phwi_ctrlr; |
810 | struct hwi_context_memory *phwi_context; | |
4f5af07e | 811 | int ret, msix_vec, i, j; |
6733b39a | 812 | |
bfead3b2 JK |
813 | phwi_ctrlr = phba->phwi_ctrlr; |
814 | phwi_context = phwi_ctrlr->phwi_ctxt; | |
815 | ||
816 | if (phba->msix_enabled) { | |
817 | for (i = 0; i < phba->num_cpus; i++) { | |
8fcfb210 JK |
818 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, |
819 | GFP_KERNEL); | |
820 | if (!phba->msi_name[i]) { | |
821 | ret = -ENOMEM; | |
822 | goto free_msix_irqs; | |
823 | } | |
824 | ||
825 | sprintf(phba->msi_name[i], "beiscsi_%02x_%02x", | |
826 | phba->shost->host_no, i); | |
bfead3b2 | 827 | msix_vec = phba->msix_entries[i].vector; |
8fcfb210 JK |
828 | ret = request_irq(msix_vec, be_isr_msix, 0, |
829 | phba->msi_name[i], | |
bfead3b2 | 830 | &phwi_context->be_eq[i]); |
4f5af07e | 831 | if (ret) { |
99bc5d55 JSJ |
832 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
833 | "BM_%d : beiscsi_init_irqs-Failed to" | |
834 | "register msix for i = %d\n", | |
835 | i); | |
8fcfb210 | 836 | kfree(phba->msi_name[i]); |
4f5af07e JK |
837 | goto free_msix_irqs; |
838 | } | |
bfead3b2 | 839 | } |
8fcfb210 JK |
840 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL); |
841 | if (!phba->msi_name[i]) { | |
842 | ret = -ENOMEM; | |
843 | goto free_msix_irqs; | |
844 | } | |
845 | sprintf(phba->msi_name[i], "beiscsi_mcc_%02x", | |
846 | phba->shost->host_no); | |
bfead3b2 | 847 | msix_vec = phba->msix_entries[i].vector; |
8fcfb210 | 848 | ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i], |
bfead3b2 | 849 | &phwi_context->be_eq[i]); |
4f5af07e | 850 | if (ret) { |
99bc5d55 JSJ |
851 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
852 | "BM_%d : beiscsi_init_irqs-" | |
853 | "Failed to register beiscsi_msix_mcc\n"); | |
8fcfb210 | 854 | kfree(phba->msi_name[i]); |
4f5af07e JK |
855 | goto free_msix_irqs; |
856 | } | |
857 | ||
bfead3b2 JK |
858 | } else { |
859 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, | |
860 | "beiscsi", phba); | |
861 | if (ret) { | |
99bc5d55 JSJ |
862 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
863 | "BM_%d : beiscsi_init_irqs-" | |
864 | "Failed to register irq\\n"); | |
bfead3b2 JK |
865 | return ret; |
866 | } | |
6733b39a JK |
867 | } |
868 | return 0; | |
4f5af07e | 869 | free_msix_irqs: |
8fcfb210 JK |
870 | for (j = i - 1; j >= 0; j--) { |
871 | kfree(phba->msi_name[j]); | |
872 | msix_vec = phba->msix_entries[j].vector; | |
4f5af07e | 873 | free_irq(msix_vec, &phwi_context->be_eq[j]); |
8fcfb210 | 874 | } |
4f5af07e | 875 | return ret; |
6733b39a JK |
876 | } |
877 | ||
e08b3c8b | 878 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
6733b39a | 879 | unsigned int id, unsigned int num_processed, |
1094cf68 | 880 | unsigned char rearm) |
6733b39a JK |
881 | { |
882 | u32 val = 0; | |
e08b3c8b | 883 | |
6733b39a JK |
884 | if (rearm) |
885 | val |= 1 << DB_CQ_REARM_SHIFT; | |
e08b3c8b | 886 | |
6733b39a | 887 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
e08b3c8b JK |
888 | |
889 | /* Setting lower order CQ_ID Bits */ | |
890 | val |= (id & DB_CQ_RING_ID_LOW_MASK); | |
891 | ||
892 | /* Setting Higher order CQ_ID Bits */ | |
893 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & | |
894 | DB_CQ_RING_ID_HIGH_MASK) | |
895 | << DB_CQ_HIGH_SET_SHIFT); | |
896 | ||
6733b39a JK |
897 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
898 | } | |
899 | ||
6733b39a JK |
900 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
901 | { | |
902 | struct sgl_handle *psgl_handle; | |
903 | ||
10139fe0 | 904 | spin_lock_bh(&phba->io_sgl_lock); |
6733b39a | 905 | if (phba->io_sgl_hndl_avbl) { |
99bc5d55 JSJ |
906 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
907 | "BM_%d : In alloc_io_sgl_handle," | |
908 | " io_sgl_alloc_index=%d\n", | |
909 | phba->io_sgl_alloc_index); | |
910 | ||
6733b39a JK |
911 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
912 | io_sgl_alloc_index]; | |
913 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; | |
914 | phba->io_sgl_hndl_avbl--; | |
bfead3b2 JK |
915 | if (phba->io_sgl_alloc_index == (phba->params. |
916 | ios_per_ctrl - 1)) | |
6733b39a JK |
917 | phba->io_sgl_alloc_index = 0; |
918 | else | |
919 | phba->io_sgl_alloc_index++; | |
920 | } else | |
921 | psgl_handle = NULL; | |
10139fe0 | 922 | spin_unlock_bh(&phba->io_sgl_lock); |
6733b39a JK |
923 | return psgl_handle; |
924 | } | |
925 | ||
926 | static void | |
927 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) | |
928 | { | |
10139fe0 | 929 | spin_lock_bh(&phba->io_sgl_lock); |
99bc5d55 JSJ |
930 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
931 | "BM_%d : In free_,io_sgl_free_index=%d\n", | |
932 | phba->io_sgl_free_index); | |
933 | ||
6733b39a JK |
934 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
935 | /* | |
936 | * this can happen if clean_task is called on a task that | |
937 | * failed in xmit_task or alloc_pdu. | |
938 | */ | |
99bc5d55 JSJ |
939 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
940 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d," | |
941 | "value there=%p\n", phba->io_sgl_free_index, | |
942 | phba->io_sgl_hndl_base | |
943 | [phba->io_sgl_free_index]); | |
10139fe0 | 944 | spin_unlock_bh(&phba->io_sgl_lock); |
6733b39a JK |
945 | return; |
946 | } | |
947 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; | |
948 | phba->io_sgl_hndl_avbl++; | |
949 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) | |
950 | phba->io_sgl_free_index = 0; | |
951 | else | |
952 | phba->io_sgl_free_index++; | |
10139fe0 | 953 | spin_unlock_bh(&phba->io_sgl_lock); |
6733b39a JK |
954 | } |
955 | ||
cb564c6b JB |
956 | static inline struct wrb_handle * |
957 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, | |
958 | unsigned int wrbs_per_cxn) | |
959 | { | |
960 | struct wrb_handle *pwrb_handle; | |
961 | ||
f64d92e6 | 962 | spin_lock_bh(&pwrb_context->wrb_lock); |
cb564c6b JB |
963 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
964 | pwrb_context->wrb_handles_available--; | |
965 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) | |
966 | pwrb_context->alloc_index = 0; | |
967 | else | |
968 | pwrb_context->alloc_index++; | |
f64d92e6 | 969 | spin_unlock_bh(&pwrb_context->wrb_lock); |
bf9b7554 JB |
970 | |
971 | if (pwrb_handle) | |
972 | memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); | |
cb564c6b JB |
973 | |
974 | return pwrb_handle; | |
975 | } | |
976 | ||
6733b39a JK |
977 | /** |
978 | * alloc_wrb_handle - To allocate a wrb handle | |
979 | * @phba: The hba pointer | |
980 | * @cid: The cid to use for allocation | |
340c99e9 | 981 | * @pwrb_context: ptr to ptr to wrb context |
6733b39a JK |
982 | * |
983 | * This happens under session_lock until submission to chip | |
984 | */ | |
340c99e9 | 985 | struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, |
cb564c6b | 986 | struct hwi_wrb_context **pcontext) |
6733b39a JK |
987 | { |
988 | struct hwi_wrb_context *pwrb_context; | |
989 | struct hwi_controller *phwi_ctrlr; | |
a7909b39 | 990 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
6733b39a JK |
991 | |
992 | phwi_ctrlr = phba->phwi_ctrlr; | |
a7909b39 | 993 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
cb564c6b JB |
994 | /* return the context address */ |
995 | *pcontext = pwrb_context; | |
996 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); | |
997 | } | |
340c99e9 | 998 | |
cb564c6b JB |
999 | static inline void |
1000 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, | |
1001 | struct wrb_handle *pwrb_handle, | |
1002 | unsigned int wrbs_per_cxn) | |
1003 | { | |
f64d92e6 | 1004 | spin_lock_bh(&pwrb_context->wrb_lock); |
cb564c6b JB |
1005 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
1006 | pwrb_context->wrb_handles_available++; | |
1007 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) | |
1008 | pwrb_context->free_index = 0; | |
1009 | else | |
1010 | pwrb_context->free_index++; | |
f64d92e6 | 1011 | spin_unlock_bh(&pwrb_context->wrb_lock); |
6733b39a JK |
1012 | } |
1013 | ||
1014 | /** | |
1015 | * free_wrb_handle - To free the wrb handle back to pool | |
1016 | * @phba: The hba pointer | |
1017 | * @pwrb_context: The context to free from | |
1018 | * @pwrb_handle: The wrb_handle to free | |
1019 | * | |
1020 | * This happens under session_lock until submission to chip | |
1021 | */ | |
1022 | static void | |
1023 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, | |
1024 | struct wrb_handle *pwrb_handle) | |
1025 | { | |
cb564c6b JB |
1026 | beiscsi_put_wrb_handle(pwrb_context, |
1027 | pwrb_handle, | |
1028 | phba->params.wrbs_per_cxn); | |
99bc5d55 JSJ |
1029 | beiscsi_log(phba, KERN_INFO, |
1030 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
1031 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" | |
1032 | "wrb_handles_available=%d\n", | |
1033 | pwrb_handle, pwrb_context->free_index, | |
1034 | pwrb_context->wrb_handles_available); | |
6733b39a JK |
1035 | } |
1036 | ||
1037 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) | |
1038 | { | |
1039 | struct sgl_handle *psgl_handle; | |
1040 | ||
10139fe0 | 1041 | spin_lock_bh(&phba->mgmt_sgl_lock); |
6733b39a JK |
1042 | if (phba->eh_sgl_hndl_avbl) { |
1043 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; | |
1044 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; | |
99bc5d55 JSJ |
1045 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
1046 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", | |
1047 | phba->eh_sgl_alloc_index, | |
1048 | phba->eh_sgl_alloc_index); | |
1049 | ||
6733b39a JK |
1050 | phba->eh_sgl_hndl_avbl--; |
1051 | if (phba->eh_sgl_alloc_index == | |
1052 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - | |
1053 | 1)) | |
1054 | phba->eh_sgl_alloc_index = 0; | |
1055 | else | |
1056 | phba->eh_sgl_alloc_index++; | |
1057 | } else | |
1058 | psgl_handle = NULL; | |
10139fe0 | 1059 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
6733b39a JK |
1060 | return psgl_handle; |
1061 | } | |
1062 | ||
1063 | void | |
1064 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) | |
1065 | { | |
10139fe0 | 1066 | spin_lock_bh(&phba->mgmt_sgl_lock); |
99bc5d55 JSJ |
1067 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
1068 | "BM_%d : In free_mgmt_sgl_handle," | |
1069 | "eh_sgl_free_index=%d\n", | |
1070 | phba->eh_sgl_free_index); | |
1071 | ||
6733b39a JK |
1072 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
1073 | /* | |
1074 | * this can happen if clean_task is called on a task that | |
1075 | * failed in xmit_task or alloc_pdu. | |
1076 | */ | |
99bc5d55 JSJ |
1077 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
1078 | "BM_%d : Double Free in eh SGL ," | |
1079 | "eh_sgl_free_index=%d\n", | |
1080 | phba->eh_sgl_free_index); | |
10139fe0 | 1081 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
6733b39a JK |
1082 | return; |
1083 | } | |
1084 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; | |
1085 | phba->eh_sgl_hndl_avbl++; | |
1086 | if (phba->eh_sgl_free_index == | |
1087 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) | |
1088 | phba->eh_sgl_free_index = 0; | |
1089 | else | |
1090 | phba->eh_sgl_free_index++; | |
10139fe0 | 1091 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
6733b39a JK |
1092 | } |
1093 | ||
1094 | static void | |
1095 | be_complete_io(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1096 | struct iscsi_task *task, |
1097 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1098 | { |
1099 | struct beiscsi_io_task *io_task = task->dd_data; | |
1100 | struct be_status_bhs *sts_bhs = | |
1101 | (struct be_status_bhs *)io_task->cmd_bhs; | |
1102 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
6733b39a JK |
1103 | unsigned char *sense; |
1104 | u32 resid = 0, exp_cmdsn, max_cmdsn; | |
1105 | u8 rsp, status, flags; | |
1106 | ||
73133261 JSJ |
1107 | exp_cmdsn = csol_cqe->exp_cmdsn; |
1108 | max_cmdsn = (csol_cqe->exp_cmdsn + | |
1109 | csol_cqe->cmd_wnd - 1); | |
1110 | rsp = csol_cqe->i_resp; | |
1111 | status = csol_cqe->i_sts; | |
1112 | flags = csol_cqe->i_flags; | |
1113 | resid = csol_cqe->res_cnt; | |
1114 | ||
bd535451 | 1115 | if (!task->sc) { |
da334977 | 1116 | if (io_task->scsi_cmnd) { |
bd535451 | 1117 | scsi_dma_unmap(io_task->scsi_cmnd); |
da334977 JK |
1118 | io_task->scsi_cmnd = NULL; |
1119 | } | |
6733b39a | 1120 | |
bd535451 JK |
1121 | return; |
1122 | } | |
6733b39a JK |
1123 | task->sc->result = (DID_OK << 16) | status; |
1124 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { | |
1125 | task->sc->result = DID_ERROR << 16; | |
1126 | goto unmap; | |
1127 | } | |
1128 | ||
1129 | /* bidi not initially supported */ | |
1130 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { | |
6733b39a JK |
1131 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
1132 | task->sc->result = DID_ERROR << 16; | |
1133 | ||
1134 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { | |
1135 | scsi_set_resid(task->sc, resid); | |
1136 | if (!status && (scsi_bufflen(task->sc) - resid < | |
1137 | task->sc->underflow)) | |
1138 | task->sc->result = DID_ERROR << 16; | |
1139 | } | |
1140 | } | |
1141 | ||
1142 | if (status == SAM_STAT_CHECK_CONDITION) { | |
4053a4be | 1143 | u16 sense_len; |
bfead3b2 | 1144 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
4053a4be | 1145 | |
6733b39a | 1146 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
4053a4be | 1147 | sense_len = be16_to_cpu(*slen); |
6733b39a JK |
1148 | memcpy(task->sc->sense_buffer, sense, |
1149 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); | |
1150 | } | |
756d29c8 | 1151 | |
73133261 JSJ |
1152 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
1153 | conn->rxdata_octets += resid; | |
6733b39a | 1154 | unmap: |
eb1c4692 JSJ |
1155 | if (io_task->scsi_cmnd) { |
1156 | scsi_dma_unmap(io_task->scsi_cmnd); | |
1157 | io_task->scsi_cmnd = NULL; | |
1158 | } | |
6733b39a JK |
1159 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
1160 | } | |
1161 | ||
1162 | static void | |
1163 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1164 | struct iscsi_task *task, |
1165 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1166 | { |
1167 | struct iscsi_logout_rsp *hdr; | |
bfead3b2 | 1168 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1169 | struct iscsi_conn *conn = beiscsi_conn->conn; |
1170 | ||
1171 | hdr = (struct iscsi_logout_rsp *)task->hdr; | |
7bd6e25c | 1172 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
6733b39a JK |
1173 | hdr->t2wait = 5; |
1174 | hdr->t2retain = 0; | |
73133261 JSJ |
1175 | hdr->flags = csol_cqe->i_flags; |
1176 | hdr->response = csol_cqe->i_resp; | |
702dc5e8 JK |
1177 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
1178 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + | |
1179 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1180 | |
7bd6e25c JK |
1181 | hdr->dlength[0] = 0; |
1182 | hdr->dlength[1] = 0; | |
1183 | hdr->dlength[2] = 0; | |
6733b39a | 1184 | hdr->hlength = 0; |
bfead3b2 | 1185 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1186 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1187 | } | |
1188 | ||
1189 | static void | |
1190 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1191 | struct iscsi_task *task, |
1192 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1193 | { |
1194 | struct iscsi_tm_rsp *hdr; | |
1195 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
bfead3b2 | 1196 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1197 | |
1198 | hdr = (struct iscsi_tm_rsp *)task->hdr; | |
7bd6e25c | 1199 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
73133261 JSJ |
1200 | hdr->flags = csol_cqe->i_flags; |
1201 | hdr->response = csol_cqe->i_resp; | |
702dc5e8 JK |
1202 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
1203 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + | |
1204 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1205 | |
bfead3b2 | 1206 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1207 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1208 | } | |
1209 | ||
1210 | static void | |
1211 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, | |
1212 | struct beiscsi_hba *phba, struct sol_cqe *psol) | |
1213 | { | |
1214 | struct hwi_wrb_context *pwrb_context; | |
e1f9d31e | 1215 | uint16_t wrb_index, cid, cri_index; |
6733b39a | 1216 | struct hwi_controller *phwi_ctrlr; |
e1f9d31e | 1217 | struct wrb_handle *pwrb_handle; |
bfead3b2 | 1218 | struct iscsi_task *task; |
6733b39a JK |
1219 | |
1220 | phwi_ctrlr = phba->phwi_ctrlr; | |
2c9dfd36 JK |
1221 | if (is_chip_be2_be3r(phba)) { |
1222 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, | |
73133261 | 1223 | wrb_idx, psol); |
2c9dfd36 | 1224 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
73133261 JSJ |
1225 | cid, psol); |
1226 | } else { | |
2c9dfd36 | 1227 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
73133261 | 1228 | wrb_idx, psol); |
2c9dfd36 | 1229 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
73133261 JSJ |
1230 | cid, psol); |
1231 | } | |
1232 | ||
a7909b39 JK |
1233 | cri_index = BE_GET_CRI_FROM_CID(cid); |
1234 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; | |
73133261 | 1235 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
32951dd8 | 1236 | task = pwrb_handle->pio_handle; |
4a4a11b9 | 1237 | iscsi_put_task(task); |
6733b39a JK |
1238 | } |
1239 | ||
1240 | static void | |
1241 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, | |
73133261 JSJ |
1242 | struct iscsi_task *task, |
1243 | struct common_sol_cqe *csol_cqe) | |
6733b39a JK |
1244 | { |
1245 | struct iscsi_nopin *hdr; | |
1246 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
bfead3b2 | 1247 | struct beiscsi_io_task *io_task = task->dd_data; |
6733b39a JK |
1248 | |
1249 | hdr = (struct iscsi_nopin *)task->hdr; | |
73133261 JSJ |
1250 | hdr->flags = csol_cqe->i_flags; |
1251 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); | |
702dc5e8 JK |
1252 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
1253 | csol_cqe->cmd_wnd - 1); | |
73133261 | 1254 | |
6733b39a | 1255 | hdr->opcode = ISCSI_OP_NOOP_IN; |
bfead3b2 | 1256 | hdr->itt = io_task->libiscsi_itt; |
6733b39a JK |
1257 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
1258 | } | |
1259 | ||
73133261 JSJ |
1260 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
1261 | struct sol_cqe *psol, | |
1262 | struct common_sol_cqe *csol_cqe) | |
1263 | { | |
2c9dfd36 JK |
1264 | if (is_chip_be2_be3r(phba)) { |
1265 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, | |
1266 | i_exp_cmd_sn, psol); | |
1267 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, | |
1268 | i_res_cnt, psol); | |
1269 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, | |
1270 | i_cmd_wnd, psol); | |
1271 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, | |
1272 | wrb_index, psol); | |
1273 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, | |
1274 | cid, psol); | |
1275 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, | |
1276 | hw_sts, psol); | |
1277 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, | |
1278 | i_resp, psol); | |
1279 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, | |
1280 | i_sts, psol); | |
1281 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, | |
1282 | i_flags, psol); | |
1283 | } else { | |
73133261 JSJ |
1284 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
1285 | i_exp_cmd_sn, psol); | |
1286 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1287 | i_res_cnt, psol); | |
1288 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1289 | wrb_index, psol); | |
1290 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1291 | cid, psol); | |
1292 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1293 | hw_sts, psol); | |
702dc5e8 | 1294 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
73133261 JSJ |
1295 | i_cmd_wnd, psol); |
1296 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1297 | cmd_cmpl, psol)) | |
1298 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1299 | i_sts, psol); | |
1300 | else | |
1301 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1302 | i_sts, psol); | |
1303 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1304 | u, psol)) | |
1305 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; | |
1306 | ||
1307 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1308 | o, psol)) | |
1309 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; | |
73133261 JSJ |
1310 | } |
1311 | } | |
1312 | ||
1313 | ||
6733b39a JK |
1314 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
1315 | struct beiscsi_hba *phba, struct sol_cqe *psol) | |
1316 | { | |
1317 | struct hwi_wrb_context *pwrb_context; | |
1318 | struct wrb_handle *pwrb_handle; | |
1319 | struct iscsi_wrb *pwrb = NULL; | |
1320 | struct hwi_controller *phwi_ctrlr; | |
1321 | struct iscsi_task *task; | |
bfead3b2 | 1322 | unsigned int type; |
6733b39a JK |
1323 | struct iscsi_conn *conn = beiscsi_conn->conn; |
1324 | struct iscsi_session *session = conn->session; | |
73133261 | 1325 | struct common_sol_cqe csol_cqe = {0}; |
a7909b39 | 1326 | uint16_t cri_index = 0; |
6733b39a JK |
1327 | |
1328 | phwi_ctrlr = phba->phwi_ctrlr; | |
73133261 JSJ |
1329 | |
1330 | /* Copy the elements to a common structure */ | |
1331 | adapter_get_sol_cqe(phba, psol, &csol_cqe); | |
1332 | ||
a7909b39 JK |
1333 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
1334 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; | |
73133261 JSJ |
1335 | |
1336 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ | |
1337 | csol_cqe.wrb_index]; | |
1338 | ||
32951dd8 JK |
1339 | task = pwrb_handle->pio_handle; |
1340 | pwrb = pwrb_handle->pwrb; | |
73133261 | 1341 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
32951dd8 | 1342 | |
659743b0 | 1343 | spin_lock_bh(&session->back_lock); |
bfead3b2 | 1344 | switch (type) { |
6733b39a JK |
1345 | case HWH_TYPE_IO: |
1346 | case HWH_TYPE_IO_RD: | |
1347 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == | |
dafab8e0 | 1348 | ISCSI_OP_NOOP_OUT) |
73133261 | 1349 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
dafab8e0 | 1350 | else |
73133261 | 1351 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1352 | break; |
1353 | ||
1354 | case HWH_TYPE_LOGOUT: | |
dafab8e0 | 1355 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
73133261 | 1356 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
dafab8e0 | 1357 | else |
73133261 | 1358 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1359 | break; |
1360 | ||
1361 | case HWH_TYPE_LOGIN: | |
99bc5d55 JSJ |
1362 | beiscsi_log(phba, KERN_ERR, |
1363 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1364 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" | |
1365 | " hwi_complete_cmd- Solicited path\n"); | |
6733b39a JK |
1366 | break; |
1367 | ||
6733b39a | 1368 | case HWH_TYPE_NOP: |
73133261 | 1369 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
6733b39a JK |
1370 | break; |
1371 | ||
1372 | default: | |
99bc5d55 JSJ |
1373 | beiscsi_log(phba, KERN_WARNING, |
1374 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1375 | "BM_%d : In hwi_complete_cmd, unknown type = %d" | |
1376 | "wrb_index 0x%x CID 0x%x\n", type, | |
73133261 JSJ |
1377 | csol_cqe.wrb_index, |
1378 | csol_cqe.cid); | |
6733b39a JK |
1379 | break; |
1380 | } | |
35e66019 | 1381 | |
659743b0 | 1382 | spin_unlock_bh(&session->back_lock); |
6733b39a JK |
1383 | } |
1384 | ||
938f372c JB |
1385 | /** |
1386 | * ASYNC PDUs include | |
1387 | * a. Unsolicited NOP-In (target initiated NOP-In) | |
1388 | * b. ASYNC Messages | |
1389 | * c. Reject PDU | |
1390 | * d. Login response | |
1391 | * These headers arrive unprocessed by the EP firmware. | |
1392 | * iSCSI layer processes them. | |
1393 | */ | |
1394 | static unsigned int | |
1395 | beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn, | |
1396 | struct pdu_base *phdr, void *pdata, unsigned int dlen) | |
6733b39a | 1397 | { |
938f372c JB |
1398 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1399 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
1400 | struct beiscsi_io_task *io_task; | |
1401 | struct iscsi_hdr *login_hdr; | |
1402 | struct iscsi_task *task; | |
1403 | u8 code; | |
1404 | ||
1405 | code = AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr); | |
1406 | switch (code) { | |
1407 | case ISCSI_OP_NOOP_IN: | |
1408 | pdata = NULL; | |
1409 | dlen = 0; | |
1410 | break; | |
1411 | case ISCSI_OP_ASYNC_EVENT: | |
1412 | break; | |
1413 | case ISCSI_OP_REJECT: | |
1414 | WARN_ON(!pdata); | |
1415 | WARN_ON(!(dlen == 48)); | |
1416 | beiscsi_log(phba, KERN_ERR, | |
1417 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1418 | "BM_%d : In ISCSI_OP_REJECT\n"); | |
1419 | break; | |
1420 | case ISCSI_OP_LOGIN_RSP: | |
1421 | case ISCSI_OP_TEXT_RSP: | |
1422 | task = conn->login_task; | |
1423 | io_task = task->dd_data; | |
1424 | login_hdr = (struct iscsi_hdr *)phdr; | |
1425 | login_hdr->itt = io_task->libiscsi_itt; | |
1426 | break; | |
1427 | default: | |
1428 | beiscsi_log(phba, KERN_WARNING, | |
1429 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
1430 | "BM_%d : unrecognized async PDU opcode 0x%x\n", | |
1431 | code); | |
1432 | return 1; | |
1433 | } | |
1434 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)phdr, pdata, dlen); | |
1435 | return 0; | |
1436 | } | |
1437 | ||
1438 | static inline void | |
1439 | beiscsi_hdl_put_handle(struct hd_async_context *pasync_ctx, | |
1440 | struct hd_async_handle *pasync_handle) | |
1441 | { | |
1442 | if (pasync_handle->is_header) { | |
1443 | list_add_tail(&pasync_handle->link, | |
1444 | &pasync_ctx->async_header.free_list); | |
1445 | pasync_ctx->async_header.free_entries++; | |
1446 | } else { | |
1447 | list_add_tail(&pasync_handle->link, | |
1448 | &pasync_ctx->async_data.free_list); | |
1449 | pasync_ctx->async_data.free_entries++; | |
1450 | } | |
6733b39a JK |
1451 | } |
1452 | ||
938f372c JB |
1453 | static struct hd_async_handle * |
1454 | beiscsi_hdl_get_handle(struct beiscsi_conn *beiscsi_conn, | |
1455 | struct hd_async_context *pasync_ctx, | |
1456 | struct i_t_dpdu_cqe *pdpdu_cqe) | |
6733b39a | 1457 | { |
938f372c JB |
1458 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1459 | struct hd_async_handle *pasync_handle; | |
6733b39a | 1460 | struct be_bus_address phys_addr; |
938f372c JB |
1461 | u8 final, error = 0; |
1462 | u16 cid, code, ci; | |
1463 | u32 dpl; | |
73133261 | 1464 | |
938f372c JB |
1465 | cid = beiscsi_conn->beiscsi_conn_cid; |
1466 | /** | |
1467 | * This function is invoked to get the right async_handle structure | |
1468 | * from a given DEF PDU CQ entry. | |
1469 | * | |
1470 | * - index in CQ entry gives the vertical index | |
1471 | * - address in CQ entry is the offset where the DMA last ended | |
1472 | * - final - no more notifications for this PDU | |
1473 | */ | |
2c9dfd36 JK |
1474 | if (is_chip_be2_be3r(phba)) { |
1475 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
73133261 | 1476 | dpl, pdpdu_cqe); |
938f372c | 1477 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
73133261 | 1478 | index, pdpdu_cqe); |
938f372c JB |
1479 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
1480 | final, pdpdu_cqe); | |
73133261 | 1481 | } else { |
2c9dfd36 | 1482 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
73133261 | 1483 | dpl, pdpdu_cqe); |
938f372c | 1484 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
73133261 | 1485 | index, pdpdu_cqe); |
938f372c JB |
1486 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
1487 | final, pdpdu_cqe); | |
73133261 | 1488 | } |
6733b39a | 1489 | |
938f372c JB |
1490 | /** |
1491 | * DB addr Hi/Lo is same for BE and SKH. | |
1492 | * Subtract the dataplacementlength to get to the base. | |
1493 | */ | |
1494 | phys_addr.u.a32.address_lo = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
1495 | db_addr_lo, pdpdu_cqe); | |
1496 | phys_addr.u.a32.address_lo -= dpl; | |
1497 | phys_addr.u.a32.address_hi = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, | |
1498 | db_addr_hi, pdpdu_cqe); | |
1499 | ||
1500 | code = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, code, pdpdu_cqe); | |
1501 | switch (code) { | |
6733b39a | 1502 | case UNSOL_HDR_NOTIFY: |
938f372c | 1503 | pasync_handle = pasync_ctx->async_entry[ci].header; |
6733b39a | 1504 | break; |
938f372c JB |
1505 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
1506 | error = 1; | |
6733b39a | 1507 | case UNSOL_DATA_NOTIFY: |
938f372c | 1508 | pasync_handle = pasync_ctx->async_entry[ci].data; |
6733b39a | 1509 | break; |
938f372c | 1510 | /* called only for above codes */ |
6733b39a | 1511 | default: |
938f372c JB |
1512 | pasync_handle = NULL; |
1513 | break; | |
6733b39a JK |
1514 | } |
1515 | ||
938f372c JB |
1516 | if (!pasync_handle) { |
1517 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1518 | "BM_%d : cid %d async PDU handle not found - code %d ci %d addr %llx\n", | |
1519 | cid, code, ci, phys_addr.u.a64.address); | |
1520 | return pasync_handle; | |
6733b39a JK |
1521 | } |
1522 | ||
938f372c JB |
1523 | if (pasync_handle->pa.u.a64.address != phys_addr.u.a64.address || |
1524 | pasync_handle->index != ci) { | |
1525 | /* driver bug - if ci does not match async handle index */ | |
1526 | error = 1; | |
1527 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1528 | "BM_%d : cid %u async PDU handle mismatch - addr in %cQE %llx at %u:addr in CQE %llx ci %u\n", | |
1529 | cid, pasync_handle->is_header ? 'H' : 'D', | |
1530 | pasync_handle->pa.u.a64.address, | |
1531 | pasync_handle->index, | |
1532 | phys_addr.u.a64.address, ci); | |
1533 | /* FW has stale address - attempt continuing by dropping */ | |
1534 | } | |
6733b39a | 1535 | |
938f372c JB |
1536 | /** |
1537 | * Each CID is associated with unique CRI. | |
1538 | * ASYNC_CRI_FROM_CID mapping and CRI_FROM_CID are totaly different. | |
1539 | **/ | |
1540 | pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(cid); | |
1541 | pasync_handle->is_final = final; | |
73133261 | 1542 | pasync_handle->buffer_len = dpl; |
938f372c JB |
1543 | /* empty the slot */ |
1544 | if (pasync_handle->is_header) | |
1545 | pasync_ctx->async_entry[ci].header = NULL; | |
1546 | else | |
1547 | pasync_ctx->async_entry[ci].data = NULL; | |
6733b39a | 1548 | |
938f372c JB |
1549 | /** |
1550 | * DEF PDU header and data buffers with errors should be simply | |
1551 | * dropped as there are no consumers for it. | |
1552 | */ | |
1553 | if (error) { | |
1554 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
1555 | pasync_handle = NULL; | |
1556 | } | |
6733b39a JK |
1557 | return pasync_handle; |
1558 | } | |
1559 | ||
938f372c JB |
1560 | static void |
1561 | beiscsi_hdl_purge_handles(struct beiscsi_hba *phba, | |
1562 | struct hd_async_context *pasync_ctx, | |
1563 | u16 cri) | |
6733b39a | 1564 | { |
938f372c JB |
1565 | struct hd_async_handle *pasync_handle, *tmp_handle; |
1566 | struct list_head *plist; | |
6733b39a | 1567 | |
938f372c JB |
1568 | plist = &pasync_ctx->async_entry[cri].wq.list; |
1569 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) { | |
1570 | list_del(&pasync_handle->link); | |
1571 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
6733b39a JK |
1572 | } |
1573 | ||
938f372c JB |
1574 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wq.list); |
1575 | pasync_ctx->async_entry[cri].wq.hdr_len = 0; | |
1576 | pasync_ctx->async_entry[cri].wq.bytes_received = 0; | |
1577 | pasync_ctx->async_entry[cri].wq.bytes_needed = 0; | |
6733b39a JK |
1578 | } |
1579 | ||
938f372c JB |
1580 | static unsigned int |
1581 | beiscsi_hdl_fwd_pdu(struct beiscsi_conn *beiscsi_conn, | |
1582 | struct hd_async_context *pasync_ctx, | |
1583 | u16 cri) | |
6733b39a | 1584 | { |
938f372c JB |
1585 | struct iscsi_session *session = beiscsi_conn->conn->session; |
1586 | struct hd_async_handle *pasync_handle, *plast_handle; | |
1587 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
1588 | void *phdr = NULL, *pdata = NULL; | |
1589 | u32 dlen = 0, status = 0; | |
6733b39a | 1590 | struct list_head *plist; |
6733b39a | 1591 | |
938f372c JB |
1592 | plist = &pasync_ctx->async_entry[cri].wq.list; |
1593 | plast_handle = NULL; | |
1594 | list_for_each_entry(pasync_handle, plist, link) { | |
1595 | plast_handle = pasync_handle; | |
1596 | /* get the header, the first entry */ | |
1597 | if (!phdr) { | |
1598 | phdr = pasync_handle->pbuffer; | |
1599 | continue; | |
6733b39a | 1600 | } |
938f372c JB |
1601 | /* use first buffer to collect all the data */ |
1602 | if (!pdata) { | |
1603 | pdata = pasync_handle->pbuffer; | |
1604 | dlen = pasync_handle->buffer_len; | |
1605 | continue; | |
1606 | } | |
1607 | memcpy(pdata + dlen, pasync_handle->pbuffer, | |
1608 | pasync_handle->buffer_len); | |
1609 | dlen += pasync_handle->buffer_len; | |
6733b39a JK |
1610 | } |
1611 | ||
938f372c JB |
1612 | if (!plast_handle->is_final) { |
1613 | /* last handle should have final PDU notification from FW */ | |
1614 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1615 | "BM_%d : cid %u %p fwd async PDU with last handle missing - HL%u:DN%u:DR%u\n", | |
1616 | beiscsi_conn->beiscsi_conn_cid, plast_handle, | |
1617 | pasync_ctx->async_entry[cri].wq.hdr_len, | |
1618 | pasync_ctx->async_entry[cri].wq.bytes_needed, | |
1619 | pasync_ctx->async_entry[cri].wq.bytes_received); | |
1620 | } | |
1621 | spin_lock_bh(&session->back_lock); | |
1622 | status = beiscsi_complete_pdu(beiscsi_conn, phdr, pdata, dlen); | |
1623 | spin_unlock_bh(&session->back_lock); | |
1624 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); | |
1625 | return status; | |
6733b39a JK |
1626 | } |
1627 | ||
938f372c JB |
1628 | static unsigned int |
1629 | beiscsi_hdl_gather_pdu(struct beiscsi_conn *beiscsi_conn, | |
1630 | struct hd_async_context *pasync_ctx, | |
1631 | struct hd_async_handle *pasync_handle) | |
6733b39a | 1632 | { |
938f372c JB |
1633 | unsigned int bytes_needed = 0, status = 0; |
1634 | u16 cri = pasync_handle->cri; | |
1635 | struct cri_wait_queue *wq; | |
1636 | struct beiscsi_hba *phba; | |
1637 | struct pdu_base *ppdu; | |
1638 | char *err = ""; | |
6733b39a | 1639 | |
938f372c JB |
1640 | phba = beiscsi_conn->phba; |
1641 | wq = &pasync_ctx->async_entry[cri].wq; | |
1642 | if (pasync_handle->is_header) { | |
1643 | /* check if PDU hdr is rcv'd when old hdr not completed */ | |
1644 | if (wq->hdr_len) { | |
1645 | err = "incomplete"; | |
1646 | goto drop_pdu; | |
1647 | } | |
1648 | ppdu = pasync_handle->pbuffer; | |
1649 | bytes_needed = AMAP_GET_BITS(struct amap_pdu_base, | |
1650 | data_len_hi, ppdu); | |
1651 | bytes_needed <<= 16; | |
1652 | bytes_needed |= be16_to_cpu(AMAP_GET_BITS(struct amap_pdu_base, | |
1653 | data_len_lo, ppdu)); | |
1654 | wq->hdr_len = pasync_handle->buffer_len; | |
1655 | wq->bytes_received = 0; | |
1656 | wq->bytes_needed = bytes_needed; | |
1657 | list_add_tail(&pasync_handle->link, &wq->list); | |
1658 | if (!bytes_needed) | |
1659 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, | |
1660 | pasync_ctx, cri); | |
1661 | } else { | |
1662 | /* check if data received has header and is needed */ | |
1663 | if (!wq->hdr_len || !wq->bytes_needed) { | |
1664 | err = "header less"; | |
1665 | goto drop_pdu; | |
1666 | } | |
1667 | wq->bytes_received += pasync_handle->buffer_len; | |
1668 | /* Something got overwritten? Better catch it here. */ | |
1669 | if (wq->bytes_received > wq->bytes_needed) { | |
1670 | err = "overflow"; | |
1671 | goto drop_pdu; | |
1672 | } | |
1673 | list_add_tail(&pasync_handle->link, &wq->list); | |
1674 | if (wq->bytes_received == wq->bytes_needed) | |
1675 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, | |
1676 | pasync_ctx, cri); | |
1677 | } | |
1678 | return status; | |
6733b39a | 1679 | |
938f372c JB |
1680 | drop_pdu: |
1681 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1682 | "BM_%d : cid %u async PDU %s - def-%c:HL%u:DN%u:DR%u\n", | |
1683 | beiscsi_conn->beiscsi_conn_cid, err, | |
1684 | pasync_handle->is_header ? 'H' : 'D', | |
1685 | wq->hdr_len, wq->bytes_needed, | |
1686 | pasync_handle->buffer_len); | |
1687 | /* discard this handle */ | |
1688 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); | |
1689 | /* free all the other handles in cri_wait_queue */ | |
1690 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); | |
1691 | /* try continuing */ | |
1692 | return status; | |
6733b39a JK |
1693 | } |
1694 | ||
938f372c JB |
1695 | static void |
1696 | beiscsi_hdq_post_handles(struct beiscsi_hba *phba, | |
1697 | u8 header, u8 ulp_num) | |
6733b39a | 1698 | { |
938f372c JB |
1699 | struct hd_async_handle *pasync_handle, *tmp, **slot; |
1700 | struct hd_async_context *pasync_ctx; | |
6733b39a | 1701 | struct hwi_controller *phwi_ctrlr; |
938f372c | 1702 | struct list_head *hfree_list; |
6733b39a | 1703 | struct phys_addr *pasync_sge; |
938f372c JB |
1704 | u32 ring_id, doorbell = 0; |
1705 | u16 index, num_entries; | |
1706 | u32 doorbell_offset; | |
1707 | u16 prod = 0, cons; | |
6733b39a JK |
1708 | |
1709 | phwi_ctrlr = phba->phwi_ctrlr; | |
8a86e833 | 1710 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
dc63aac6 | 1711 | num_entries = pasync_ctx->num_entries; |
938f372c JB |
1712 | if (header) { |
1713 | cons = pasync_ctx->async_header.free_entries; | |
1714 | hfree_list = &pasync_ctx->async_header.free_list; | |
8a86e833 JK |
1715 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
1716 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. | |
938f372c | 1717 | doorbell_offset; |
6733b39a | 1718 | } else { |
938f372c JB |
1719 | cons = pasync_ctx->async_data.free_entries; |
1720 | hfree_list = &pasync_ctx->async_data.free_list; | |
8a86e833 JK |
1721 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
1722 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. | |
938f372c | 1723 | doorbell_offset; |
6733b39a | 1724 | } |
938f372c JB |
1725 | /* number of entries posted must be in multiples of 8 */ |
1726 | if (cons % 8) | |
1727 | return; | |
6733b39a | 1728 | |
938f372c JB |
1729 | list_for_each_entry_safe(pasync_handle, tmp, hfree_list, link) { |
1730 | list_del_init(&pasync_handle->link); | |
1731 | pasync_handle->is_final = 0; | |
1732 | pasync_handle->buffer_len = 0; | |
6733b39a | 1733 | |
938f372c JB |
1734 | /* handles can be consumed out of order, use index in handle */ |
1735 | index = pasync_handle->index; | |
1736 | WARN_ON(pasync_handle->is_header != header); | |
1737 | if (header) | |
1738 | slot = &pasync_ctx->async_entry[index].header; | |
1739 | else | |
1740 | slot = &pasync_ctx->async_entry[index].data; | |
1741 | /** | |
1742 | * The slot just tracks handle's hold and release, so | |
1743 | * overwriting at the same index won't do any harm but | |
1744 | * needs to be caught. | |
1745 | */ | |
1746 | if (*slot != NULL) { | |
1747 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, | |
1748 | "BM_%d : async PDU %s slot at %u not empty\n", | |
1749 | header ? "header" : "data", index); | |
6733b39a | 1750 | } |
938f372c JB |
1751 | /** |
1752 | * We use same freed index as in completion to post so this | |
1753 | * operation is not required for refills. Its required only | |
1754 | * for ring creation. | |
1755 | */ | |
1756 | if (header) | |
1757 | pasync_sge = pasync_ctx->async_header.ring_base; | |
1758 | else | |
1759 | pasync_sge = pasync_ctx->async_data.ring_base; | |
1760 | pasync_sge += index; | |
1761 | /* if its a refill then address is same; hi is lo */ | |
1762 | WARN_ON(pasync_sge->hi && | |
1763 | pasync_sge->hi != pasync_handle->pa.u.a32.address_lo); | |
1764 | WARN_ON(pasync_sge->lo && | |
1765 | pasync_sge->lo != pasync_handle->pa.u.a32.address_hi); | |
1766 | pasync_sge->hi = pasync_handle->pa.u.a32.address_lo; | |
1767 | pasync_sge->lo = pasync_handle->pa.u.a32.address_hi; | |
1768 | ||
1769 | *slot = pasync_handle; | |
1770 | if (++prod == cons) | |
1771 | break; | |
6733b39a | 1772 | } |
938f372c JB |
1773 | if (header) |
1774 | pasync_ctx->async_header.free_entries -= prod; | |
1775 | else | |
1776 | pasync_ctx->async_data.free_entries -= prod; | |
6733b39a | 1777 | |
938f372c JB |
1778 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
1779 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; | |
1780 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; | |
1781 | doorbell |= (prod & DB_DEF_PDU_CQPROC_MASK) << DB_DEF_PDU_CQPROC_SHIFT; | |
1782 | iowrite32(doorbell, phba->db_va + doorbell_offset); | |
6733b39a JK |
1783 | } |
1784 | ||
938f372c JB |
1785 | static void |
1786 | beiscsi_hdq_process_compl(struct beiscsi_conn *beiscsi_conn, | |
1787 | struct i_t_dpdu_cqe *pdpdu_cqe) | |
6733b39a | 1788 | { |
938f372c JB |
1789 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
1790 | struct hd_async_handle *pasync_handle = NULL; | |
1791 | struct hd_async_context *pasync_ctx; | |
6733b39a | 1792 | struct hwi_controller *phwi_ctrlr; |
938f372c JB |
1793 | u16 cid_cri; |
1794 | u8 ulp_num; | |
6733b39a JK |
1795 | |
1796 | phwi_ctrlr = phba->phwi_ctrlr; | |
938f372c JB |
1797 | cid_cri = BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid); |
1798 | ulp_num = BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cid_cri); | |
1799 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); | |
1800 | pasync_handle = beiscsi_hdl_get_handle(beiscsi_conn, pasync_ctx, | |
1801 | pdpdu_cqe); | |
1802 | if (!pasync_handle) | |
1803 | return; | |
99bc5d55 | 1804 | |
938f372c JB |
1805 | beiscsi_hdl_gather_pdu(beiscsi_conn, pasync_ctx, pasync_handle); |
1806 | beiscsi_hdq_post_handles(phba, pasync_handle->is_header, ulp_num); | |
6733b39a JK |
1807 | } |
1808 | ||
2e4e8f65 | 1809 | void beiscsi_process_mcc_cq(struct beiscsi_hba *phba) |
756d29c8 JK |
1810 | { |
1811 | struct be_queue_info *mcc_cq; | |
1812 | struct be_mcc_compl *mcc_compl; | |
1813 | unsigned int num_processed = 0; | |
1814 | ||
1815 | mcc_cq = &phba->ctrl.mcc_obj.cq; | |
1816 | mcc_compl = queue_tail_node(mcc_cq); | |
1817 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); | |
1818 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { | |
9122e991 JB |
1819 | if (beiscsi_hba_in_error(phba)) |
1820 | return; | |
1821 | ||
756d29c8 JK |
1822 | if (num_processed >= 32) { |
1823 | hwi_ring_cq_db(phba, mcc_cq->id, | |
1094cf68 | 1824 | num_processed, 0); |
756d29c8 JK |
1825 | num_processed = 0; |
1826 | } | |
1827 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { | |
53aefe25 | 1828 | beiscsi_process_async_event(phba, mcc_compl); |
756d29c8 | 1829 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
2e4e8f65 | 1830 | beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl); |
756d29c8 JK |
1831 | } |
1832 | ||
1833 | mcc_compl->flags = 0; | |
1834 | queue_tail_inc(mcc_cq); | |
1835 | mcc_compl = queue_tail_node(mcc_cq); | |
1836 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); | |
1837 | num_processed++; | |
1838 | } | |
1839 | ||
1840 | if (num_processed > 0) | |
1094cf68 | 1841 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
756d29c8 | 1842 | } |
bfead3b2 | 1843 | |
a3095016 JB |
1844 | static void beiscsi_mcc_work(struct work_struct *work) |
1845 | { | |
1846 | struct be_eq_obj *pbe_eq; | |
1847 | struct beiscsi_hba *phba; | |
1848 | ||
1849 | pbe_eq = container_of(work, struct be_eq_obj, mcc_work); | |
1850 | phba = pbe_eq->phba; | |
1851 | beiscsi_process_mcc_cq(phba); | |
1852 | /* rearm EQ for further interrupts */ | |
9122e991 JB |
1853 | if (!beiscsi_hba_in_error(phba)) |
1854 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); | |
a3095016 JB |
1855 | } |
1856 | ||
6763daae JSJ |
1857 | /** |
1858 | * beiscsi_process_cq()- Process the Completion Queue | |
1859 | * @pbe_eq: Event Q on which the Completion has come | |
1094cf68 | 1860 | * @budget: Max number of events to processed |
6763daae JSJ |
1861 | * |
1862 | * return | |
1863 | * Number of Completion Entries processed. | |
1864 | **/ | |
1094cf68 | 1865 | unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget) |
6733b39a | 1866 | { |
6733b39a JK |
1867 | struct be_queue_info *cq; |
1868 | struct sol_cqe *sol; | |
1869 | struct dmsg_cqe *dmsg; | |
1094cf68 | 1870 | unsigned int total = 0; |
6733b39a | 1871 | unsigned int num_processed = 0; |
0a513dd8 | 1872 | unsigned short code = 0, cid = 0; |
a7909b39 | 1873 | uint16_t cri_index = 0; |
6733b39a | 1874 | struct beiscsi_conn *beiscsi_conn; |
c2462288 JK |
1875 | struct beiscsi_endpoint *beiscsi_ep; |
1876 | struct iscsi_endpoint *ep; | |
bfead3b2 | 1877 | struct beiscsi_hba *phba; |
6733b39a | 1878 | |
bfead3b2 | 1879 | cq = pbe_eq->cq; |
6733b39a | 1880 | sol = queue_tail_node(cq); |
bfead3b2 | 1881 | phba = pbe_eq->phba; |
6733b39a JK |
1882 | |
1883 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & | |
1884 | CQE_VALID_MASK) { | |
9122e991 JB |
1885 | if (beiscsi_hba_in_error(phba)) |
1886 | return 0; | |
1887 | ||
6733b39a JK |
1888 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
1889 | ||
73133261 JSJ |
1890 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / |
1891 | 32] & CQE_CODE_MASK); | |
1892 | ||
1893 | /* Get the CID */ | |
2c9dfd36 JK |
1894 | if (is_chip_be2_be3r(phba)) { |
1895 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); | |
1896 | } else { | |
73133261 JSJ |
1897 | if ((code == DRIVERMSG_NOTIFY) || |
1898 | (code == UNSOL_HDR_NOTIFY) || | |
1899 | (code == UNSOL_DATA_NOTIFY)) | |
1900 | cid = AMAP_GET_BITS( | |
1901 | struct amap_i_t_dpdu_cqe_v2, | |
1902 | cid, sol); | |
1903 | else | |
1904 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, | |
1905 | cid, sol); | |
2c9dfd36 | 1906 | } |
32951dd8 | 1907 | |
a7909b39 JK |
1908 | cri_index = BE_GET_CRI_FROM_CID(cid); |
1909 | ep = phba->ep_array[cri_index]; | |
b7ab35b1 JK |
1910 | |
1911 | if (ep == NULL) { | |
1912 | /* connection has already been freed | |
1913 | * just move on to next one | |
1914 | */ | |
1915 | beiscsi_log(phba, KERN_WARNING, | |
1916 | BEISCSI_LOG_INIT, | |
1917 | "BM_%d : proc cqe of disconn ep: cid %d\n", | |
1918 | cid); | |
1919 | goto proc_next_cqe; | |
1920 | } | |
1921 | ||
c2462288 JK |
1922 | beiscsi_ep = ep->dd_data; |
1923 | beiscsi_conn = beiscsi_ep->conn; | |
756d29c8 | 1924 | |
1094cf68 JB |
1925 | /* replenish cq */ |
1926 | if (num_processed == 32) { | |
1927 | hwi_ring_cq_db(phba, cq->id, 32, 0); | |
6733b39a JK |
1928 | num_processed = 0; |
1929 | } | |
1094cf68 | 1930 | total++; |
6733b39a | 1931 | |
0a513dd8 | 1932 | switch (code) { |
6733b39a JK |
1933 | case SOL_CMD_COMPLETE: |
1934 | hwi_complete_cmd(beiscsi_conn, phba, sol); | |
1935 | break; | |
1936 | case DRIVERMSG_NOTIFY: | |
99bc5d55 JSJ |
1937 | beiscsi_log(phba, KERN_INFO, |
1938 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1939 | "BM_%d : Received %s[%d] on CID : %d\n", |
1940 | cqe_desc[code], code, cid); | |
99bc5d55 | 1941 | |
6733b39a JK |
1942 | dmsg = (struct dmsg_cqe *)sol; |
1943 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); | |
1944 | break; | |
1945 | case UNSOL_HDR_NOTIFY: | |
99bc5d55 JSJ |
1946 | beiscsi_log(phba, KERN_INFO, |
1947 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1948 | "BM_%d : Received %s[%d] on CID : %d\n", |
1949 | cqe_desc[code], code, cid); | |
99bc5d55 | 1950 | |
8f09a3b9 | 1951 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
1952 | beiscsi_hdq_process_compl(beiscsi_conn, |
1953 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 1954 | spin_unlock_bh(&phba->async_pdu_lock); |
bfead3b2 | 1955 | break; |
6733b39a | 1956 | case UNSOL_DATA_NOTIFY: |
99bc5d55 JSJ |
1957 | beiscsi_log(phba, KERN_INFO, |
1958 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
6763daae JSJ |
1959 | "BM_%d : Received %s[%d] on CID : %d\n", |
1960 | cqe_desc[code], code, cid); | |
99bc5d55 | 1961 | |
8f09a3b9 | 1962 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
1963 | beiscsi_hdq_process_compl(beiscsi_conn, |
1964 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 1965 | spin_unlock_bh(&phba->async_pdu_lock); |
6733b39a JK |
1966 | break; |
1967 | case CXN_INVALIDATE_INDEX_NOTIFY: | |
1968 | case CMD_INVALIDATED_NOTIFY: | |
1969 | case CXN_INVALIDATE_NOTIFY: | |
99bc5d55 JSJ |
1970 | beiscsi_log(phba, KERN_ERR, |
1971 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1972 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
1973 | cqe_desc[code], code, cid); | |
6733b39a | 1974 | break; |
1094cf68 | 1975 | case CXN_KILLED_HDR_DIGEST_ERR: |
6733b39a | 1976 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
1094cf68 JB |
1977 | beiscsi_log(phba, KERN_ERR, |
1978 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1979 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", | |
1980 | cqe_desc[code], code, cid); | |
1981 | break; | |
6733b39a JK |
1982 | case CMD_KILLED_INVALID_STATSN_RCVD: |
1983 | case CMD_KILLED_INVALID_R2T_RCVD: | |
1984 | case CMD_CXN_KILLED_LUN_INVALID: | |
1985 | case CMD_CXN_KILLED_ICD_INVALID: | |
1986 | case CMD_CXN_KILLED_ITT_INVALID: | |
1987 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: | |
1988 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: | |
99bc5d55 JSJ |
1989 | beiscsi_log(phba, KERN_ERR, |
1990 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
6763daae JSJ |
1991 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
1992 | cqe_desc[code], code, cid); | |
6733b39a JK |
1993 | break; |
1994 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: | |
99bc5d55 JSJ |
1995 | beiscsi_log(phba, KERN_ERR, |
1996 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
1997 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
1998 | cqe_desc[code], code, cid); | |
8f09a3b9 | 1999 | spin_lock_bh(&phba->async_pdu_lock); |
938f372c JB |
2000 | /* driver consumes the entry and drops the contents */ |
2001 | beiscsi_hdq_process_compl(beiscsi_conn, | |
2002 | (struct i_t_dpdu_cqe *)sol); | |
8f09a3b9 | 2003 | spin_unlock_bh(&phba->async_pdu_lock); |
6733b39a JK |
2004 | break; |
2005 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: | |
2006 | case CXN_KILLED_BURST_LEN_MISMATCH: | |
2007 | case CXN_KILLED_AHS_RCVD: | |
6733b39a JK |
2008 | case CXN_KILLED_UNKNOWN_HDR: |
2009 | case CXN_KILLED_STALE_ITT_TTT_RCVD: | |
2010 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: | |
2011 | case CXN_KILLED_TIMED_OUT: | |
2012 | case CXN_KILLED_FIN_RCVD: | |
6763daae JSJ |
2013 | case CXN_KILLED_RST_SENT: |
2014 | case CXN_KILLED_RST_RCVD: | |
6733b39a JK |
2015 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
2016 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: | |
2017 | case CXN_KILLED_OVER_RUN_RESIDUAL: | |
2018 | case CXN_KILLED_UNDER_RUN_RESIDUAL: | |
2019 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: | |
99bc5d55 JSJ |
2020 | beiscsi_log(phba, KERN_ERR, |
2021 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
2022 | "BM_%d : Event %s[%d] received on CID : %d\n", |
2023 | cqe_desc[code], code, cid); | |
0a513dd8 JSJ |
2024 | if (beiscsi_conn) |
2025 | iscsi_conn_failure(beiscsi_conn->conn, | |
2026 | ISCSI_ERR_CONN_FAILED); | |
6733b39a JK |
2027 | break; |
2028 | default: | |
99bc5d55 JSJ |
2029 | beiscsi_log(phba, KERN_ERR, |
2030 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, | |
6763daae JSJ |
2031 | "BM_%d : Invalid CQE Event Received Code : %d" |
2032 | "CID 0x%x...\n", | |
0a513dd8 | 2033 | code, cid); |
6733b39a JK |
2034 | break; |
2035 | } | |
2036 | ||
b7ab35b1 | 2037 | proc_next_cqe: |
6733b39a JK |
2038 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
2039 | queue_tail_inc(cq); | |
2040 | sol = queue_tail_node(cq); | |
2041 | num_processed++; | |
1094cf68 JB |
2042 | if (total == budget) |
2043 | break; | |
6733b39a JK |
2044 | } |
2045 | ||
1094cf68 JB |
2046 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
2047 | return total; | |
6733b39a JK |
2048 | } |
2049 | ||
511cbce2 | 2050 | static int be_iopoll(struct irq_poll *iop, int budget) |
6733b39a | 2051 | { |
a3095016 | 2052 | unsigned int ret, io_events; |
6733b39a | 2053 | struct beiscsi_hba *phba; |
bfead3b2 | 2054 | struct be_eq_obj *pbe_eq; |
1094cf68 JB |
2055 | struct be_eq_entry *eqe = NULL; |
2056 | struct be_queue_info *eq; | |
6733b39a | 2057 | |
bfead3b2 | 2058 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
1094cf68 | 2059 | phba = pbe_eq->phba; |
9122e991 JB |
2060 | if (beiscsi_hba_in_error(phba)) { |
2061 | irq_poll_complete(iop); | |
2062 | return 0; | |
2063 | } | |
2064 | ||
2065 | io_events = 0; | |
1094cf68 JB |
2066 | eq = &pbe_eq->q; |
2067 | eqe = queue_tail_node(eq); | |
1094cf68 JB |
2068 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
2069 | EQE_VALID_MASK) { | |
2070 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); | |
2071 | queue_tail_inc(eq); | |
2072 | eqe = queue_tail_node(eq); | |
a3095016 | 2073 | io_events++; |
1094cf68 | 2074 | } |
a3095016 | 2075 | hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1); |
1094cf68 JB |
2076 | |
2077 | ret = beiscsi_process_cq(pbe_eq, budget); | |
73af08e1 | 2078 | pbe_eq->cq_count += ret; |
6733b39a | 2079 | if (ret < budget) { |
511cbce2 | 2080 | irq_poll_complete(iop); |
99bc5d55 JSJ |
2081 | beiscsi_log(phba, KERN_INFO, |
2082 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, | |
1094cf68 JB |
2083 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
2084 | pbe_eq->q.id, ret); | |
9122e991 JB |
2085 | if (!beiscsi_hba_in_error(phba)) |
2086 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); | |
6733b39a JK |
2087 | } |
2088 | return ret; | |
2089 | } | |
2090 | ||
09a1093a JSJ |
2091 | static void |
2092 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, | |
2093 | unsigned int num_sg, struct beiscsi_io_task *io_task) | |
2094 | { | |
2095 | struct iscsi_sge *psgl; | |
2096 | unsigned int sg_len, index; | |
2097 | unsigned int sge_len = 0; | |
2098 | unsigned long long addr; | |
2099 | struct scatterlist *l_sg; | |
2100 | unsigned int offset; | |
2101 | ||
2102 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, | |
2103 | io_task->bhs_pa.u.a32.address_lo); | |
2104 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, | |
2105 | io_task->bhs_pa.u.a32.address_hi); | |
2106 | ||
2107 | l_sg = sg; | |
2108 | for (index = 0; (index < num_sg) && (index < 2); index++, | |
2109 | sg = sg_next(sg)) { | |
2110 | if (index == 0) { | |
2111 | sg_len = sg_dma_len(sg); | |
2112 | addr = (u64) sg_dma_address(sg); | |
2113 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2114 | sge0_addr_lo, pwrb, | |
2115 | lower_32_bits(addr)); | |
2116 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2117 | sge0_addr_hi, pwrb, | |
2118 | upper_32_bits(addr)); | |
2119 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2120 | sge0_len, pwrb, | |
2121 | sg_len); | |
2122 | sge_len = sg_len; | |
2123 | } else { | |
2124 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, | |
2125 | pwrb, sge_len); | |
2126 | sg_len = sg_dma_len(sg); | |
2127 | addr = (u64) sg_dma_address(sg); | |
2128 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2129 | sge1_addr_lo, pwrb, | |
2130 | lower_32_bits(addr)); | |
2131 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2132 | sge1_addr_hi, pwrb, | |
2133 | upper_32_bits(addr)); | |
2134 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, | |
2135 | sge1_len, pwrb, | |
2136 | sg_len); | |
2137 | } | |
2138 | } | |
2139 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2140 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); | |
2141 | ||
2142 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); | |
2143 | ||
2144 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2145 | io_task->bhs_pa.u.a32.address_hi); | |
2146 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2147 | io_task->bhs_pa.u.a32.address_lo); | |
2148 | ||
2149 | if (num_sg == 1) { | |
2150 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2151 | 1); | |
2152 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2153 | 0); | |
2154 | } else if (num_sg == 2) { | |
2155 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2156 | 0); | |
2157 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2158 | 1); | |
2159 | } else { | |
2160 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, | |
2161 | 0); | |
2162 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, | |
2163 | 0); | |
2164 | } | |
2165 | ||
2166 | sg = l_sg; | |
2167 | psgl++; | |
2168 | psgl++; | |
2169 | offset = 0; | |
2170 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { | |
2171 | sg_len = sg_dma_len(sg); | |
2172 | addr = (u64) sg_dma_address(sg); | |
2173 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2174 | lower_32_bits(addr)); | |
2175 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2176 | upper_32_bits(addr)); | |
2177 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); | |
2178 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); | |
2179 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2180 | offset += sg_len; | |
2181 | } | |
2182 | psgl--; | |
2183 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
2184 | } | |
2185 | ||
6733b39a JK |
2186 | static void |
2187 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, | |
2188 | unsigned int num_sg, struct beiscsi_io_task *io_task) | |
2189 | { | |
2190 | struct iscsi_sge *psgl; | |
58ff4bd0 | 2191 | unsigned int sg_len, index; |
6733b39a JK |
2192 | unsigned int sge_len = 0; |
2193 | unsigned long long addr; | |
2194 | struct scatterlist *l_sg; | |
2195 | unsigned int offset; | |
2196 | ||
2197 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, | |
2198 | io_task->bhs_pa.u.a32.address_lo); | |
2199 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, | |
2200 | io_task->bhs_pa.u.a32.address_hi); | |
2201 | ||
2202 | l_sg = sg; | |
48bd86cf JK |
2203 | for (index = 0; (index < num_sg) && (index < 2); index++, |
2204 | sg = sg_next(sg)) { | |
6733b39a JK |
2205 | if (index == 0) { |
2206 | sg_len = sg_dma_len(sg); | |
2207 | addr = (u64) sg_dma_address(sg); | |
2208 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, | |
457ff3b7 | 2209 | ((u32)(addr & 0xFFFFFFFF))); |
6733b39a | 2210 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
457ff3b7 | 2211 | ((u32)(addr >> 32))); |
6733b39a JK |
2212 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
2213 | sg_len); | |
2214 | sge_len = sg_len; | |
6733b39a | 2215 | } else { |
6733b39a JK |
2216 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
2217 | pwrb, sge_len); | |
2218 | sg_len = sg_dma_len(sg); | |
2219 | addr = (u64) sg_dma_address(sg); | |
2220 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, | |
457ff3b7 | 2221 | ((u32)(addr & 0xFFFFFFFF))); |
6733b39a | 2222 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
457ff3b7 | 2223 | ((u32)(addr >> 32))); |
6733b39a JK |
2224 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
2225 | sg_len); | |
2226 | } | |
2227 | } | |
2228 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2229 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); | |
2230 | ||
2231 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); | |
2232 | ||
2233 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2234 | io_task->bhs_pa.u.a32.address_hi); | |
2235 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2236 | io_task->bhs_pa.u.a32.address_lo); | |
2237 | ||
caf818f1 JK |
2238 | if (num_sg == 1) { |
2239 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2240 | 1); | |
2241 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2242 | 0); | |
2243 | } else if (num_sg == 2) { | |
2244 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2245 | 0); | |
2246 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2247 | 1); | |
2248 | } else { | |
2249 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, | |
2250 | 0); | |
2251 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, | |
2252 | 0); | |
2253 | } | |
6733b39a JK |
2254 | sg = l_sg; |
2255 | psgl++; | |
2256 | psgl++; | |
2257 | offset = 0; | |
48bd86cf | 2258 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
6733b39a JK |
2259 | sg_len = sg_dma_len(sg); |
2260 | addr = (u64) sg_dma_address(sg); | |
2261 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2262 | (addr & 0xFFFFFFFF)); | |
2263 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2264 | (addr >> 32)); | |
2265 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); | |
2266 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); | |
2267 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2268 | offset += sg_len; | |
2269 | } | |
2270 | psgl--; | |
2271 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
2272 | } | |
2273 | ||
d629c471 JSJ |
2274 | /** |
2275 | * hwi_write_buffer()- Populate the WRB with task info | |
2276 | * @pwrb: ptr to the WRB entry | |
2277 | * @task: iscsi task which is to be executed | |
2278 | **/ | |
e0493627 | 2279 | static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task) |
6733b39a JK |
2280 | { |
2281 | struct iscsi_sge *psgl; | |
6733b39a JK |
2282 | struct beiscsi_io_task *io_task = task->dd_data; |
2283 | struct beiscsi_conn *beiscsi_conn = io_task->conn; | |
2284 | struct beiscsi_hba *phba = beiscsi_conn->phba; | |
09a1093a | 2285 | uint8_t dsp_value = 0; |
6733b39a JK |
2286 | |
2287 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; | |
2288 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, | |
2289 | io_task->bhs_pa.u.a32.address_lo); | |
2290 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, | |
2291 | io_task->bhs_pa.u.a32.address_hi); | |
2292 | ||
2293 | if (task->data) { | |
09a1093a JSJ |
2294 | |
2295 | /* Check for the data_count */ | |
2296 | dsp_value = (task->data_count) ? 1 : 0; | |
2297 | ||
2c9dfd36 JK |
2298 | if (is_chip_be2_be3r(phba)) |
2299 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, | |
09a1093a JSJ |
2300 | pwrb, dsp_value); |
2301 | else | |
2c9dfd36 | 2302 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
09a1093a JSJ |
2303 | pwrb, dsp_value); |
2304 | ||
2305 | /* Map addr only if there is data_count */ | |
2306 | if (dsp_value) { | |
d629c471 JSJ |
2307 | io_task->mtask_addr = pci_map_single(phba->pcidev, |
2308 | task->data, | |
2309 | task->data_count, | |
2310 | PCI_DMA_TODEVICE); | |
e0493627 AK |
2311 | if (pci_dma_mapping_error(phba->pcidev, |
2312 | io_task->mtask_addr)) | |
2313 | return -ENOMEM; | |
d629c471 | 2314 | io_task->mtask_data_count = task->data_count; |
09a1093a | 2315 | } else |
d629c471 | 2316 | io_task->mtask_addr = 0; |
09a1093a | 2317 | |
6733b39a | 2318 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
d629c471 | 2319 | lower_32_bits(io_task->mtask_addr)); |
6733b39a | 2320 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
d629c471 | 2321 | upper_32_bits(io_task->mtask_addr)); |
6733b39a JK |
2322 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
2323 | task->data_count); | |
2324 | ||
2325 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); | |
2326 | } else { | |
2327 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); | |
d629c471 | 2328 | io_task->mtask_addr = 0; |
6733b39a JK |
2329 | } |
2330 | ||
2331 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; | |
2332 | ||
2333 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); | |
2334 | ||
2335 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, | |
2336 | io_task->bhs_pa.u.a32.address_hi); | |
2337 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
2338 | io_task->bhs_pa.u.a32.address_lo); | |
2339 | if (task->data) { | |
2340 | psgl++; | |
2341 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); | |
2342 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); | |
2343 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); | |
2344 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); | |
2345 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); | |
2346 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); | |
2347 | ||
2348 | psgl++; | |
2349 | if (task->data) { | |
2350 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, | |
d629c471 | 2351 | lower_32_bits(io_task->mtask_addr)); |
6733b39a | 2352 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
d629c471 | 2353 | upper_32_bits(io_task->mtask_addr)); |
6733b39a JK |
2354 | } |
2355 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); | |
2356 | } | |
2357 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); | |
e0493627 | 2358 | return 0; |
6733b39a JK |
2359 | } |
2360 | ||
843ae752 JK |
2361 | /** |
2362 | * beiscsi_find_mem_req()- Find mem needed | |
2363 | * @phba: ptr to HBA struct | |
2364 | **/ | |
6733b39a JK |
2365 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
2366 | { | |
8a86e833 | 2367 | uint8_t mem_descr_index, ulp_num; |
bfead3b2 | 2368 | unsigned int num_cq_pages, num_async_pdu_buf_pages; |
6733b39a JK |
2369 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
2370 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; | |
2371 | ||
2372 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ | |
2373 | sizeof(struct sol_cqe)); | |
6733b39a JK |
2374 | |
2375 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); | |
2376 | ||
2377 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * | |
2378 | BE_ISCSI_PDU_HEADER_SIZE; | |
2379 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = | |
2380 | sizeof(struct hwi_context_memory); | |
2381 | ||
6733b39a JK |
2382 | |
2383 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) | |
2384 | * (phba->params.wrbs_per_cxn) | |
2385 | * phba->params.cxns_per_ctrl; | |
2386 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * | |
2387 | (phba->params.wrbs_per_cxn); | |
2388 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * | |
2389 | phba->params.cxns_per_ctrl); | |
2390 | ||
2391 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * | |
2392 | phba->params.icds_per_ctrl; | |
2393 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * | |
2394 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; | |
8a86e833 JK |
2395 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
2396 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
6733b39a | 2397 | |
8a86e833 JK |
2398 | num_async_pdu_buf_sgl_pages = |
2399 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2400 | phba, ulp_num) * | |
2401 | sizeof(struct phys_addr)); | |
2402 | ||
2403 | num_async_pdu_buf_pages = | |
2404 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2405 | phba, ulp_num) * | |
2406 | phba->params.defpdu_hdr_sz); | |
2407 | ||
2408 | num_async_pdu_data_pages = | |
2409 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2410 | phba, ulp_num) * | |
2411 | phba->params.defpdu_data_sz); | |
2412 | ||
2413 | num_async_pdu_data_sgl_pages = | |
2414 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( | |
2415 | phba, ulp_num) * | |
2416 | sizeof(struct phys_addr)); | |
2417 | ||
a129d92f JK |
2418 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
2419 | (ulp_num * MEM_DESCR_OFFSET)); | |
2420 | phba->mem_req[mem_descr_index] = | |
2421 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
2422 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; | |
2423 | ||
8a86e833 JK |
2424 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
2425 | (ulp_num * MEM_DESCR_OFFSET)); | |
2426 | phba->mem_req[mem_descr_index] = | |
2427 | num_async_pdu_buf_pages * | |
2428 | PAGE_SIZE; | |
2429 | ||
2430 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + | |
2431 | (ulp_num * MEM_DESCR_OFFSET)); | |
2432 | phba->mem_req[mem_descr_index] = | |
2433 | num_async_pdu_data_pages * | |
2434 | PAGE_SIZE; | |
2435 | ||
2436 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + | |
2437 | (ulp_num * MEM_DESCR_OFFSET)); | |
2438 | phba->mem_req[mem_descr_index] = | |
2439 | num_async_pdu_buf_sgl_pages * | |
2440 | PAGE_SIZE; | |
2441 | ||
2442 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + | |
2443 | (ulp_num * MEM_DESCR_OFFSET)); | |
2444 | phba->mem_req[mem_descr_index] = | |
2445 | num_async_pdu_data_sgl_pages * | |
2446 | PAGE_SIZE; | |
2447 | ||
2448 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + | |
2449 | (ulp_num * MEM_DESCR_OFFSET)); | |
2450 | phba->mem_req[mem_descr_index] = | |
2451 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
938f372c | 2452 | sizeof(struct hd_async_handle); |
8a86e833 JK |
2453 | |
2454 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + | |
2455 | (ulp_num * MEM_DESCR_OFFSET)); | |
2456 | phba->mem_req[mem_descr_index] = | |
2457 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * | |
938f372c | 2458 | sizeof(struct hd_async_handle); |
8a86e833 JK |
2459 | |
2460 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + | |
2461 | (ulp_num * MEM_DESCR_OFFSET)); | |
2462 | phba->mem_req[mem_descr_index] = | |
938f372c | 2463 | sizeof(struct hd_async_context) + |
8a86e833 | 2464 | (BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
938f372c | 2465 | sizeof(struct hd_async_entry)); |
8a86e833 JK |
2466 | } |
2467 | } | |
6733b39a JK |
2468 | } |
2469 | ||
2470 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) | |
2471 | { | |
6733b39a | 2472 | dma_addr_t bus_add; |
a7909b39 JK |
2473 | struct hwi_controller *phwi_ctrlr; |
2474 | struct be_mem_descriptor *mem_descr; | |
6733b39a JK |
2475 | struct mem_array *mem_arr, *mem_arr_orig; |
2476 | unsigned int i, j, alloc_size, curr_alloc_size; | |
2477 | ||
3ec78271 | 2478 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
6733b39a JK |
2479 | if (!phba->phwi_ctrlr) |
2480 | return -ENOMEM; | |
2481 | ||
a7909b39 JK |
2482 | /* Allocate memory for wrb_context */ |
2483 | phwi_ctrlr = phba->phwi_ctrlr; | |
2484 | phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) * | |
2485 | phba->params.cxns_per_ctrl, | |
2486 | GFP_KERNEL); | |
0c88740d ML |
2487 | if (!phwi_ctrlr->wrb_context) { |
2488 | kfree(phba->phwi_ctrlr); | |
a7909b39 | 2489 | return -ENOMEM; |
0c88740d | 2490 | } |
a7909b39 | 2491 | |
6733b39a JK |
2492 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
2493 | GFP_KERNEL); | |
2494 | if (!phba->init_mem) { | |
a7909b39 | 2495 | kfree(phwi_ctrlr->wrb_context); |
6733b39a JK |
2496 | kfree(phba->phwi_ctrlr); |
2497 | return -ENOMEM; | |
2498 | } | |
2499 | ||
2500 | mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT, | |
2501 | GFP_KERNEL); | |
2502 | if (!mem_arr_orig) { | |
2503 | kfree(phba->init_mem); | |
a7909b39 | 2504 | kfree(phwi_ctrlr->wrb_context); |
6733b39a JK |
2505 | kfree(phba->phwi_ctrlr); |
2506 | return -ENOMEM; | |
2507 | } | |
2508 | ||
2509 | mem_descr = phba->init_mem; | |
2510 | for (i = 0; i < SE_MEM_MAX; i++) { | |
8a86e833 JK |
2511 | if (!phba->mem_req[i]) { |
2512 | mem_descr->mem_array = NULL; | |
2513 | mem_descr++; | |
2514 | continue; | |
2515 | } | |
2516 | ||
6733b39a JK |
2517 | j = 0; |
2518 | mem_arr = mem_arr_orig; | |
2519 | alloc_size = phba->mem_req[i]; | |
2520 | memset(mem_arr, 0, sizeof(struct mem_array) * | |
2521 | BEISCSI_MAX_FRAGS_INIT); | |
2522 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); | |
2523 | do { | |
2524 | mem_arr->virtual_address = pci_alloc_consistent( | |
2525 | phba->pcidev, | |
2526 | curr_alloc_size, | |
2527 | &bus_add); | |
2528 | if (!mem_arr->virtual_address) { | |
2529 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) | |
2530 | goto free_mem; | |
2531 | if (curr_alloc_size - | |
2532 | rounddown_pow_of_two(curr_alloc_size)) | |
2533 | curr_alloc_size = rounddown_pow_of_two | |
2534 | (curr_alloc_size); | |
2535 | else | |
2536 | curr_alloc_size = curr_alloc_size / 2; | |
2537 | } else { | |
2538 | mem_arr->bus_address.u. | |
2539 | a64.address = (__u64) bus_add; | |
2540 | mem_arr->size = curr_alloc_size; | |
2541 | alloc_size -= curr_alloc_size; | |
2542 | curr_alloc_size = min(be_max_phys_size * | |
2543 | 1024, alloc_size); | |
2544 | j++; | |
2545 | mem_arr++; | |
2546 | } | |
2547 | } while (alloc_size); | |
2548 | mem_descr->num_elements = j; | |
2549 | mem_descr->size_in_bytes = phba->mem_req[i]; | |
2550 | mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j, | |
2551 | GFP_KERNEL); | |
2552 | if (!mem_descr->mem_array) | |
2553 | goto free_mem; | |
2554 | ||
2555 | memcpy(mem_descr->mem_array, mem_arr_orig, | |
2556 | sizeof(struct mem_array) * j); | |
2557 | mem_descr++; | |
2558 | } | |
2559 | kfree(mem_arr_orig); | |
2560 | return 0; | |
2561 | free_mem: | |
2562 | mem_descr->num_elements = j; | |
2563 | while ((i) || (j)) { | |
2564 | for (j = mem_descr->num_elements; j > 0; j--) { | |
2565 | pci_free_consistent(phba->pcidev, | |
2566 | mem_descr->mem_array[j - 1].size, | |
2567 | mem_descr->mem_array[j - 1]. | |
2568 | virtual_address, | |
457ff3b7 JK |
2569 | (unsigned long)mem_descr-> |
2570 | mem_array[j - 1]. | |
6733b39a JK |
2571 | bus_address.u.a64.address); |
2572 | } | |
2573 | if (i) { | |
2574 | i--; | |
2575 | kfree(mem_descr->mem_array); | |
2576 | mem_descr--; | |
2577 | } | |
2578 | } | |
2579 | kfree(mem_arr_orig); | |
2580 | kfree(phba->init_mem); | |
a7909b39 | 2581 | kfree(phba->phwi_ctrlr->wrb_context); |
6733b39a JK |
2582 | kfree(phba->phwi_ctrlr); |
2583 | return -ENOMEM; | |
2584 | } | |
2585 | ||
2586 | static int beiscsi_get_memory(struct beiscsi_hba *phba) | |
2587 | { | |
2588 | beiscsi_find_mem_req(phba); | |
2589 | return beiscsi_alloc_mem(phba); | |
2590 | } | |
2591 | ||
2592 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) | |
2593 | { | |
2594 | struct pdu_data_out *pdata_out; | |
2595 | struct pdu_nop_out *pnop_out; | |
2596 | struct be_mem_descriptor *mem_descr; | |
2597 | ||
2598 | mem_descr = phba->init_mem; | |
2599 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; | |
2600 | pdata_out = | |
2601 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; | |
2602 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); | |
2603 | ||
2604 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, | |
2605 | IIOC_SCSI_DATA); | |
2606 | ||
2607 | pnop_out = | |
2608 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. | |
2609 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); | |
2610 | ||
2611 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); | |
2612 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); | |
2613 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); | |
2614 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); | |
2615 | } | |
2616 | ||
3ec78271 | 2617 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
6733b39a JK |
2618 | { |
2619 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; | |
a7909b39 | 2620 | struct hwi_context_memory *phwi_ctxt; |
3ec78271 | 2621 | struct wrb_handle *pwrb_handle = NULL; |
6733b39a JK |
2622 | struct hwi_controller *phwi_ctrlr; |
2623 | struct hwi_wrb_context *pwrb_context; | |
3ec78271 JK |
2624 | struct iscsi_wrb *pwrb = NULL; |
2625 | unsigned int num_cxn_wrbh = 0; | |
2626 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; | |
6733b39a JK |
2627 | |
2628 | mem_descr_wrbh = phba->init_mem; | |
2629 | mem_descr_wrbh += HWI_MEM_WRBH; | |
2630 | ||
2631 | mem_descr_wrb = phba->init_mem; | |
2632 | mem_descr_wrb += HWI_MEM_WRB; | |
6733b39a JK |
2633 | phwi_ctrlr = phba->phwi_ctrlr; |
2634 | ||
a7909b39 JK |
2635 | /* Allocate memory for WRBQ */ |
2636 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; | |
2637 | phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) * | |
843ae752 | 2638 | phba->params.cxns_per_ctrl, |
a7909b39 JK |
2639 | GFP_KERNEL); |
2640 | if (!phwi_ctxt->be_wrbq) { | |
2641 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, | |
2642 | "BM_%d : WRBQ Mem Alloc Failed\n"); | |
2643 | return -ENOMEM; | |
2644 | } | |
2645 | ||
2646 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { | |
6733b39a | 2647 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
6733b39a JK |
2648 | pwrb_context->pwrb_handle_base = |
2649 | kzalloc(sizeof(struct wrb_handle *) * | |
2650 | phba->params.wrbs_per_cxn, GFP_KERNEL); | |
3ec78271 | 2651 | if (!pwrb_context->pwrb_handle_base) { |
99bc5d55 JSJ |
2652 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
2653 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
3ec78271 JK |
2654 | goto init_wrb_hndl_failed; |
2655 | } | |
6733b39a JK |
2656 | pwrb_context->pwrb_handle_basestd = |
2657 | kzalloc(sizeof(struct wrb_handle *) * | |
2658 | phba->params.wrbs_per_cxn, GFP_KERNEL); | |
3ec78271 | 2659 | if (!pwrb_context->pwrb_handle_basestd) { |
99bc5d55 JSJ |
2660 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
2661 | "BM_%d : Mem Alloc Failed. Failing to load\n"); | |
3ec78271 JK |
2662 | goto init_wrb_hndl_failed; |
2663 | } | |
2664 | if (!num_cxn_wrbh) { | |
2665 | pwrb_handle = | |
2666 | mem_descr_wrbh->mem_array[idx].virtual_address; | |
2667 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / | |
2668 | ((sizeof(struct wrb_handle)) * | |
2669 | phba->params.wrbs_per_cxn)); | |
2670 | idx++; | |
2671 | } | |
2672 | pwrb_context->alloc_index = 0; | |
2673 | pwrb_context->wrb_handles_available = 0; | |
2674 | pwrb_context->free_index = 0; | |
2675 | ||
6733b39a | 2676 | if (num_cxn_wrbh) { |
6733b39a JK |
2677 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
2678 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; | |
2679 | pwrb_context->pwrb_handle_basestd[j] = | |
2680 | pwrb_handle; | |
2681 | pwrb_context->wrb_handles_available++; | |
bfead3b2 | 2682 | pwrb_handle->wrb_index = j; |
6733b39a JK |
2683 | pwrb_handle++; |
2684 | } | |
6733b39a JK |
2685 | num_cxn_wrbh--; |
2686 | } | |
f64d92e6 | 2687 | spin_lock_init(&pwrb_context->wrb_lock); |
6733b39a JK |
2688 | } |
2689 | idx = 0; | |
a7909b39 | 2690 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
6733b39a | 2691 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
3ec78271 | 2692 | if (!num_cxn_wrb) { |
6733b39a | 2693 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
7c56533c | 2694 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
3ec78271 JK |
2695 | ((sizeof(struct iscsi_wrb) * |
2696 | phba->params.wrbs_per_cxn)); | |
2697 | idx++; | |
2698 | } | |
2699 | ||
2700 | if (num_cxn_wrb) { | |
6733b39a JK |
2701 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
2702 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; | |
2703 | pwrb_handle->pwrb = pwrb; | |
2704 | pwrb++; | |
2705 | } | |
2706 | num_cxn_wrb--; | |
2707 | } | |
2708 | } | |
3ec78271 JK |
2709 | return 0; |
2710 | init_wrb_hndl_failed: | |
2711 | for (j = index; j > 0; j--) { | |
2712 | pwrb_context = &phwi_ctrlr->wrb_context[j]; | |
2713 | kfree(pwrb_context->pwrb_handle_base); | |
2714 | kfree(pwrb_context->pwrb_handle_basestd); | |
2715 | } | |
2716 | return -ENOMEM; | |
6733b39a JK |
2717 | } |
2718 | ||
a7909b39 | 2719 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
6733b39a | 2720 | { |
8a86e833 | 2721 | uint8_t ulp_num; |
6733b39a JK |
2722 | struct hwi_controller *phwi_ctrlr; |
2723 | struct hba_parameters *p = &phba->params; | |
938f372c JB |
2724 | struct hd_async_context *pasync_ctx; |
2725 | struct hd_async_handle *pasync_header_h, *pasync_data_h; | |
dc63aac6 | 2726 | unsigned int index, idx, num_per_mem, num_async_data; |
6733b39a JK |
2727 | struct be_mem_descriptor *mem_descr; |
2728 | ||
8a86e833 JK |
2729 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
2730 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { | |
938f372c | 2731 | /* get async_ctx for each ULP */ |
8a86e833 JK |
2732 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2733 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + | |
2734 | (ulp_num * MEM_DESCR_OFFSET)); | |
2735 | ||
2736 | phwi_ctrlr = phba->phwi_ctrlr; | |
2737 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = | |
938f372c | 2738 | (struct hd_async_context *) |
8a86e833 JK |
2739 | mem_descr->mem_array[0].virtual_address; |
2740 | ||
2741 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; | |
2742 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); | |
2743 | ||
2744 | pasync_ctx->async_entry = | |
938f372c | 2745 | (struct hd_async_entry *) |
8a86e833 | 2746 | ((long unsigned int)pasync_ctx + |
938f372c | 2747 | sizeof(struct hd_async_context)); |
8a86e833 JK |
2748 | |
2749 | pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba, | |
2750 | ulp_num); | |
938f372c | 2751 | /* setup header buffers */ |
8a86e833 JK |
2752 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2753 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + | |
2754 | (ulp_num * MEM_DESCR_OFFSET); | |
2755 | if (mem_descr->mem_array[0].virtual_address) { | |
2756 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2757 | "BM_%d : hwi_init_async_pdu_ctx" | |
2758 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", | |
2759 | ulp_num, | |
2760 | mem_descr->mem_array[0]. | |
2761 | virtual_address); | |
2762 | } else | |
2763 | beiscsi_log(phba, KERN_WARNING, | |
2764 | BEISCSI_LOG_INIT, | |
2765 | "BM_%d : No Virtual address for ULP : %d\n", | |
2766 | ulp_num); | |
2767 | ||
938f372c | 2768 | pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz; |
8a86e833 | 2769 | pasync_ctx->async_header.va_base = |
6733b39a | 2770 | mem_descr->mem_array[0].virtual_address; |
6733b39a | 2771 | |
8a86e833 JK |
2772 | pasync_ctx->async_header.pa_base.u.a64.address = |
2773 | mem_descr->mem_array[0]. | |
2774 | bus_address.u.a64.address; | |
6733b39a | 2775 | |
938f372c | 2776 | /* setup header buffer sgls */ |
8a86e833 JK |
2777 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2778 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + | |
2779 | (ulp_num * MEM_DESCR_OFFSET); | |
2780 | if (mem_descr->mem_array[0].virtual_address) { | |
2781 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2782 | "BM_%d : hwi_init_async_pdu_ctx" | |
2783 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", | |
2784 | ulp_num, | |
2785 | mem_descr->mem_array[0]. | |
2786 | virtual_address); | |
2787 | } else | |
2788 | beiscsi_log(phba, KERN_WARNING, | |
2789 | BEISCSI_LOG_INIT, | |
2790 | "BM_%d : No Virtual address for ULP : %d\n", | |
2791 | ulp_num); | |
2792 | ||
2793 | pasync_ctx->async_header.ring_base = | |
2794 | mem_descr->mem_array[0].virtual_address; | |
6733b39a | 2795 | |
938f372c | 2796 | /* setup header buffer handles */ |
8a86e833 JK |
2797 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2798 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + | |
2799 | (ulp_num * MEM_DESCR_OFFSET); | |
2800 | if (mem_descr->mem_array[0].virtual_address) { | |
2801 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2802 | "BM_%d : hwi_init_async_pdu_ctx" | |
2803 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", | |
2804 | ulp_num, | |
2805 | mem_descr->mem_array[0]. | |
2806 | virtual_address); | |
2807 | } else | |
2808 | beiscsi_log(phba, KERN_WARNING, | |
2809 | BEISCSI_LOG_INIT, | |
2810 | "BM_%d : No Virtual address for ULP : %d\n", | |
2811 | ulp_num); | |
2812 | ||
2813 | pasync_ctx->async_header.handle_base = | |
2814 | mem_descr->mem_array[0].virtual_address; | |
8a86e833 JK |
2815 | INIT_LIST_HEAD(&pasync_ctx->async_header.free_list); |
2816 | ||
938f372c | 2817 | /* setup data buffer sgls */ |
8a86e833 JK |
2818 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2819 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + | |
2820 | (ulp_num * MEM_DESCR_OFFSET); | |
2821 | if (mem_descr->mem_array[0].virtual_address) { | |
2822 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2823 | "BM_%d : hwi_init_async_pdu_ctx" | |
2824 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", | |
2825 | ulp_num, | |
2826 | mem_descr->mem_array[0]. | |
2827 | virtual_address); | |
2828 | } else | |
2829 | beiscsi_log(phba, KERN_WARNING, | |
2830 | BEISCSI_LOG_INIT, | |
2831 | "BM_%d : No Virtual address for ULP : %d\n", | |
2832 | ulp_num); | |
2833 | ||
2834 | pasync_ctx->async_data.ring_base = | |
2835 | mem_descr->mem_array[0].virtual_address; | |
6733b39a | 2836 | |
938f372c | 2837 | /* setup data buffer handles */ |
8a86e833 JK |
2838 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2839 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + | |
2840 | (ulp_num * MEM_DESCR_OFFSET); | |
2841 | if (!mem_descr->mem_array[0].virtual_address) | |
2842 | beiscsi_log(phba, KERN_WARNING, | |
2843 | BEISCSI_LOG_INIT, | |
2844 | "BM_%d : No Virtual address for ULP : %d\n", | |
2845 | ulp_num); | |
99bc5d55 | 2846 | |
8a86e833 JK |
2847 | pasync_ctx->async_data.handle_base = |
2848 | mem_descr->mem_array[0].virtual_address; | |
8a86e833 JK |
2849 | INIT_LIST_HEAD(&pasync_ctx->async_data.free_list); |
2850 | ||
2851 | pasync_header_h = | |
938f372c | 2852 | (struct hd_async_handle *) |
8a86e833 JK |
2853 | pasync_ctx->async_header.handle_base; |
2854 | pasync_data_h = | |
938f372c | 2855 | (struct hd_async_handle *) |
8a86e833 JK |
2856 | pasync_ctx->async_data.handle_base; |
2857 | ||
938f372c | 2858 | /* setup data buffers */ |
8a86e833 JK |
2859 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
2860 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + | |
2861 | (ulp_num * MEM_DESCR_OFFSET); | |
2862 | if (mem_descr->mem_array[0].virtual_address) { | |
2863 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
2864 | "BM_%d : hwi_init_async_pdu_ctx" | |
2865 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", | |
2866 | ulp_num, | |
2867 | mem_descr->mem_array[0]. | |
2868 | virtual_address); | |
2869 | } else | |
2870 | beiscsi_log(phba, KERN_WARNING, | |
2871 | BEISCSI_LOG_INIT, | |
2872 | "BM_%d : No Virtual address for ULP : %d\n", | |
2873 | ulp_num); | |
2874 | ||
2875 | idx = 0; | |
938f372c | 2876 | pasync_ctx->async_data.buffer_size = p->defpdu_data_sz; |
dc63aac6 JK |
2877 | pasync_ctx->async_data.va_base = |
2878 | mem_descr->mem_array[idx].virtual_address; | |
2879 | pasync_ctx->async_data.pa_base.u.a64.address = | |
2880 | mem_descr->mem_array[idx]. | |
2881 | bus_address.u.a64.address; | |
2882 | ||
2883 | num_async_data = ((mem_descr->mem_array[idx].size) / | |
2884 | phba->params.defpdu_data_sz); | |
8a86e833 | 2885 | num_per_mem = 0; |
6733b39a | 2886 | |
8a86e833 JK |
2887 | for (index = 0; index < BEISCSI_GET_CID_COUNT |
2888 | (phba, ulp_num); index++) { | |
2889 | pasync_header_h->cri = -1; | |
938f372c JB |
2890 | pasync_header_h->is_header = 1; |
2891 | pasync_header_h->index = index; | |
8a86e833 JK |
2892 | INIT_LIST_HEAD(&pasync_header_h->link); |
2893 | pasync_header_h->pbuffer = | |
2894 | (void *)((unsigned long) | |
2895 | (pasync_ctx-> | |
2896 | async_header.va_base) + | |
2897 | (p->defpdu_hdr_sz * index)); | |
2898 | ||
2899 | pasync_header_h->pa.u.a64.address = | |
2900 | pasync_ctx->async_header.pa_base.u.a64. | |
2901 | address + (p->defpdu_hdr_sz * index); | |
2902 | ||
2903 | list_add_tail(&pasync_header_h->link, | |
2904 | &pasync_ctx->async_header. | |
2905 | free_list); | |
2906 | pasync_header_h++; | |
2907 | pasync_ctx->async_header.free_entries++; | |
8a86e833 | 2908 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
938f372c JB |
2909 | wq.list); |
2910 | pasync_ctx->async_entry[index].header = NULL; | |
2911 | ||
8a86e833 | 2912 | pasync_data_h->cri = -1; |
938f372c JB |
2913 | pasync_data_h->is_header = 0; |
2914 | pasync_data_h->index = index; | |
8a86e833 JK |
2915 | INIT_LIST_HEAD(&pasync_data_h->link); |
2916 | ||
2917 | if (!num_async_data) { | |
2918 | num_per_mem = 0; | |
2919 | idx++; | |
2920 | pasync_ctx->async_data.va_base = | |
2921 | mem_descr->mem_array[idx]. | |
2922 | virtual_address; | |
2923 | pasync_ctx->async_data.pa_base.u. | |
2924 | a64.address = | |
2925 | mem_descr->mem_array[idx]. | |
2926 | bus_address.u.a64.address; | |
2927 | num_async_data = | |
2928 | ((mem_descr->mem_array[idx]. | |
2929 | size) / | |
2930 | phba->params.defpdu_data_sz); | |
2931 | } | |
2932 | pasync_data_h->pbuffer = | |
2933 | (void *)((unsigned long) | |
2934 | (pasync_ctx->async_data.va_base) + | |
2935 | (p->defpdu_data_sz * num_per_mem)); | |
2936 | ||
2937 | pasync_data_h->pa.u.a64.address = | |
2938 | pasync_ctx->async_data.pa_base.u.a64. | |
2939 | address + (p->defpdu_data_sz * | |
2940 | num_per_mem); | |
2941 | num_per_mem++; | |
2942 | num_async_data--; | |
2943 | ||
2944 | list_add_tail(&pasync_data_h->link, | |
2945 | &pasync_ctx->async_data. | |
2946 | free_list); | |
2947 | pasync_data_h++; | |
2948 | pasync_ctx->async_data.free_entries++; | |
938f372c | 2949 | pasync_ctx->async_entry[index].data = NULL; |
8a86e833 | 2950 | } |
8a86e833 | 2951 | } |
6733b39a JK |
2952 | } |
2953 | ||
a7909b39 | 2954 | return 0; |
6733b39a JK |
2955 | } |
2956 | ||
2957 | static int | |
2958 | be_sgl_create_contiguous(void *virtual_address, | |
2959 | u64 physical_address, u32 length, | |
2960 | struct be_dma_mem *sgl) | |
2961 | { | |
2962 | WARN_ON(!virtual_address); | |
2963 | WARN_ON(!physical_address); | |
dd29dae0 | 2964 | WARN_ON(!length); |
6733b39a JK |
2965 | WARN_ON(!sgl); |
2966 | ||
2967 | sgl->va = virtual_address; | |
457ff3b7 | 2968 | sgl->dma = (unsigned long)physical_address; |
6733b39a JK |
2969 | sgl->size = length; |
2970 | ||
2971 | return 0; | |
2972 | } | |
2973 | ||
2974 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) | |
2975 | { | |
2976 | memset(sgl, 0, sizeof(*sgl)); | |
2977 | } | |
2978 | ||
2979 | static void | |
2980 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, | |
2981 | struct mem_array *pmem, struct be_dma_mem *sgl) | |
2982 | { | |
2983 | if (sgl->va) | |
2984 | be_sgl_destroy_contiguous(sgl); | |
2985 | ||
2986 | be_sgl_create_contiguous(pmem->virtual_address, | |
2987 | pmem->bus_address.u.a64.address, | |
2988 | pmem->size, sgl); | |
2989 | } | |
2990 | ||
2991 | static void | |
2992 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, | |
2993 | struct mem_array *pmem, struct be_dma_mem *sgl) | |
2994 | { | |
2995 | if (sgl->va) | |
2996 | be_sgl_destroy_contiguous(sgl); | |
2997 | ||
2998 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, | |
2999 | pmem->bus_address.u.a64.address, | |
3000 | pmem->size, sgl); | |
3001 | } | |
3002 | ||
3003 | static int be_fill_queue(struct be_queue_info *q, | |
3004 | u16 len, u16 entry_size, void *vaddress) | |
3005 | { | |
3006 | struct be_dma_mem *mem = &q->dma_mem; | |
3007 | ||
3008 | memset(q, 0, sizeof(*q)); | |
3009 | q->len = len; | |
3010 | q->entry_size = entry_size; | |
3011 | mem->size = len * entry_size; | |
3012 | mem->va = vaddress; | |
3013 | if (!mem->va) | |
3014 | return -ENOMEM; | |
3015 | memset(mem->va, 0, mem->size); | |
3016 | return 0; | |
3017 | } | |
3018 | ||
bfead3b2 | 3019 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
6733b39a JK |
3020 | struct hwi_context_memory *phwi_context) |
3021 | { | |
deeea8ed | 3022 | int ret = -ENOMEM, eq_for_mcc; |
bfead3b2 | 3023 | unsigned int i, num_eq_pages; |
6733b39a JK |
3024 | struct be_queue_info *eq; |
3025 | struct be_dma_mem *mem; | |
6733b39a | 3026 | void *eq_vaddress; |
bfead3b2 | 3027 | dma_addr_t paddr; |
6733b39a | 3028 | |
bfead3b2 JK |
3029 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
3030 | sizeof(struct be_eq_entry)); | |
6733b39a | 3031 | |
bfead3b2 JK |
3032 | if (phba->msix_enabled) |
3033 | eq_for_mcc = 1; | |
3034 | else | |
3035 | eq_for_mcc = 0; | |
3036 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { | |
3037 | eq = &phwi_context->be_eq[i].q; | |
3038 | mem = &eq->dma_mem; | |
3039 | phwi_context->be_eq[i].phba = phba; | |
3040 | eq_vaddress = pci_alloc_consistent(phba->pcidev, | |
deeea8ed CJ |
3041 | num_eq_pages * PAGE_SIZE, |
3042 | &paddr); | |
bfead3b2 JK |
3043 | if (!eq_vaddress) |
3044 | goto create_eq_error; | |
3045 | ||
3046 | mem->va = eq_vaddress; | |
3047 | ret = be_fill_queue(eq, phba->params.num_eq_entries, | |
3048 | sizeof(struct be_eq_entry), eq_vaddress); | |
3049 | if (ret) { | |
99bc5d55 JSJ |
3050 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3051 | "BM_%d : be_fill_queue Failed for EQ\n"); | |
bfead3b2 JK |
3052 | goto create_eq_error; |
3053 | } | |
6733b39a | 3054 | |
bfead3b2 JK |
3055 | mem->dma = paddr; |
3056 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, | |
3057 | phwi_context->cur_eqd); | |
3058 | if (ret) { | |
99bc5d55 JSJ |
3059 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
3060 | "BM_%d : beiscsi_cmd_eq_create" | |
3061 | "Failed for EQ\n"); | |
bfead3b2 JK |
3062 | goto create_eq_error; |
3063 | } | |
99bc5d55 JSJ |
3064 | |
3065 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, | |
3066 | "BM_%d : eqid = %d\n", | |
3067 | phwi_context->be_eq[i].q.id); | |
6733b39a | 3068 | } |
6733b39a | 3069 | return 0; |
deeea8ed | 3070 | |
bfead3b2 | 3071 | create_eq_error: |
107dfcba | 3072 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
bfead3b2 JK |
3073 | eq = &phwi_context->be_eq[i].q; |
3074 | mem = &eq->dma_mem; | |
3075 | if (mem->va) | |
3076 | pci_free_consistent(phba->pcidev, num_eq_pages | |
3077 | * PAGE_SIZE, | |
3078 | mem->va, mem->dma); | |
3079 | } | |
3080 | return ret; | |
6733b39a JK |
3081 | } |
3082 | ||
bfead3b2 | 3083 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
6733b39a JK |
3084 | struct hwi_context_memory *phwi_context) |
3085 | { | |
bfead3b2 | 3086 | unsigned int i, num_cq_pages; |
6733b39a JK |
3087 | struct be_queue_info *cq, *eq; |
3088 | struct be_dma_mem *mem; | |
bfead3b2 | 3089 | struct be_eq_obj *pbe_eq; |
6733b39a | 3090 | void *cq_vaddress; |
deeea8ed | 3091 | int ret = -ENOMEM; |
bfead3b2 | 3092 | dma_addr_t paddr; |
6733b39a | 3093 | |
bfead3b2 JK |
3094 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
3095 | sizeof(struct sol_cqe)); | |
6733b39a | 3096 | |
bfead3b2 JK |
3097 | for (i = 0; i < phba->num_cpus; i++) { |
3098 | cq = &phwi_context->be_cq[i]; | |
3099 | eq = &phwi_context->be_eq[i].q; | |
3100 | pbe_eq = &phwi_context->be_eq[i]; | |
3101 | pbe_eq->cq = cq; | |
3102 | pbe_eq->phba = phba; | |
3103 | mem = &cq->dma_mem; | |
3104 | cq_vaddress = pci_alloc_consistent(phba->pcidev, | |
deeea8ed CJ |
3105 | num_cq_pages * PAGE_SIZE, |
3106 | &paddr); | |
bfead3b2 JK |
3107 | if (!cq_vaddress) |
3108 | goto create_cq_error; | |
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 | } |
09a1093a JSJ |
4587 | int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg, |
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 | ||
99bc5d55 JSJ |
4976 | void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
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); |