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