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