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