blob: 015efb57938426c3128af7b475c925b037960c88 [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
2 *
3 * Copyright (c) 2006 - 2009 Broadcom Corporation
4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
10 *
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
12 */
13
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/gfp.h>
Michael Chancf4e6362009-06-08 18:14:44 -070015#include <scsi/scsi_tcq.h>
16#include <scsi/libiscsi.h>
17#include "bnx2i.h"
18
19/**
20 * bnx2i_get_cid_num - get cid from ep
21 * @ep: endpoint pointer
22 *
23 * Only applicable to 57710 family of devices
24 */
25static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
26{
27 u32 cid;
28
29 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
30 cid = ep->ep_cid;
31 else
32 cid = GET_CID_NUM(ep->ep_cid);
33 return cid;
34}
35
36
37/**
38 * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
39 * @hba: Adapter for which adjustments is to be made
40 *
41 * Only applicable to 57710 family of devices
42 */
43static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
44{
45 u32 num_elements_per_pg;
46
47 if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
48 test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
49 test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
50 if (!is_power_of_2(hba->max_sqes))
51 hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
52
53 if (!is_power_of_2(hba->max_rqes))
54 hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
55 }
56
57 /* Adjust each queue size if the user selection does not
58 * yield integral num of page buffers
59 */
60 /* adjust SQ */
61 num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
62 if (hba->max_sqes < num_elements_per_pg)
63 hba->max_sqes = num_elements_per_pg;
64 else if (hba->max_sqes % num_elements_per_pg)
65 hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
66 ~(num_elements_per_pg - 1);
67
68 /* adjust CQ */
69 num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
70 if (hba->max_cqes < num_elements_per_pg)
71 hba->max_cqes = num_elements_per_pg;
72 else if (hba->max_cqes % num_elements_per_pg)
73 hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
74 ~(num_elements_per_pg - 1);
75
76 /* adjust RQ */
77 num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
78 if (hba->max_rqes < num_elements_per_pg)
79 hba->max_rqes = num_elements_per_pg;
80 else if (hba->max_rqes % num_elements_per_pg)
81 hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
82 ~(num_elements_per_pg - 1);
83}
84
85
86/**
87 * bnx2i_get_link_state - get network interface link state
88 * @hba: adapter instance pointer
89 *
90 * updates adapter structure flag based on netdev state
91 */
92static void bnx2i_get_link_state(struct bnx2i_hba *hba)
93{
94 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
95 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
96 else
97 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
98}
99
100
101/**
102 * bnx2i_iscsi_license_error - displays iscsi license related error message
103 * @hba: adapter instance pointer
104 * @error_code: error classification
105 *
106 * Puts out an error log when driver is unable to offload iscsi connection
107 * due to license restrictions
108 */
109static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
110{
111 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
112 /* iSCSI offload not supported on this device */
113 printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
114 hba->netdev->name);
115 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
116 /* iSCSI offload not supported on this LOM device */
117 printk(KERN_ERR "bnx2i: LOM is not enable to "
118 "offload iSCSI connections, dev=%s\n",
119 hba->netdev->name);
120 set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
121}
122
123
124/**
125 * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
126 * @ep: endpoint (transport indentifier) structure
127 * @action: action, ARM or DISARM. For now only ARM_CQE is used
128 *
129 * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
130 * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
131 * outstanding and on chip timer expires
132 */
133void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
134{
135 struct bnx2i_5771x_cq_db *cq_db;
136 u16 cq_index;
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800137 u16 next_index;
138 u32 num_active_cmds;
Michael Chancf4e6362009-06-08 18:14:44 -0700139
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800140
141 /* Coalesce CQ entries only on 10G devices */
Michael Chancf4e6362009-06-08 18:14:44 -0700142 if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
143 return;
144
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800145 /* Do not update CQ DB multiple times before firmware writes
146 * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
147 * interrupts and other unwanted results
148 */
149 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
150 if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
151 return;
152
Michael Chancf4e6362009-06-08 18:14:44 -0700153 if (action == CNIC_ARM_CQE) {
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800154 num_active_cmds = ep->num_active_cmds;
155 if (num_active_cmds <= event_coal_min)
156 next_index = 1;
157 else
158 next_index = event_coal_min +
159 (num_active_cmds - event_coal_min) / event_coal_div;
160 if (!next_index)
161 next_index = 1;
162 cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
163 if (cq_index > ep->qp.cqe_size * 2)
164 cq_index -= ep->qp.cqe_size * 2;
165 if (!cq_index)
Michael Chancf4e6362009-06-08 18:14:44 -0700166 cq_index = 1;
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800167
168 cq_db->sqn[0] = cq_index;
Michael Chancf4e6362009-06-08 18:14:44 -0700169 }
170}
171
172
173/**
174 * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
175 * @conn: iscsi connection on which RQ event occured
176 * @ptr: driver buffer to which RQ buffer contents is to
177 * be copied
178 * @len: length of valid data inside RQ buf
179 *
180 * Copies RQ buffer contents from shared (DMA'able) memory region to
181 * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
182 * scsi sense info
183 */
184void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
185{
186 if (!bnx2i_conn->ep->qp.rqe_left)
187 return;
188
189 bnx2i_conn->ep->qp.rqe_left--;
190 memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
191 if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
192 bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
193 bnx2i_conn->ep->qp.rq_cons_idx = 0;
194 } else {
195 bnx2i_conn->ep->qp.rq_cons_qe++;
196 bnx2i_conn->ep->qp.rq_cons_idx++;
197 }
198}
199
200
201static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
202{
203 struct bnx2i_5771x_dbell dbell;
204 u32 msg;
205
206 memset(&dbell, 0, sizeof(dbell));
207 dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
208 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
209 msg = *((u32 *)&dbell);
210 /* TODO : get doorbell register mapping */
211 writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
212}
213
214
215/**
216 * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
217 * @conn: iscsi connection on which event to post
218 * @count: number of RQ buffer being posted to chip
219 *
220 * No need to ring hardware doorbell for 57710 family of devices
221 */
222void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
223{
224 struct bnx2i_5771x_sq_rq_db *rq_db;
225 u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
226 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
227
228 ep->qp.rqe_left += count;
229 ep->qp.rq_prod_idx &= 0x7FFF;
230 ep->qp.rq_prod_idx += count;
231
232 if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
233 ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
234 if (!hi_bit)
235 ep->qp.rq_prod_idx |= 0x8000;
236 } else
237 ep->qp.rq_prod_idx |= hi_bit;
238
239 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
240 rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
241 rq_db->prod_idx = ep->qp.rq_prod_idx;
242 /* no need to ring hardware doorbell for 57710 */
243 } else {
244 writew(ep->qp.rq_prod_idx,
245 ep->qp.ctx_base + CNIC_RECV_DOORBELL);
246 }
247 mmiowb();
248}
249
250
251/**
252 * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
253 * @conn: iscsi connection to which new SQ entries belong
254 * @count: number of SQ WQEs to post
255 *
256 * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
257 * of devices. For 5706/5708/5709 new SQ WQE count is written into the
258 * doorbell register
259 */
260static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
261{
262 struct bnx2i_5771x_sq_rq_db *sq_db;
263 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
264
265 ep->num_active_cmds++;
266 wmb(); /* flush SQ WQE memory before the doorbell is rung */
267 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
268 sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
269 sq_db->prod_idx = ep->qp.sq_prod_idx;
270 bnx2i_ring_577xx_doorbell(bnx2i_conn);
271 } else
272 writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
273
274 mmiowb(); /* flush posted PCI writes */
275}
276
277
278/**
279 * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
280 * @conn: iscsi connection to which new SQ entries belong
281 * @count: number of SQ WQEs to post
282 *
283 * this routine will update SQ driver parameters and ring the doorbell
284 */
285static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
286 int count)
287{
288 int tmp_cnt;
289
290 if (count == 1) {
291 if (bnx2i_conn->ep->qp.sq_prod_qe ==
292 bnx2i_conn->ep->qp.sq_last_qe)
293 bnx2i_conn->ep->qp.sq_prod_qe =
294 bnx2i_conn->ep->qp.sq_first_qe;
295 else
296 bnx2i_conn->ep->qp.sq_prod_qe++;
297 } else {
298 if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
299 bnx2i_conn->ep->qp.sq_last_qe)
300 bnx2i_conn->ep->qp.sq_prod_qe += count;
301 else {
302 tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
303 bnx2i_conn->ep->qp.sq_prod_qe;
304 bnx2i_conn->ep->qp.sq_prod_qe =
305 &bnx2i_conn->ep->qp.sq_first_qe[count -
306 (tmp_cnt + 1)];
307 }
308 }
309 bnx2i_conn->ep->qp.sq_prod_idx += count;
310 /* Ring the doorbell */
311 bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
312}
313
314
315/**
316 * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
317 * @conn: iscsi connection
318 * @cmd: driver command structure which is requesting
319 * a WQE to sent to chip for further processing
320 *
321 * prepare and post an iSCSI Login request WQE to CNIC firmware
322 */
323int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
324 struct iscsi_task *task)
325{
326 struct bnx2i_cmd *bnx2i_cmd;
327 struct bnx2i_login_request *login_wqe;
328 struct iscsi_login *login_hdr;
329 u32 dword;
330
331 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
332 login_hdr = (struct iscsi_login *)task->hdr;
333 login_wqe = (struct bnx2i_login_request *)
334 bnx2i_conn->ep->qp.sq_prod_qe;
335
336 login_wqe->op_code = login_hdr->opcode;
337 login_wqe->op_attr = login_hdr->flags;
338 login_wqe->version_max = login_hdr->max_version;
339 login_wqe->version_min = login_hdr->min_version;
340 login_wqe->data_length = ntoh24(login_hdr->dlength);
341 login_wqe->isid_lo = *((u32 *) login_hdr->isid);
342 login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
343 login_wqe->tsih = login_hdr->tsih;
344 login_wqe->itt = task->itt |
345 (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
346 login_wqe->cid = login_hdr->cid;
347
348 login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
349 login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
Anil Veerabhadrappa2e15efc2010-03-25 10:54:40 -0700350 login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
Michael Chancf4e6362009-06-08 18:14:44 -0700351
352 login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
353 login_wqe->resp_bd_list_addr_hi =
354 (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
355
356 dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
357 (bnx2i_conn->gen_pdu.resp_buf_size <<
358 ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
359 login_wqe->resp_buffer = dword;
Michael Chancf4e6362009-06-08 18:14:44 -0700360 login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
361 login_wqe->bd_list_addr_hi =
362 (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
363 login_wqe->num_bds = 1;
364 login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
365
366 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
367 return 0;
368}
369
370/**
371 * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
372 * @conn: iscsi connection
373 * @mtask: driver command structure which is requesting
374 * a WQE to sent to chip for further processing
375 *
376 * prepare and post an iSCSI Login request WQE to CNIC firmware
377 */
378int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
379 struct iscsi_task *mtask)
380{
381 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
382 struct iscsi_tm *tmfabort_hdr;
383 struct scsi_cmnd *ref_sc;
384 struct iscsi_task *ctask;
385 struct bnx2i_cmd *bnx2i_cmd;
386 struct bnx2i_tmf_request *tmfabort_wqe;
387 u32 dword;
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800388 u32 scsi_lun[2];
Michael Chancf4e6362009-06-08 18:14:44 -0700389
390 bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
391 tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
392 tmfabort_wqe = (struct bnx2i_tmf_request *)
393 bnx2i_conn->ep->qp.sq_prod_qe;
394
395 tmfabort_wqe->op_code = tmfabort_hdr->opcode;
396 tmfabort_wqe->op_attr = 0;
397 tmfabort_wqe->op_attr =
398 ISCSI_TMF_REQUEST_ALWAYS_ONE | ISCSI_TM_FUNC_ABORT_TASK;
Michael Chancf4e6362009-06-08 18:14:44 -0700399
400 tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
401 tmfabort_wqe->reserved2 = 0;
402 tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
403
404 ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800405 if (!ctask || !ctask->sc)
Michael Chancf4e6362009-06-08 18:14:44 -0700406 /*
407 * the iscsi layer must have completed the cmd while this
408 * was starting up.
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800409 *
410 * Note: In the case of a SCSI cmd timeout, the task's sc
411 * is still active; hence ctask->sc != 0
412 * In this case, the task must be aborted
Michael Chancf4e6362009-06-08 18:14:44 -0700413 */
414 return 0;
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800415
Michael Chancf4e6362009-06-08 18:14:44 -0700416 ref_sc = ctask->sc;
417
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800418 /* Retrieve LUN directly from the ref_sc */
419 int_to_scsilun(ref_sc->device->lun, (struct scsi_lun *) scsi_lun);
420 tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
421 tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
422
Michael Chancf4e6362009-06-08 18:14:44 -0700423 if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
424 dword = (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
425 else
426 dword = (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800427 tmfabort_wqe->ref_itt = (dword | (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
Michael Chancf4e6362009-06-08 18:14:44 -0700428 tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
429
430 tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
431 tmfabort_wqe->bd_list_addr_hi = (u32)
432 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
433 tmfabort_wqe->num_bds = 1;
434 tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
435
436 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
437 return 0;
438}
439
440/**
441 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
442 * @conn: iscsi connection
443 * @cmd: driver command structure which is requesting
444 * a WQE to sent to chip for further processing
445 *
446 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
447 */
448int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
449 struct bnx2i_cmd *cmd)
450{
451 struct bnx2i_cmd_request *scsi_cmd_wqe;
452
453 scsi_cmd_wqe = (struct bnx2i_cmd_request *)
454 bnx2i_conn->ep->qp.sq_prod_qe;
455 memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
456 scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
457
458 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
459 return 0;
460}
461
462/**
463 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
464 * @conn: iscsi connection
465 * @cmd: driver command structure which is requesting
466 * a WQE to sent to chip for further processing
Michael Chancf4e6362009-06-08 18:14:44 -0700467 * @datap: payload buffer pointer
468 * @data_len: payload data length
469 * @unsol: indicated whether nopout pdu is unsolicited pdu or
470 * in response to target's NOPIN w/ TTT != FFFFFFFF
471 *
472 * prepare and post a nopout request WQE to CNIC firmware
473 */
474int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
Eddie Wai39304072010-08-12 16:44:27 -0700475 struct iscsi_task *task,
Michael Chancf4e6362009-06-08 18:14:44 -0700476 char *datap, int data_len, int unsol)
477{
478 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
479 struct bnx2i_cmd *bnx2i_cmd;
480 struct bnx2i_nop_out_request *nopout_wqe;
481 struct iscsi_nopout *nopout_hdr;
482
483 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
484 nopout_hdr = (struct iscsi_nopout *)task->hdr;
485 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
486 nopout_wqe->op_code = nopout_hdr->opcode;
487 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
488 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
489
490 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
491 u32 tmp = nopout_hdr->lun[0];
492 /* 57710 requires LUN field to be swapped */
493 nopout_hdr->lun[0] = nopout_hdr->lun[1];
494 nopout_hdr->lun[1] = tmp;
495 }
496
497 nopout_wqe->itt = ((u16)task->itt |
498 (ISCSI_TASK_TYPE_MPATH <<
499 ISCSI_TMF_REQUEST_TYPE_SHIFT));
Eddie Wai39304072010-08-12 16:44:27 -0700500 nopout_wqe->ttt = nopout_hdr->ttt;
Michael Chancf4e6362009-06-08 18:14:44 -0700501 nopout_wqe->flags = 0;
502 if (!unsol)
503 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
504 else if (nopout_hdr->itt == RESERVED_ITT)
505 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
506
507 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
508 nopout_wqe->data_length = data_len;
509 if (data_len) {
510 /* handle payload data, not required in first release */
511 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
512 } else {
513 nopout_wqe->bd_list_addr_lo = (u32)
514 bnx2i_conn->hba->mp_bd_dma;
515 nopout_wqe->bd_list_addr_hi =
516 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
517 nopout_wqe->num_bds = 1;
518 }
519 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
520
521 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
522 return 0;
523}
524
525
526/**
527 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
528 * @conn: iscsi connection
529 * @cmd: driver command structure which is requesting
530 * a WQE to sent to chip for further processing
531 *
532 * prepare and post logout request WQE to CNIC firmware
533 */
534int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
535 struct iscsi_task *task)
536{
537 struct bnx2i_cmd *bnx2i_cmd;
538 struct bnx2i_logout_request *logout_wqe;
539 struct iscsi_logout *logout_hdr;
540
541 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
542 logout_hdr = (struct iscsi_logout *)task->hdr;
543
544 logout_wqe = (struct bnx2i_logout_request *)
545 bnx2i_conn->ep->qp.sq_prod_qe;
546 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
547
548 logout_wqe->op_code = logout_hdr->opcode;
549 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
550 logout_wqe->op_attr =
551 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
552 logout_wqe->itt = ((u16)task->itt |
553 (ISCSI_TASK_TYPE_MPATH <<
554 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
555 logout_wqe->data_length = 0;
556 logout_wqe->cid = 0;
557
558 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
559 logout_wqe->bd_list_addr_hi = (u32)
560 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
561 logout_wqe->num_bds = 1;
562 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
563
Eddie Wai2eefb202010-07-01 15:34:54 -0700564 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
565
Michael Chancf4e6362009-06-08 18:14:44 -0700566 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
567 return 0;
568}
569
570
571/**
572 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
573 * @conn: iscsi connection which requires iscsi parameter update
574 *
575 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
576 */
577void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
578{
579 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
580 struct bnx2i_hba *hba = bnx2i_conn->hba;
581 struct kwqe *kwqe_arr[2];
582 struct iscsi_kwqe_conn_update *update_wqe;
583 struct iscsi_kwqe_conn_update conn_update_kwqe;
584
585 update_wqe = &conn_update_kwqe;
586
587 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
588 update_wqe->hdr.flags =
589 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
590
591 /* 5771x requires conn context id to be passed as is */
592 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
593 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
594 else
595 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
596 update_wqe->conn_flags = 0;
597 if (conn->hdrdgst_en)
598 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
599 if (conn->datadgst_en)
600 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
601 if (conn->session->initial_r2t_en)
602 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
603 if (conn->session->imm_data_en)
604 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
605
606 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
607 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
608 update_wqe->first_burst_length = conn->session->first_burst;
609 update_wqe->max_burst_length = conn->session->max_burst;
610 update_wqe->exp_stat_sn = conn->exp_statsn;
611 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
612 update_wqe->session_error_recovery_level = conn->session->erl;
613 iscsi_conn_printk(KERN_ALERT, conn,
614 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
615 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
616 update_wqe->max_burst_length,
617 update_wqe->first_burst_length,
618 update_wqe->max_recv_pdu_length,
619 update_wqe->max_send_pdu_length);
620
621 kwqe_arr[0] = (struct kwqe *) update_wqe;
622 if (hba->cnic && hba->cnic->submit_kwqes)
623 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
624}
625
626
627/**
628 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
629 * @data: endpoint (transport handle) structure pointer
630 *
631 * routine to handle connection offload/destroy request timeout
632 */
633void bnx2i_ep_ofld_timer(unsigned long data)
634{
635 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
636
637 if (ep->state == EP_STATE_OFLD_START) {
638 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
639 ep->state = EP_STATE_OFLD_FAILED;
640 } else if (ep->state == EP_STATE_DISCONN_START) {
641 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
642 ep->state = EP_STATE_DISCONN_TIMEDOUT;
643 } else if (ep->state == EP_STATE_CLEANUP_START) {
644 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
645 ep->state = EP_STATE_CLEANUP_FAILED;
646 }
647
648 wake_up_interruptible(&ep->ofld_wait);
649}
650
651
652static int bnx2i_power_of2(u32 val)
653{
654 u32 power = 0;
655 if (val & (val - 1))
656 return power;
657 val--;
658 while (val) {
659 val = val >> 1;
660 power++;
661 }
662 return power;
663}
664
665
666/**
667 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
668 * @hba: adapter structure pointer
669 * @cmd: driver command structure which is requesting
670 * a WQE to sent to chip for further processing
671 *
672 * prepares and posts CONN_OFLD_REQ1/2 KWQE
673 */
674void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
675{
676 struct bnx2i_cleanup_request *cmd_cleanup;
677
678 cmd_cleanup =
679 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
680 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
681
682 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
683 cmd_cleanup->itt = cmd->req.itt;
684 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
685
686 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
687}
688
689
690/**
691 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
692 * @hba: adapter structure pointer
693 * @ep: endpoint (transport indentifier) structure
694 *
695 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
696 * iscsi connection context clean-up process
697 */
698void bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
699{
700 struct kwqe *kwqe_arr[2];
701 struct iscsi_kwqe_conn_destroy conn_cleanup;
702
703 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
704
705 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
706 conn_cleanup.hdr.flags =
707 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
708 /* 5771x requires conn context id to be passed as is */
709 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
710 conn_cleanup.context_id = ep->ep_cid;
711 else
712 conn_cleanup.context_id = (ep->ep_cid >> 7);
713
714 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
715
716 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
717 if (hba->cnic && hba->cnic->submit_kwqes)
718 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
719}
720
721
722/**
723 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
724 * @hba: adapter structure pointer
725 * @ep: endpoint (transport indentifier) structure
726 *
727 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
728 */
729static void bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
730 struct bnx2i_endpoint *ep)
731{
732 struct kwqe *kwqe_arr[2];
733 struct iscsi_kwqe_conn_offload1 ofld_req1;
734 struct iscsi_kwqe_conn_offload2 ofld_req2;
735 dma_addr_t dma_addr;
736 int num_kwqes = 2;
737 u32 *ptbl;
738
739 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
740 ofld_req1.hdr.flags =
741 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
742
743 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
744
745 dma_addr = ep->qp.sq_pgtbl_phys;
746 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
747 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
748
749 dma_addr = ep->qp.cq_pgtbl_phys;
750 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
751 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
752
753 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
754 ofld_req2.hdr.flags =
755 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
756
757 dma_addr = ep->qp.rq_pgtbl_phys;
758 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
759 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
760
761 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
762
763 ofld_req2.sq_first_pte.hi = *ptbl++;
764 ofld_req2.sq_first_pte.lo = *ptbl;
765
766 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
767 ofld_req2.cq_first_pte.hi = *ptbl++;
768 ofld_req2.cq_first_pte.lo = *ptbl;
769
770 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
771 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
772 ofld_req2.num_additional_wqes = 0;
773
774 if (hba->cnic && hba->cnic->submit_kwqes)
775 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
776}
777
778
779/**
780 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
781 * @hba: adapter structure pointer
782 * @ep: endpoint (transport indentifier) structure
783 *
784 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
785 */
786static void bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
787 struct bnx2i_endpoint *ep)
788{
789 struct kwqe *kwqe_arr[5];
790 struct iscsi_kwqe_conn_offload1 ofld_req1;
791 struct iscsi_kwqe_conn_offload2 ofld_req2;
792 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
793 dma_addr_t dma_addr;
794 int num_kwqes = 2;
795 u32 *ptbl;
796
797 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
798 ofld_req1.hdr.flags =
799 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
800
801 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
802
803 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
804 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
805 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
806
807 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
808 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
809 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
810
811 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
812 ofld_req2.hdr.flags =
813 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
814
815 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
816 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
817 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
818
819 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
820 ofld_req2.sq_first_pte.hi = *ptbl++;
821 ofld_req2.sq_first_pte.lo = *ptbl;
822
823 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
824 ofld_req2.cq_first_pte.hi = *ptbl++;
825 ofld_req2.cq_first_pte.lo = *ptbl;
826
827 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
828 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
829
830 ofld_req2.num_additional_wqes = 1;
831 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
832 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
833 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
834 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
835
836 kwqe_arr[2] = (struct kwqe *) ofld_req3;
837 /* need if we decide to go with multiple KCQE's per conn */
838 num_kwqes += 1;
839
840 if (hba->cnic && hba->cnic->submit_kwqes)
841 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
842}
843
844/**
845 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
846 *
847 * @hba: adapter structure pointer
848 * @ep: endpoint (transport indentifier) structure
849 *
850 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
851 */
852void bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
853{
854 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
855 bnx2i_5771x_send_conn_ofld_req(hba, ep);
856 else
857 bnx2i_570x_send_conn_ofld_req(hba, ep);
858}
859
860
861/**
862 * setup_qp_page_tables - iscsi QP page table setup function
863 * @ep: endpoint (transport indentifier) structure
864 *
865 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
866 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
867 * PT in little endian format
868 */
869static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
870{
871 int num_pages;
872 u32 *ptbl;
873 dma_addr_t page;
874 int cnic_dev_10g;
875
876 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
877 cnic_dev_10g = 1;
878 else
879 cnic_dev_10g = 0;
880
881 /* SQ page table */
882 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
883 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
884 page = ep->qp.sq_phys;
885
886 if (cnic_dev_10g)
887 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
888 else
889 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
890 while (num_pages--) {
891 if (cnic_dev_10g) {
892 /* PTE is written in little endian format for 57710 */
893 *ptbl = (u32) page;
894 ptbl++;
895 *ptbl = (u32) ((u64) page >> 32);
896 ptbl++;
897 page += PAGE_SIZE;
898 } else {
899 /* PTE is written in big endian format for
900 * 5706/5708/5709 devices */
901 *ptbl = (u32) ((u64) page >> 32);
902 ptbl++;
903 *ptbl = (u32) page;
904 ptbl++;
905 page += PAGE_SIZE;
906 }
907 }
908
909 /* RQ page table */
910 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
911 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
912 page = ep->qp.rq_phys;
913
914 if (cnic_dev_10g)
915 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
916 else
917 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
918 while (num_pages--) {
919 if (cnic_dev_10g) {
920 /* PTE is written in little endian format for 57710 */
921 *ptbl = (u32) page;
922 ptbl++;
923 *ptbl = (u32) ((u64) page >> 32);
924 ptbl++;
925 page += PAGE_SIZE;
926 } else {
927 /* PTE is written in big endian format for
928 * 5706/5708/5709 devices */
929 *ptbl = (u32) ((u64) page >> 32);
930 ptbl++;
931 *ptbl = (u32) page;
932 ptbl++;
933 page += PAGE_SIZE;
934 }
935 }
936
937 /* CQ page table */
938 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
939 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
940 page = ep->qp.cq_phys;
941
942 if (cnic_dev_10g)
943 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
944 else
945 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
946 while (num_pages--) {
947 if (cnic_dev_10g) {
948 /* PTE is written in little endian format for 57710 */
949 *ptbl = (u32) page;
950 ptbl++;
951 *ptbl = (u32) ((u64) page >> 32);
952 ptbl++;
953 page += PAGE_SIZE;
954 } else {
955 /* PTE is written in big endian format for
956 * 5706/5708/5709 devices */
957 *ptbl = (u32) ((u64) page >> 32);
958 ptbl++;
959 *ptbl = (u32) page;
960 ptbl++;
961 page += PAGE_SIZE;
962 }
963 }
964}
965
966
967/**
968 * bnx2i_alloc_qp_resc - allocates required resources for QP.
969 * @hba: adapter structure pointer
970 * @ep: endpoint (transport indentifier) structure
971 *
972 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
973 * memory for SQ/RQ/CQ and page tables. EP structure elements such
974 * as producer/consumer indexes/pointers, queue sizes and page table
975 * contents are setup
976 */
977int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
978{
979 struct bnx2i_5771x_cq_db *cq_db;
980
981 ep->hba = hba;
982 ep->conn = NULL;
983 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
984
985 /* Allocate page table memory for SQ which is page aligned */
986 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
987 ep->qp.sq_mem_size =
988 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
989 ep->qp.sq_pgtbl_size =
990 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
991 ep->qp.sq_pgtbl_size =
992 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
993
994 ep->qp.sq_pgtbl_virt =
995 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
996 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
997 if (!ep->qp.sq_pgtbl_virt) {
998 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
999 ep->qp.sq_pgtbl_size);
1000 goto mem_alloc_err;
1001 }
1002
1003 /* Allocate memory area for actual SQ element */
1004 ep->qp.sq_virt =
1005 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1006 &ep->qp.sq_phys, GFP_KERNEL);
1007 if (!ep->qp.sq_virt) {
1008 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1009 ep->qp.sq_mem_size);
1010 goto mem_alloc_err;
1011 }
1012
1013 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1014 ep->qp.sq_first_qe = ep->qp.sq_virt;
1015 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1016 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1017 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1018 ep->qp.sq_prod_idx = 0;
1019 ep->qp.sq_cons_idx = 0;
1020 ep->qp.sqe_left = hba->max_sqes;
1021
1022 /* Allocate page table memory for CQ which is page aligned */
1023 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1024 ep->qp.cq_mem_size =
1025 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1026 ep->qp.cq_pgtbl_size =
1027 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1028 ep->qp.cq_pgtbl_size =
1029 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1030
1031 ep->qp.cq_pgtbl_virt =
1032 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1033 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1034 if (!ep->qp.cq_pgtbl_virt) {
1035 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1036 ep->qp.cq_pgtbl_size);
1037 goto mem_alloc_err;
1038 }
1039
1040 /* Allocate memory area for actual CQ element */
1041 ep->qp.cq_virt =
1042 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1043 &ep->qp.cq_phys, GFP_KERNEL);
1044 if (!ep->qp.cq_virt) {
1045 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1046 ep->qp.cq_mem_size);
1047 goto mem_alloc_err;
1048 }
1049 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1050
1051 ep->qp.cq_first_qe = ep->qp.cq_virt;
1052 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1053 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1054 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1055 ep->qp.cq_prod_idx = 0;
1056 ep->qp.cq_cons_idx = 0;
1057 ep->qp.cqe_left = hba->max_cqes;
1058 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1059 ep->qp.cqe_size = hba->max_cqes;
1060
1061 /* Invalidate all EQ CQE index, req only for 57710 */
1062 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1063 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1064
1065 /* Allocate page table memory for RQ which is page aligned */
1066 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1067 ep->qp.rq_mem_size =
1068 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1069 ep->qp.rq_pgtbl_size =
1070 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1071 ep->qp.rq_pgtbl_size =
1072 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1073
1074 ep->qp.rq_pgtbl_virt =
1075 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1076 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1077 if (!ep->qp.rq_pgtbl_virt) {
1078 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1079 ep->qp.rq_pgtbl_size);
1080 goto mem_alloc_err;
1081 }
1082
1083 /* Allocate memory area for actual RQ element */
1084 ep->qp.rq_virt =
1085 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1086 &ep->qp.rq_phys, GFP_KERNEL);
1087 if (!ep->qp.rq_virt) {
1088 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1089 ep->qp.rq_mem_size);
1090 goto mem_alloc_err;
1091 }
1092
1093 ep->qp.rq_first_qe = ep->qp.rq_virt;
1094 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1095 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1096 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1097 ep->qp.rq_prod_idx = 0x8000;
1098 ep->qp.rq_cons_idx = 0;
1099 ep->qp.rqe_left = hba->max_rqes;
1100
1101 setup_qp_page_tables(ep);
1102
1103 return 0;
1104
1105mem_alloc_err:
1106 bnx2i_free_qp_resc(hba, ep);
1107 return -ENOMEM;
1108}
1109
1110
1111
1112/**
1113 * bnx2i_free_qp_resc - free memory resources held by QP
1114 * @hba: adapter structure pointer
1115 * @ep: endpoint (transport indentifier) structure
1116 *
1117 * Free QP resources - SQ/RQ/CQ memory and page tables.
1118 */
1119void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1120{
1121 if (ep->qp.ctx_base) {
1122 iounmap(ep->qp.ctx_base);
1123 ep->qp.ctx_base = NULL;
1124 }
1125 /* Free SQ mem */
1126 if (ep->qp.sq_pgtbl_virt) {
1127 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1128 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1129 ep->qp.sq_pgtbl_virt = NULL;
1130 ep->qp.sq_pgtbl_phys = 0;
1131 }
1132 if (ep->qp.sq_virt) {
1133 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1134 ep->qp.sq_virt, ep->qp.sq_phys);
1135 ep->qp.sq_virt = NULL;
1136 ep->qp.sq_phys = 0;
1137 }
1138
1139 /* Free RQ mem */
1140 if (ep->qp.rq_pgtbl_virt) {
1141 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1142 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1143 ep->qp.rq_pgtbl_virt = NULL;
1144 ep->qp.rq_pgtbl_phys = 0;
1145 }
1146 if (ep->qp.rq_virt) {
1147 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1148 ep->qp.rq_virt, ep->qp.rq_phys);
1149 ep->qp.rq_virt = NULL;
1150 ep->qp.rq_phys = 0;
1151 }
1152
1153 /* Free CQ mem */
1154 if (ep->qp.cq_pgtbl_virt) {
1155 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1156 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1157 ep->qp.cq_pgtbl_virt = NULL;
1158 ep->qp.cq_pgtbl_phys = 0;
1159 }
1160 if (ep->qp.cq_virt) {
1161 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1162 ep->qp.cq_virt, ep->qp.cq_phys);
1163 ep->qp.cq_virt = NULL;
1164 ep->qp.cq_phys = 0;
1165 }
1166}
1167
1168
1169/**
1170 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1171 * @hba: adapter structure pointer
1172 *
1173 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1174 * This results in iSCSi support validation and on-chip context manager
1175 * initialization. Firmware completes this handshake with a CQE carrying
1176 * the result of iscsi support validation. Parameter carried by
1177 * iscsi init request determines the number of offloaded connection and
1178 * tolerance level for iscsi protocol violation this hba/chip can support
1179 */
1180int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1181{
1182 struct kwqe *kwqe_arr[3];
1183 struct iscsi_kwqe_init1 iscsi_init;
1184 struct iscsi_kwqe_init2 iscsi_init2;
1185 int rc = 0;
1186 u64 mask64;
1187
1188 bnx2i_adjust_qp_size(hba);
1189
1190 iscsi_init.flags =
1191 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1192 if (en_tcp_dack)
1193 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1194 iscsi_init.reserved0 = 0;
1195 iscsi_init.num_cqs = 1;
1196 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1197 iscsi_init.hdr.flags =
1198 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1199
1200 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1201 iscsi_init.dummy_buffer_addr_hi =
1202 (u32) ((u64) hba->dummy_buf_dma >> 32);
1203
1204 hba->ctx_ccell_tasks =
1205 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1206 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1207 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1208 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1209 iscsi_init.sq_num_wqes = hba->max_sqes;
1210 iscsi_init.cq_log_wqes_per_page =
1211 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1212 iscsi_init.cq_num_wqes = hba->max_cqes;
1213 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1214 (PAGE_SIZE - 1)) / PAGE_SIZE;
1215 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1216 (PAGE_SIZE - 1)) / PAGE_SIZE;
1217 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1218 iscsi_init.rq_num_wqes = hba->max_rqes;
1219
1220
1221 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1222 iscsi_init2.hdr.flags =
1223 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1224 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1225 mask64 = 0x0ULL;
1226 mask64 |= (
1227 /* CISCO MDS */
1228 (1UL <<
1229 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1230 /* HP MSA1510i */
1231 (1UL <<
1232 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1233 /* EMC */
1234 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1235 if (error_mask1)
1236 iscsi_init2.error_bit_map[0] = error_mask1;
1237 else
1238 iscsi_init2.error_bit_map[0] = (u32) mask64;
1239
1240 if (error_mask2)
1241 iscsi_init2.error_bit_map[1] = error_mask2;
1242 else
1243 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1244
1245 iscsi_error_mask = mask64;
1246
1247 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1248 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1249
1250 if (hba->cnic && hba->cnic->submit_kwqes)
1251 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1252 return rc;
1253}
1254
1255
1256/**
1257 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1258 * @conn: iscsi connection
1259 * @cqe: pointer to newly DMA'ed CQE entry for processing
1260 *
1261 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1262 */
1263static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1264 struct bnx2i_conn *bnx2i_conn,
1265 struct cqe *cqe)
1266{
1267 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1268 struct bnx2i_cmd_response *resp_cqe;
1269 struct bnx2i_cmd *bnx2i_cmd;
1270 struct iscsi_task *task;
1271 struct iscsi_cmd_rsp *hdr;
1272 u32 datalen = 0;
1273
1274 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1275 spin_lock(&session->lock);
1276 task = iscsi_itt_to_task(conn,
1277 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1278 if (!task)
1279 goto fail;
1280
1281 bnx2i_cmd = task->dd_data;
1282
1283 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1284 conn->datain_pdus_cnt +=
1285 resp_cqe->task_stat.read_stat.num_data_outs;
1286 conn->rxdata_octets +=
1287 bnx2i_cmd->req.total_data_transfer_length;
1288 } else {
1289 conn->dataout_pdus_cnt +=
1290 resp_cqe->task_stat.read_stat.num_data_outs;
1291 conn->r2t_pdus_cnt +=
1292 resp_cqe->task_stat.read_stat.num_r2ts;
1293 conn->txdata_octets +=
1294 bnx2i_cmd->req.total_data_transfer_length;
1295 }
1296 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1297
1298 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1299 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1300 hdr->opcode = resp_cqe->op_code;
1301 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1302 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1303 hdr->response = resp_cqe->response;
1304 hdr->cmd_status = resp_cqe->status;
1305 hdr->flags = resp_cqe->response_flags;
1306 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1307
1308 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1309 goto done;
1310
1311 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1312 datalen = resp_cqe->data_length;
1313 if (datalen < 2)
1314 goto done;
1315
1316 if (datalen > BNX2I_RQ_WQE_SIZE) {
1317 iscsi_conn_printk(KERN_ERR, conn,
1318 "sense data len %d > RQ sz\n",
1319 datalen);
1320 datalen = BNX2I_RQ_WQE_SIZE;
1321 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1322 iscsi_conn_printk(KERN_ERR, conn,
1323 "sense data len %d > conn data\n",
1324 datalen);
1325 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1326 }
1327
1328 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1329 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1330 }
1331
1332done:
1333 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1334 conn->data, datalen);
1335fail:
1336 spin_unlock(&session->lock);
1337 return 0;
1338}
1339
1340
1341/**
1342 * bnx2i_process_login_resp - this function handles iscsi login response
1343 * @session: iscsi session pointer
1344 * @bnx2i_conn: iscsi connection pointer
1345 * @cqe: pointer to newly DMA'ed CQE entry for processing
1346 *
1347 * process Login Response CQE & complete it to open-iscsi user daemon
1348 */
1349static int bnx2i_process_login_resp(struct iscsi_session *session,
1350 struct bnx2i_conn *bnx2i_conn,
1351 struct cqe *cqe)
1352{
1353 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1354 struct iscsi_task *task;
1355 struct bnx2i_login_response *login;
1356 struct iscsi_login_rsp *resp_hdr;
1357 int pld_len;
1358 int pad_len;
1359
1360 login = (struct bnx2i_login_response *) cqe;
1361 spin_lock(&session->lock);
1362 task = iscsi_itt_to_task(conn,
1363 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1364 if (!task)
1365 goto done;
1366
1367 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1368 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1369 resp_hdr->opcode = login->op_code;
1370 resp_hdr->flags = login->response_flags;
1371 resp_hdr->max_version = login->version_max;
Joe Perchesa419aef2009-08-18 11:18:35 -07001372 resp_hdr->active_version = login->version_active;
Michael Chancf4e6362009-06-08 18:14:44 -07001373 resp_hdr->hlength = 0;
1374
1375 hton24(resp_hdr->dlength, login->data_length);
1376 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1377 resp_hdr->tsih = cpu_to_be16(login->tsih);
1378 resp_hdr->itt = task->hdr->itt;
1379 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1380 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1381 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1382 resp_hdr->status_class = login->status_class;
1383 resp_hdr->status_detail = login->status_detail;
1384 pld_len = login->data_length;
1385 bnx2i_conn->gen_pdu.resp_wr_ptr =
1386 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1387
1388 pad_len = 0;
1389 if (pld_len & 0x3)
1390 pad_len = 4 - (pld_len % 4);
1391
1392 if (pad_len) {
1393 int i = 0;
1394 for (i = 0; i < pad_len; i++) {
1395 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1396 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1397 }
1398 }
1399
1400 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1401 bnx2i_conn->gen_pdu.resp_buf,
1402 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1403done:
1404 spin_unlock(&session->lock);
1405 return 0;
1406}
1407
1408/**
1409 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1410 * @session: iscsi session pointer
1411 * @bnx2i_conn: iscsi connection pointer
1412 * @cqe: pointer to newly DMA'ed CQE entry for processing
1413 *
1414 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1415 */
1416static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1417 struct bnx2i_conn *bnx2i_conn,
1418 struct cqe *cqe)
1419{
1420 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1421 struct iscsi_task *task;
1422 struct bnx2i_tmf_response *tmf_cqe;
1423 struct iscsi_tm_rsp *resp_hdr;
1424
1425 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1426 spin_lock(&session->lock);
1427 task = iscsi_itt_to_task(conn,
1428 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1429 if (!task)
1430 goto done;
1431
1432 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1433 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1434 resp_hdr->opcode = tmf_cqe->op_code;
1435 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1436 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1437 resp_hdr->itt = task->hdr->itt;
1438 resp_hdr->response = tmf_cqe->response;
1439
1440 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1441done:
1442 spin_unlock(&session->lock);
1443 return 0;
1444}
1445
1446/**
1447 * bnx2i_process_logout_resp - this function handles iscsi logout response
1448 * @session: iscsi session pointer
1449 * @bnx2i_conn: iscsi connection pointer
1450 * @cqe: pointer to newly DMA'ed CQE entry for processing
1451 *
1452 * process iSCSI Logout Response CQE & make function call to
1453 * notify the user daemon.
1454 */
1455static int bnx2i_process_logout_resp(struct iscsi_session *session,
1456 struct bnx2i_conn *bnx2i_conn,
1457 struct cqe *cqe)
1458{
1459 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1460 struct iscsi_task *task;
1461 struct bnx2i_logout_response *logout;
1462 struct iscsi_logout_rsp *resp_hdr;
1463
1464 logout = (struct bnx2i_logout_response *) cqe;
1465 spin_lock(&session->lock);
1466 task = iscsi_itt_to_task(conn,
1467 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1468 if (!task)
1469 goto done;
1470
1471 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1472 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1473 resp_hdr->opcode = logout->op_code;
1474 resp_hdr->flags = logout->response;
1475 resp_hdr->hlength = 0;
1476
1477 resp_hdr->itt = task->hdr->itt;
1478 resp_hdr->statsn = task->hdr->exp_statsn;
1479 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1480 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1481
1482 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1483 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1484
1485 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
Eddie Wai2eefb202010-07-01 15:34:54 -07001486
1487 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
Michael Chancf4e6362009-06-08 18:14:44 -07001488done:
1489 spin_unlock(&session->lock);
1490 return 0;
1491}
1492
1493/**
1494 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1495 * @session: iscsi session pointer
1496 * @bnx2i_conn: iscsi connection pointer
1497 * @cqe: pointer to newly DMA'ed CQE entry for processing
1498 *
1499 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1500 */
1501static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1502 struct bnx2i_conn *bnx2i_conn,
1503 struct cqe *cqe)
1504{
1505 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1506 struct bnx2i_nop_in_msg *nop_in;
1507 struct iscsi_task *task;
1508
1509 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1510 spin_lock(&session->lock);
1511 task = iscsi_itt_to_task(conn,
1512 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1513 if (task)
1514 iscsi_put_task(task);
1515 spin_unlock(&session->lock);
1516}
1517
1518/**
1519 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1520 * @conn: iscsi connection
1521 *
1522 * Firmware advances RQ producer index for every unsolicited PDU even if
1523 * payload data length is '0'. This function makes corresponding
1524 * adjustments on the driver side to match this f/w behavior
1525 */
1526static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1527{
1528 char dummy_rq_data[2];
1529 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1530 bnx2i_put_rq_buf(bnx2i_conn, 1);
1531}
1532
1533
1534/**
1535 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1536 * @session: iscsi session pointer
1537 * @bnx2i_conn: iscsi connection pointer
1538 * @cqe: pointer to newly DMA'ed CQE entry for processing
1539 *
1540 * process iSCSI target's proactive iSCSI NOPIN request
1541 */
1542static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1543 struct bnx2i_conn *bnx2i_conn,
1544 struct cqe *cqe)
1545{
1546 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1547 struct iscsi_task *task;
1548 struct bnx2i_nop_in_msg *nop_in;
1549 struct iscsi_nopin *hdr;
1550 u32 itt;
1551 int tgt_async_nop = 0;
1552
1553 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1554 itt = nop_in->itt & ISCSI_NOP_IN_MSG_INDEX;
1555
1556 spin_lock(&session->lock);
1557 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1558 memset(hdr, 0, sizeof(struct iscsi_hdr));
1559 hdr->opcode = nop_in->op_code;
1560 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1561 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1562 hdr->ttt = cpu_to_be32(nop_in->ttt);
1563
1564 if (itt == (u16) RESERVED_ITT) {
1565 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1566 hdr->itt = RESERVED_ITT;
1567 tgt_async_nop = 1;
1568 goto done;
1569 }
1570
1571 /* this is a response to one of our nop-outs */
1572 task = iscsi_itt_to_task(conn, itt);
1573 if (task) {
1574 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1575 hdr->itt = task->hdr->itt;
1576 hdr->ttt = cpu_to_be32(nop_in->ttt);
1577 memcpy(hdr->lun, nop_in->lun, 8);
1578 }
1579done:
1580 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1581 spin_unlock(&session->lock);
1582
1583 return tgt_async_nop;
1584}
1585
1586
1587/**
1588 * bnx2i_process_async_mesg - this function handles iscsi async message
1589 * @session: iscsi session pointer
1590 * @bnx2i_conn: iscsi connection pointer
1591 * @cqe: pointer to newly DMA'ed CQE entry for processing
1592 *
1593 * process iSCSI ASYNC Message
1594 */
1595static void bnx2i_process_async_mesg(struct iscsi_session *session,
1596 struct bnx2i_conn *bnx2i_conn,
1597 struct cqe *cqe)
1598{
1599 struct bnx2i_async_msg *async_cqe;
1600 struct iscsi_async *resp_hdr;
1601 u8 async_event;
1602
1603 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1604
1605 async_cqe = (struct bnx2i_async_msg *)cqe;
1606 async_event = async_cqe->async_event;
1607
1608 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1609 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1610 "async: scsi events not supported\n");
1611 return;
1612 }
1613
1614 spin_lock(&session->lock);
1615 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1616 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1617 resp_hdr->opcode = async_cqe->op_code;
1618 resp_hdr->flags = 0x80;
1619
1620 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1621 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1622 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1623
1624 resp_hdr->async_event = async_cqe->async_event;
1625 resp_hdr->async_vcode = async_cqe->async_vcode;
1626
1627 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1628 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1629 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1630
1631 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1632 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1633 spin_unlock(&session->lock);
1634}
1635
1636
1637/**
1638 * bnx2i_process_reject_mesg - process iscsi reject pdu
1639 * @session: iscsi session pointer
1640 * @bnx2i_conn: iscsi connection pointer
1641 * @cqe: pointer to newly DMA'ed CQE entry for processing
1642 *
1643 * process iSCSI REJECT message
1644 */
1645static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1646 struct bnx2i_conn *bnx2i_conn,
1647 struct cqe *cqe)
1648{
1649 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1650 struct bnx2i_reject_msg *reject;
1651 struct iscsi_reject *hdr;
1652
1653 reject = (struct bnx2i_reject_msg *) cqe;
1654 if (reject->data_length) {
1655 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1656 bnx2i_put_rq_buf(bnx2i_conn, 1);
1657 } else
1658 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1659
1660 spin_lock(&session->lock);
1661 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1662 memset(hdr, 0, sizeof(struct iscsi_hdr));
1663 hdr->opcode = reject->op_code;
1664 hdr->reason = reject->reason;
1665 hton24(hdr->dlength, reject->data_length);
1666 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1667 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1668 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1669 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1670 reject->data_length);
1671 spin_unlock(&session->lock);
1672}
1673
1674/**
1675 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1676 * @session: iscsi session pointer
1677 * @bnx2i_conn: iscsi connection pointer
1678 * @cqe: pointer to newly DMA'ed CQE entry for processing
1679 *
1680 * process command cleanup response CQE during conn shutdown or error recovery
1681 */
1682static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1683 struct bnx2i_conn *bnx2i_conn,
1684 struct cqe *cqe)
1685{
1686 struct bnx2i_cleanup_response *cmd_clean_rsp;
1687 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1688 struct iscsi_task *task;
1689
1690 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1691 spin_lock(&session->lock);
1692 task = iscsi_itt_to_task(conn,
1693 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1694 if (!task)
1695 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1696 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1697 spin_unlock(&session->lock);
1698 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1699}
1700
1701
1702
1703/**
1704 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1705 * @bnx2i_conn: iscsi connection
1706 *
1707 * this function is called by generic KCQ handler to process all pending CQE's
1708 */
1709static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1710{
1711 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1712 struct iscsi_session *session = conn->session;
1713 struct qp_info *qp = &bnx2i_conn->ep->qp;
1714 struct bnx2i_nop_in_msg *nopin;
1715 int tgt_async_msg;
1716
1717 while (1) {
1718 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1719 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1720 break;
1721
1722 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx)))
1723 break;
1724
1725 tgt_async_msg = 0;
1726
1727 switch (nopin->op_code) {
1728 case ISCSI_OP_SCSI_CMD_RSP:
1729 case ISCSI_OP_SCSI_DATA_IN:
1730 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1731 qp->cq_cons_qe);
1732 break;
1733 case ISCSI_OP_LOGIN_RSP:
1734 bnx2i_process_login_resp(session, bnx2i_conn,
1735 qp->cq_cons_qe);
1736 break;
1737 case ISCSI_OP_SCSI_TMFUNC_RSP:
1738 bnx2i_process_tmf_resp(session, bnx2i_conn,
1739 qp->cq_cons_qe);
1740 break;
1741 case ISCSI_OP_LOGOUT_RSP:
1742 bnx2i_process_logout_resp(session, bnx2i_conn,
1743 qp->cq_cons_qe);
1744 break;
1745 case ISCSI_OP_NOOP_IN:
1746 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1747 qp->cq_cons_qe))
1748 tgt_async_msg = 1;
1749 break;
1750 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1751 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1752 qp->cq_cons_qe);
1753 break;
1754 case ISCSI_OP_ASYNC_EVENT:
1755 bnx2i_process_async_mesg(session, bnx2i_conn,
1756 qp->cq_cons_qe);
1757 tgt_async_msg = 1;
1758 break;
1759 case ISCSI_OP_REJECT:
1760 bnx2i_process_reject_mesg(session, bnx2i_conn,
1761 qp->cq_cons_qe);
1762 break;
1763 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1764 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1765 qp->cq_cons_qe);
1766 break;
1767 default:
1768 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1769 nopin->op_code);
1770 }
1771
1772 if (!tgt_async_msg)
1773 bnx2i_conn->ep->num_active_cmds--;
1774
1775 /* clear out in production version only, till beta keep opcode
1776 * field intact, will be helpful in debugging (context dump)
1777 * nopin->op_code = 0;
1778 */
1779 qp->cqe_exp_seq_sn++;
1780 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1781 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1782
1783 if (qp->cq_cons_qe == qp->cq_last_qe) {
1784 qp->cq_cons_qe = qp->cq_first_qe;
1785 qp->cq_cons_idx = 0;
1786 } else {
1787 qp->cq_cons_qe++;
1788 qp->cq_cons_idx++;
1789 }
1790 }
1791 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1792}
1793
1794/**
1795 * bnx2i_fastpath_notification - process global event queue (KCQ)
1796 * @hba: adapter structure pointer
1797 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1798 *
1799 * Fast path event notification handler, KCQ entry carries context id
1800 * of the connection that has 1 or more pending CQ entries
1801 */
1802static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1803 struct iscsi_kcqe *new_cqe_kcqe)
1804{
1805 struct bnx2i_conn *conn;
1806 u32 iscsi_cid;
1807
1808 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1809 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1810
1811 if (!conn) {
1812 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1813 return;
1814 }
1815 if (!conn->ep) {
1816 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1817 return;
1818 }
1819
1820 bnx2i_process_new_cqes(conn);
1821}
1822
1823
1824/**
1825 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1826 * @hba: adapter structure pointer
1827 * @update_kcqe: kcqe pointer
1828 *
1829 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1830 */
1831static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1832 struct iscsi_kcqe *update_kcqe)
1833{
1834 struct bnx2i_conn *conn;
1835 u32 iscsi_cid;
1836
1837 iscsi_cid = update_kcqe->iscsi_conn_id;
1838 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1839
1840 if (!conn) {
1841 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1842 return;
1843 }
1844 if (!conn->ep) {
1845 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1846 return;
1847 }
1848
1849 if (update_kcqe->completion_status) {
1850 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1851 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
1852 } else
1853 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
1854
1855 wake_up_interruptible(&conn->ep->ofld_wait);
1856}
1857
1858
1859/**
1860 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1861 * @hba: adapter structure pointer
1862 * @bnx2i_conn: iscsi connection
1863 *
1864 * Add connection to recovery queue and schedule adapter eh worker
1865 */
1866static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
1867 struct bnx2i_conn *bnx2i_conn)
1868{
1869 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
1870 ISCSI_ERR_CONN_FAILED);
1871}
1872
1873
1874/**
1875 * bnx2i_process_tcp_error - process error notification on a given connection
1876 *
1877 * @hba: adapter structure pointer
1878 * @tcp_err: tcp error kcqe pointer
1879 *
1880 * handles tcp level error notifications from FW.
1881 */
1882static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
1883 struct iscsi_kcqe *tcp_err)
1884{
1885 struct bnx2i_conn *bnx2i_conn;
1886 u32 iscsi_cid;
1887
1888 iscsi_cid = tcp_err->iscsi_conn_id;
1889 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1890
1891 if (!bnx2i_conn) {
1892 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1893 return;
1894 }
1895
1896 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1897 iscsi_cid, tcp_err->completion_status);
1898 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
1899}
1900
1901
1902/**
1903 * bnx2i_process_iscsi_error - process error notification on a given connection
1904 * @hba: adapter structure pointer
1905 * @iscsi_err: iscsi error kcqe pointer
1906 *
1907 * handles iscsi error notifications from the FW. Firmware based in initial
1908 * handshake classifies iscsi protocol / TCP rfc violation into either
1909 * warning or error indications. If indication is of "Error" type, driver
1910 * will initiate session recovery for that connection/session. For
1911 * "Warning" type indication, driver will put out a system log message
1912 * (there will be only one message for each type for the life of the
1913 * session, this is to avoid un-necessarily overloading the system)
1914 */
1915static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
1916 struct iscsi_kcqe *iscsi_err)
1917{
1918 struct bnx2i_conn *bnx2i_conn;
1919 u32 iscsi_cid;
1920 char warn_notice[] = "iscsi_warning";
1921 char error_notice[] = "iscsi_error";
1922 char additional_notice[64];
1923 char *message;
1924 int need_recovery;
1925 u64 err_mask64;
1926
1927 iscsi_cid = iscsi_err->iscsi_conn_id;
1928 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1929 if (!bnx2i_conn) {
1930 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1931 return;
1932 }
1933
1934 err_mask64 = (0x1ULL << iscsi_err->completion_status);
1935
1936 if (err_mask64 & iscsi_error_mask) {
1937 need_recovery = 0;
1938 message = warn_notice;
1939 } else {
1940 need_recovery = 1;
1941 message = error_notice;
1942 }
1943
1944 switch (iscsi_err->completion_status) {
1945 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
1946 strcpy(additional_notice, "hdr digest err");
1947 break;
1948 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
1949 strcpy(additional_notice, "data digest err");
1950 break;
1951 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
1952 strcpy(additional_notice, "wrong opcode rcvd");
1953 break;
1954 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
1955 strcpy(additional_notice, "AHS len > 0 rcvd");
1956 break;
1957 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
1958 strcpy(additional_notice, "invalid ITT rcvd");
1959 break;
1960 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
1961 strcpy(additional_notice, "wrong StatSN rcvd");
1962 break;
1963 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
1964 strcpy(additional_notice, "wrong DataSN rcvd");
1965 break;
1966 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
1967 strcpy(additional_notice, "pend R2T violation");
1968 break;
1969 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
1970 strcpy(additional_notice, "ERL0, UO");
1971 break;
1972 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
1973 strcpy(additional_notice, "ERL0, U1");
1974 break;
1975 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
1976 strcpy(additional_notice, "ERL0, U2");
1977 break;
1978 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
1979 strcpy(additional_notice, "ERL0, U3");
1980 break;
1981 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
1982 strcpy(additional_notice, "ERL0, U4");
1983 break;
1984 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
1985 strcpy(additional_notice, "ERL0, U5");
1986 break;
1987 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
1988 strcpy(additional_notice, "ERL0, U6");
1989 break;
1990 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
1991 strcpy(additional_notice, "invalid resi len");
1992 break;
1993 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
1994 strcpy(additional_notice, "MRDSL violation");
1995 break;
1996 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
1997 strcpy(additional_notice, "F-bit not set");
1998 break;
1999 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2000 strcpy(additional_notice, "invalid TTT");
2001 break;
2002 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2003 strcpy(additional_notice, "invalid DataSN");
2004 break;
2005 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2006 strcpy(additional_notice, "burst len violation");
2007 break;
2008 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2009 strcpy(additional_notice, "buf offset violation");
2010 break;
2011 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2012 strcpy(additional_notice, "invalid LUN field");
2013 break;
2014 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2015 strcpy(additional_notice, "invalid R2TSN field");
2016 break;
2017#define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2018 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2019 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2020 strcpy(additional_notice, "invalid cmd len1");
2021 break;
2022#define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2023 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2024 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2025 strcpy(additional_notice, "invalid cmd len2");
2026 break;
2027 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2028 strcpy(additional_notice,
2029 "pend r2t exceeds MaxOutstandingR2T value");
2030 break;
2031 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2032 strcpy(additional_notice, "TTT is rsvd");
2033 break;
2034 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2035 strcpy(additional_notice, "MBL violation");
2036 break;
2037#define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2038 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2039 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2040 strcpy(additional_notice, "data seg len != 0");
2041 break;
2042 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2043 strcpy(additional_notice, "reject pdu len error");
2044 break;
2045 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2046 strcpy(additional_notice, "async pdu len error");
2047 break;
2048 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2049 strcpy(additional_notice, "nopin pdu len error");
2050 break;
2051#define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2052 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2053 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2054 strcpy(additional_notice, "pend r2t in cleanup");
2055 break;
2056
2057 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2058 strcpy(additional_notice, "IP fragments rcvd");
2059 break;
2060 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2061 strcpy(additional_notice, "IP options error");
2062 break;
2063 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2064 strcpy(additional_notice, "urgent flag error");
2065 break;
2066 default:
2067 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2068 iscsi_err->completion_status);
2069 }
2070
2071 if (need_recovery) {
2072 iscsi_conn_printk(KERN_ALERT,
2073 bnx2i_conn->cls_conn->dd_data,
2074 "bnx2i: %s - %s\n",
2075 message, additional_notice);
2076
2077 iscsi_conn_printk(KERN_ALERT,
2078 bnx2i_conn->cls_conn->dd_data,
2079 "conn_err - hostno %d conn %p, "
2080 "iscsi_cid %x cid %x\n",
2081 bnx2i_conn->hba->shost->host_no,
2082 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2083 bnx2i_conn->ep->ep_cid);
2084 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2085 } else
2086 if (!test_and_set_bit(iscsi_err->completion_status,
2087 (void *) &bnx2i_conn->violation_notified))
2088 iscsi_conn_printk(KERN_ALERT,
2089 bnx2i_conn->cls_conn->dd_data,
2090 "bnx2i: %s - %s\n",
2091 message, additional_notice);
2092}
2093
2094
2095/**
2096 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2097 * @hba: adapter structure pointer
2098 * @conn_destroy: conn destroy kcqe pointer
2099 *
2100 * handles connection destroy completion request.
2101 */
2102static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2103 struct iscsi_kcqe *conn_destroy)
2104{
2105 struct bnx2i_endpoint *ep;
2106
2107 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2108 if (!ep) {
2109 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2110 "offload request, unexpected complection\n");
2111 return;
2112 }
2113
2114 if (hba != ep->hba) {
2115 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2116 return;
2117 }
2118
2119 if (conn_destroy->completion_status) {
2120 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2121 ep->state = EP_STATE_CLEANUP_FAILED;
2122 } else
2123 ep->state = EP_STATE_CLEANUP_CMPL;
2124 wake_up_interruptible(&ep->ofld_wait);
2125}
2126
2127
2128/**
2129 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2130 * @hba: adapter structure pointer
2131 * @ofld_kcqe: conn offload kcqe pointer
2132 *
2133 * handles initial connection offload completion, ep_connect() thread is
2134 * woken-up to continue with LLP connect process
2135 */
2136static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2137 struct iscsi_kcqe *ofld_kcqe)
2138{
2139 u32 cid_addr;
2140 struct bnx2i_endpoint *ep;
2141 u32 cid_num;
2142
2143 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2144 if (!ep) {
2145 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2146 return;
2147 }
2148
2149 if (hba != ep->hba) {
2150 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2151 return;
2152 }
2153
2154 if (ofld_kcqe->completion_status) {
2155 if (ofld_kcqe->completion_status ==
2156 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
2157 printk(KERN_ALERT "bnx2i: unable to allocate"
2158 " iSCSI context resources\n");
2159 ep->state = EP_STATE_OFLD_FAILED;
2160 } else {
2161 ep->state = EP_STATE_OFLD_COMPL;
2162 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2163 cid_num = bnx2i_get_cid_num(ep);
2164 ep->ep_cid = cid_addr;
2165 ep->qp.ctx_base = NULL;
2166 }
2167 wake_up_interruptible(&ep->ofld_wait);
2168}
2169
2170/**
2171 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2172 * @hba: adapter structure pointer
2173 * @update_kcqe: kcqe pointer
2174 *
2175 * Generic KCQ event handler/dispatcher
2176 */
2177static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2178 u32 num_cqe)
2179{
2180 struct bnx2i_hba *hba = context;
2181 int i = 0;
2182 struct iscsi_kcqe *ikcqe = NULL;
2183
2184 while (i < num_cqe) {
2185 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2186
2187 if (ikcqe->op_code ==
2188 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2189 bnx2i_fastpath_notification(hba, ikcqe);
2190 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2191 bnx2i_process_ofld_cmpl(hba, ikcqe);
2192 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2193 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2194 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2195 if (ikcqe->completion_status !=
2196 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2197 bnx2i_iscsi_license_error(hba, ikcqe->\
2198 completion_status);
2199 else {
2200 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2201 bnx2i_get_link_state(hba);
2202 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2203 "ISCSI_INIT passed\n",
2204 (u8)hba->pcidev->bus->number,
2205 hba->pci_devno,
2206 (u8)hba->pci_func);
2207
2208
2209 }
2210 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2211 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2212 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2213 bnx2i_process_iscsi_error(hba, ikcqe);
2214 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2215 bnx2i_process_tcp_error(hba, ikcqe);
2216 else
2217 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2218 ikcqe->op_code);
2219 }
2220}
2221
2222
2223/**
2224 * bnx2i_indicate_netevent - Generic netdev event handler
2225 * @context: adapter structure pointer
2226 * @event: event type
2227 *
2228 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2229 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2230 */
2231static void bnx2i_indicate_netevent(void *context, unsigned long event)
2232{
2233 struct bnx2i_hba *hba = context;
2234
2235 switch (event) {
2236 case NETDEV_UP:
2237 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2238 bnx2i_send_fw_iscsi_init_msg(hba);
2239 break;
2240 case NETDEV_DOWN:
2241 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2242 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2243 break;
2244 case NETDEV_GOING_DOWN:
2245 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2246 iscsi_host_for_each_session(hba->shost,
2247 bnx2i_drop_session);
2248 break;
2249 case NETDEV_CHANGE:
2250 bnx2i_get_link_state(hba);
2251 break;
2252 default:
2253 ;
2254 }
2255}
2256
2257
2258/**
2259 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2260 * @cm_sk: cnic sock structure pointer
2261 *
2262 * function callback exported via bnx2i - cnic driver interface to
2263 * indicate completion of option-2 TCP connect request.
2264 */
2265static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2266{
2267 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2268
2269 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2270 ep->state = EP_STATE_CONNECT_FAILED;
2271 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2272 ep->state = EP_STATE_CONNECT_COMPL;
2273 else
2274 ep->state = EP_STATE_CONNECT_FAILED;
2275
2276 wake_up_interruptible(&ep->ofld_wait);
2277}
2278
2279
2280/**
2281 * bnx2i_cm_close_cmpl - process tcp conn close completion
2282 * @cm_sk: cnic sock structure pointer
2283 *
2284 * function callback exported via bnx2i - cnic driver interface to
2285 * indicate completion of option-2 graceful TCP connect shutdown
2286 */
2287static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2288{
2289 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2290
2291 ep->state = EP_STATE_DISCONN_COMPL;
2292 wake_up_interruptible(&ep->ofld_wait);
2293}
2294
2295
2296/**
2297 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2298 * @cm_sk: cnic sock structure pointer
2299 *
2300 * function callback exported via bnx2i - cnic driver interface to
2301 * indicate completion of option-2 abortive TCP connect termination
2302 */
2303static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2304{
2305 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2306
2307 ep->state = EP_STATE_DISCONN_COMPL;
2308 wake_up_interruptible(&ep->ofld_wait);
2309}
2310
2311
2312/**
2313 * bnx2i_cm_remote_close - process received TCP FIN
2314 * @hba: adapter structure pointer
2315 * @update_kcqe: kcqe pointer
2316 *
2317 * function callback exported via bnx2i - cnic driver interface to indicate
2318 * async TCP events such as FIN
2319 */
2320static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2321{
2322 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2323
2324 ep->state = EP_STATE_TCP_FIN_RCVD;
2325 if (ep->conn)
2326 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2327}
2328
2329/**
2330 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2331 * @hba: adapter structure pointer
2332 * @update_kcqe: kcqe pointer
2333 *
2334 * function callback exported via bnx2i - cnic driver interface to
2335 * indicate async TCP events (RST) sent by the peer.
2336 */
2337static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2338{
2339 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2340
2341 ep->state = EP_STATE_TCP_RST_RCVD;
2342 if (ep->conn)
2343 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2344}
2345
2346
2347static void bnx2i_send_nl_mesg(struct cnic_dev *dev, u32 msg_type,
2348 char *buf, u16 buflen)
2349{
2350 struct bnx2i_hba *hba;
2351
2352 hba = bnx2i_find_hba_for_cnic(dev);
2353 if (!hba)
2354 return;
2355
2356 if (iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2357 msg_type, buf, buflen))
2358 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2359
2360}
2361
2362
2363/**
2364 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2365 * carrying callback function pointers
2366 *
2367 */
2368struct cnic_ulp_ops bnx2i_cnic_cb = {
2369 .cnic_init = bnx2i_ulp_init,
2370 .cnic_exit = bnx2i_ulp_exit,
2371 .cnic_start = bnx2i_start,
2372 .cnic_stop = bnx2i_stop,
2373 .indicate_kcqes = bnx2i_indicate_kcqe,
2374 .indicate_netevent = bnx2i_indicate_netevent,
2375 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2376 .cm_close_complete = bnx2i_cm_close_cmpl,
2377 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2378 .cm_remote_close = bnx2i_cm_remote_close,
2379 .cm_remote_abort = bnx2i_cm_remote_abort,
2380 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2381 .owner = THIS_MODULE
2382};
2383
2384
2385/**
2386 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2387 * @ep: bnx2i endpoint
2388 *
2389 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2390 * register in BAR #0. Whereas in 57710 these register are accessed by
2391 * mapping BAR #1
2392 */
2393int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2394{
2395 u32 cid_num;
2396 u32 reg_off;
2397 u32 first_l4l5;
2398 u32 ctx_sz;
2399 u32 config2;
2400 resource_size_t reg_base;
2401
2402 cid_num = bnx2i_get_cid_num(ep);
2403
2404 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2405 reg_base = pci_resource_start(ep->hba->pcidev,
2406 BNX2X_DOORBELL_PCI_BAR);
2407 reg_off = PAGE_SIZE * (cid_num & 0x1FFFF) + DPM_TRIGER_TYPE;
2408 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2409 goto arm_cq;
2410 }
2411
2412 reg_base = ep->hba->netdev->base_addr;
2413 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2414 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2415 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2416 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2417 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2418 if (ctx_sz)
2419 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
Anil Veerabhadrappa53203242009-09-11 10:38:26 -07002420 + BNX2I_570X_PAGE_SIZE_DEFAULT *
Michael Chancf4e6362009-06-08 18:14:44 -07002421 (((cid_num - first_l4l5) / ctx_sz) + 256);
2422 else
2423 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2424 } else
2425 /* 5709 device in normal node and 5706/5708 devices */
2426 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2427
2428 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2429 MB_KERNEL_CTX_SIZE);
2430 if (!ep->qp.ctx_base)
2431 return -ENOMEM;
2432
2433arm_cq:
2434 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
2435 return 0;
2436}