Commit | Line | Data |
---|---|---|
cf4e6363 MC |
1 | /* |
2 | * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver. | |
3 | * | |
4 | * Copyright (c) 2006 - 2009 Broadcom Corporation | |
5 | * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. | |
6 | * Copyright (c) 2007, 2008 Mike Christie | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation. | |
11 | * | |
12 | * Written by: Anil Veerabhadrappa (anilgv@broadcom.com) | |
13 | */ | |
14 | ||
5a0e3ad6 | 15 | #include <linux/slab.h> |
cf4e6363 MC |
16 | #include <scsi/scsi_tcq.h> |
17 | #include <scsi/libiscsi.h> | |
18 | #include "bnx2i.h" | |
19 | ||
20 | struct scsi_transport_template *bnx2i_scsi_xport_template; | |
21 | struct iscsi_transport bnx2i_iscsi_transport; | |
22 | static struct scsi_host_template bnx2i_host_template; | |
23 | ||
24 | /* | |
25 | * Global endpoint resource info | |
26 | */ | |
27 | static DEFINE_SPINLOCK(bnx2i_resc_lock); /* protects global resources */ | |
28 | ||
29 | ||
30 | static int bnx2i_adapter_ready(struct bnx2i_hba *hba) | |
31 | { | |
32 | int retval = 0; | |
33 | ||
34 | if (!hba || !test_bit(ADAPTER_STATE_UP, &hba->adapter_state) || | |
35 | test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state) || | |
36 | test_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state)) | |
37 | retval = -EPERM; | |
38 | return retval; | |
39 | } | |
40 | ||
41 | /** | |
42 | * bnx2i_get_write_cmd_bd_idx - identifies various BD bookmarks | |
43 | * @cmd: iscsi cmd struct pointer | |
44 | * @buf_off: absolute buffer offset | |
45 | * @start_bd_off: u32 pointer to return the offset within the BD | |
46 | * indicated by 'start_bd_idx' on which 'buf_off' falls | |
47 | * @start_bd_idx: index of the BD on which 'buf_off' falls | |
48 | * | |
49 | * identifies & marks various bd info for scsi command's imm data, | |
50 | * unsolicited data and the first solicited data seq. | |
51 | */ | |
52 | static void bnx2i_get_write_cmd_bd_idx(struct bnx2i_cmd *cmd, u32 buf_off, | |
53 | u32 *start_bd_off, u32 *start_bd_idx) | |
54 | { | |
55 | struct iscsi_bd *bd_tbl = cmd->io_tbl.bd_tbl; | |
56 | u32 cur_offset = 0; | |
57 | u32 cur_bd_idx = 0; | |
58 | ||
59 | if (buf_off) { | |
60 | while (buf_off >= (cur_offset + bd_tbl->buffer_length)) { | |
61 | cur_offset += bd_tbl->buffer_length; | |
62 | cur_bd_idx++; | |
63 | bd_tbl++; | |
64 | } | |
65 | } | |
66 | ||
67 | *start_bd_off = buf_off - cur_offset; | |
68 | *start_bd_idx = cur_bd_idx; | |
69 | } | |
70 | ||
71 | /** | |
72 | * bnx2i_setup_write_cmd_bd_info - sets up BD various information | |
73 | * @task: transport layer's cmd struct pointer | |
74 | * | |
75 | * identifies & marks various bd info for scsi command's immediate data, | |
76 | * unsolicited data and first solicited data seq which includes BD start | |
77 | * index & BD buf off. his function takes into account iscsi parameter such | |
78 | * as immediate data and unsolicited data is support on this connection. | |
79 | */ | |
80 | static void bnx2i_setup_write_cmd_bd_info(struct iscsi_task *task) | |
81 | { | |
82 | struct bnx2i_cmd *cmd = task->dd_data; | |
83 | u32 start_bd_offset; | |
84 | u32 start_bd_idx; | |
85 | u32 buffer_offset = 0; | |
86 | u32 cmd_len = cmd->req.total_data_transfer_length; | |
87 | ||
88 | /* if ImmediateData is turned off & IntialR2T is turned on, | |
89 | * there will be no immediate or unsolicited data, just return. | |
90 | */ | |
91 | if (!iscsi_task_has_unsol_data(task) && !task->imm_count) | |
92 | return; | |
93 | ||
94 | /* Immediate data */ | |
95 | buffer_offset += task->imm_count; | |
96 | if (task->imm_count == cmd_len) | |
97 | return; | |
98 | ||
99 | if (iscsi_task_has_unsol_data(task)) { | |
100 | bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset, | |
101 | &start_bd_offset, &start_bd_idx); | |
102 | cmd->req.ud_buffer_offset = start_bd_offset; | |
103 | cmd->req.ud_start_bd_index = start_bd_idx; | |
104 | buffer_offset += task->unsol_r2t.data_length; | |
105 | } | |
106 | ||
107 | if (buffer_offset != cmd_len) { | |
108 | bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset, | |
109 | &start_bd_offset, &start_bd_idx); | |
110 | if ((start_bd_offset > task->conn->session->first_burst) || | |
111 | (start_bd_idx > scsi_sg_count(cmd->scsi_cmd))) { | |
112 | int i = 0; | |
113 | ||
114 | iscsi_conn_printk(KERN_ALERT, task->conn, | |
115 | "bnx2i- error, buf offset 0x%x " | |
116 | "bd_valid %d use_sg %d\n", | |
117 | buffer_offset, cmd->io_tbl.bd_valid, | |
118 | scsi_sg_count(cmd->scsi_cmd)); | |
119 | for (i = 0; i < cmd->io_tbl.bd_valid; i++) | |
120 | iscsi_conn_printk(KERN_ALERT, task->conn, | |
121 | "bnx2i err, bd[%d]: len %x\n", | |
122 | i, cmd->io_tbl.bd_tbl[i].\ | |
123 | buffer_length); | |
124 | } | |
125 | cmd->req.sd_buffer_offset = start_bd_offset; | |
126 | cmd->req.sd_start_bd_index = start_bd_idx; | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | /** | |
133 | * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table | |
134 | * @hba: adapter instance | |
135 | * @cmd: iscsi cmd struct pointer | |
136 | * | |
137 | * map SG list | |
138 | */ | |
139 | static int bnx2i_map_scsi_sg(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd) | |
140 | { | |
141 | struct scsi_cmnd *sc = cmd->scsi_cmd; | |
142 | struct iscsi_bd *bd = cmd->io_tbl.bd_tbl; | |
143 | struct scatterlist *sg; | |
144 | int byte_count = 0; | |
145 | int bd_count = 0; | |
146 | int sg_count; | |
147 | int sg_len; | |
148 | u64 addr; | |
149 | int i; | |
150 | ||
151 | BUG_ON(scsi_sg_count(sc) > ISCSI_MAX_BDS_PER_CMD); | |
152 | ||
153 | sg_count = scsi_dma_map(sc); | |
154 | ||
155 | scsi_for_each_sg(sc, sg, sg_count, i) { | |
156 | sg_len = sg_dma_len(sg); | |
157 | addr = (u64) sg_dma_address(sg); | |
158 | bd[bd_count].buffer_addr_lo = addr & 0xffffffff; | |
159 | bd[bd_count].buffer_addr_hi = addr >> 32; | |
160 | bd[bd_count].buffer_length = sg_len; | |
161 | bd[bd_count].flags = 0; | |
162 | if (bd_count == 0) | |
163 | bd[bd_count].flags = ISCSI_BD_FIRST_IN_BD_CHAIN; | |
164 | ||
165 | byte_count += sg_len; | |
166 | bd_count++; | |
167 | } | |
168 | ||
169 | if (bd_count) | |
170 | bd[bd_count - 1].flags |= ISCSI_BD_LAST_IN_BD_CHAIN; | |
171 | ||
172 | BUG_ON(byte_count != scsi_bufflen(sc)); | |
173 | return bd_count; | |
174 | } | |
175 | ||
176 | /** | |
177 | * bnx2i_iscsi_map_sg_list - maps SG list | |
178 | * @cmd: iscsi cmd struct pointer | |
179 | * | |
180 | * creates BD list table for the command | |
181 | */ | |
182 | static void bnx2i_iscsi_map_sg_list(struct bnx2i_cmd *cmd) | |
183 | { | |
184 | int bd_count; | |
185 | ||
186 | bd_count = bnx2i_map_scsi_sg(cmd->conn->hba, cmd); | |
187 | if (!bd_count) { | |
188 | struct iscsi_bd *bd = cmd->io_tbl.bd_tbl; | |
189 | ||
190 | bd[0].buffer_addr_lo = bd[0].buffer_addr_hi = 0; | |
191 | bd[0].buffer_length = bd[0].flags = 0; | |
192 | } | |
193 | cmd->io_tbl.bd_valid = bd_count; | |
194 | } | |
195 | ||
196 | ||
197 | /** | |
198 | * bnx2i_iscsi_unmap_sg_list - unmaps SG list | |
199 | * @cmd: iscsi cmd struct pointer | |
200 | * | |
201 | * unmap IO buffers and invalidate the BD table | |
202 | */ | |
203 | void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd) | |
204 | { | |
205 | struct scsi_cmnd *sc = cmd->scsi_cmd; | |
206 | ||
207 | if (cmd->io_tbl.bd_valid && sc) { | |
208 | scsi_dma_unmap(sc); | |
209 | cmd->io_tbl.bd_valid = 0; | |
210 | } | |
211 | } | |
212 | ||
213 | static void bnx2i_setup_cmd_wqe_template(struct bnx2i_cmd *cmd) | |
214 | { | |
215 | memset(&cmd->req, 0x00, sizeof(cmd->req)); | |
216 | cmd->req.op_code = 0xFF; | |
217 | cmd->req.bd_list_addr_lo = (u32) cmd->io_tbl.bd_tbl_dma; | |
218 | cmd->req.bd_list_addr_hi = | |
219 | (u32) ((u64) cmd->io_tbl.bd_tbl_dma >> 32); | |
220 | ||
221 | } | |
222 | ||
223 | ||
224 | /** | |
225 | * bnx2i_bind_conn_to_iscsi_cid - bind conn structure to 'iscsi_cid' | |
226 | * @hba: pointer to adapter instance | |
227 | * @conn: pointer to iscsi connection | |
228 | * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1) | |
229 | * | |
230 | * update iscsi cid table entry with connection pointer. This enables | |
231 | * driver to quickly get hold of connection structure pointer in | |
232 | * completion/interrupt thread using iscsi context ID | |
233 | */ | |
234 | static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba *hba, | |
235 | struct bnx2i_conn *bnx2i_conn, | |
236 | u32 iscsi_cid) | |
237 | { | |
238 | if (hba && hba->cid_que.conn_cid_tbl[iscsi_cid]) { | |
239 | iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data, | |
240 | "conn bind - entry #%d not free\n", iscsi_cid); | |
241 | return -EBUSY; | |
242 | } | |
243 | ||
244 | hba->cid_que.conn_cid_tbl[iscsi_cid] = bnx2i_conn; | |
245 | return 0; | |
246 | } | |
247 | ||
248 | ||
249 | /** | |
250 | * bnx2i_get_conn_from_id - maps an iscsi cid to corresponding conn ptr | |
251 | * @hba: pointer to adapter instance | |
252 | * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1) | |
253 | */ | |
254 | struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba, | |
255 | u16 iscsi_cid) | |
256 | { | |
257 | if (!hba->cid_que.conn_cid_tbl) { | |
258 | printk(KERN_ERR "bnx2i: ERROR - missing conn<->cid table\n"); | |
259 | return NULL; | |
260 | ||
261 | } else if (iscsi_cid >= hba->max_active_conns) { | |
262 | printk(KERN_ERR "bnx2i: wrong cid #%d\n", iscsi_cid); | |
263 | return NULL; | |
264 | } | |
265 | return hba->cid_que.conn_cid_tbl[iscsi_cid]; | |
266 | } | |
267 | ||
268 | ||
269 | /** | |
270 | * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool | |
271 | * @hba: pointer to adapter instance | |
272 | */ | |
273 | static u32 bnx2i_alloc_iscsi_cid(struct bnx2i_hba *hba) | |
274 | { | |
275 | int idx; | |
276 | ||
277 | if (!hba->cid_que.cid_free_cnt) | |
278 | return -1; | |
279 | ||
280 | idx = hba->cid_que.cid_q_cons_idx; | |
281 | hba->cid_que.cid_q_cons_idx++; | |
282 | if (hba->cid_que.cid_q_cons_idx == hba->cid_que.cid_q_max_idx) | |
283 | hba->cid_que.cid_q_cons_idx = 0; | |
284 | ||
285 | hba->cid_que.cid_free_cnt--; | |
286 | return hba->cid_que.cid_que[idx]; | |
287 | } | |
288 | ||
289 | ||
290 | /** | |
291 | * bnx2i_free_iscsi_cid - returns tcp port to free list | |
292 | * @hba: pointer to adapter instance | |
293 | * @iscsi_cid: iscsi context ID to free | |
294 | */ | |
295 | static void bnx2i_free_iscsi_cid(struct bnx2i_hba *hba, u16 iscsi_cid) | |
296 | { | |
297 | int idx; | |
298 | ||
299 | if (iscsi_cid == (u16) -1) | |
300 | return; | |
301 | ||
302 | hba->cid_que.cid_free_cnt++; | |
303 | ||
304 | idx = hba->cid_que.cid_q_prod_idx; | |
305 | hba->cid_que.cid_que[idx] = iscsi_cid; | |
306 | hba->cid_que.conn_cid_tbl[iscsi_cid] = NULL; | |
307 | hba->cid_que.cid_q_prod_idx++; | |
308 | if (hba->cid_que.cid_q_prod_idx == hba->cid_que.cid_q_max_idx) | |
309 | hba->cid_que.cid_q_prod_idx = 0; | |
310 | } | |
311 | ||
312 | ||
313 | /** | |
314 | * bnx2i_setup_free_cid_que - sets up free iscsi cid queue | |
315 | * @hba: pointer to adapter instance | |
316 | * | |
317 | * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table, | |
318 | * and initialize table attributes | |
319 | */ | |
320 | static int bnx2i_setup_free_cid_que(struct bnx2i_hba *hba) | |
321 | { | |
322 | int mem_size; | |
323 | int i; | |
324 | ||
325 | mem_size = hba->max_active_conns * sizeof(u32); | |
326 | mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; | |
327 | ||
328 | hba->cid_que.cid_que_base = kmalloc(mem_size, GFP_KERNEL); | |
329 | if (!hba->cid_que.cid_que_base) | |
330 | return -ENOMEM; | |
331 | ||
332 | mem_size = hba->max_active_conns * sizeof(struct bnx2i_conn *); | |
333 | mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; | |
334 | hba->cid_que.conn_cid_tbl = kmalloc(mem_size, GFP_KERNEL); | |
335 | if (!hba->cid_que.conn_cid_tbl) { | |
336 | kfree(hba->cid_que.cid_que_base); | |
337 | hba->cid_que.cid_que_base = NULL; | |
338 | return -ENOMEM; | |
339 | } | |
340 | ||
341 | hba->cid_que.cid_que = (u32 *)hba->cid_que.cid_que_base; | |
342 | hba->cid_que.cid_q_prod_idx = 0; | |
343 | hba->cid_que.cid_q_cons_idx = 0; | |
344 | hba->cid_que.cid_q_max_idx = hba->max_active_conns; | |
345 | hba->cid_que.cid_free_cnt = hba->max_active_conns; | |
346 | ||
347 | for (i = 0; i < hba->max_active_conns; i++) { | |
348 | hba->cid_que.cid_que[i] = i; | |
349 | hba->cid_que.conn_cid_tbl[i] = NULL; | |
350 | } | |
351 | return 0; | |
352 | } | |
353 | ||
354 | ||
355 | /** | |
356 | * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources | |
357 | * @hba: pointer to adapter instance | |
358 | */ | |
359 | static void bnx2i_release_free_cid_que(struct bnx2i_hba *hba) | |
360 | { | |
361 | kfree(hba->cid_que.cid_que_base); | |
362 | hba->cid_que.cid_que_base = NULL; | |
363 | ||
364 | kfree(hba->cid_que.conn_cid_tbl); | |
365 | hba->cid_que.conn_cid_tbl = NULL; | |
366 | } | |
367 | ||
368 | ||
369 | /** | |
370 | * bnx2i_alloc_ep - allocates ep structure from global pool | |
371 | * @hba: pointer to adapter instance | |
372 | * | |
373 | * routine allocates a free endpoint structure from global pool and | |
374 | * a tcp port to be used for this connection. Global resource lock, | |
375 | * 'bnx2i_resc_lock' is held while accessing shared global data structures | |
376 | */ | |
377 | static struct iscsi_endpoint *bnx2i_alloc_ep(struct bnx2i_hba *hba) | |
378 | { | |
379 | struct iscsi_endpoint *ep; | |
380 | struct bnx2i_endpoint *bnx2i_ep; | |
381 | ||
382 | ep = iscsi_create_endpoint(sizeof(*bnx2i_ep)); | |
383 | if (!ep) { | |
384 | printk(KERN_ERR "bnx2i: Could not allocate ep\n"); | |
385 | return NULL; | |
386 | } | |
387 | ||
388 | bnx2i_ep = ep->dd_data; | |
46012e8b | 389 | bnx2i_ep->cls_ep = ep; |
cf4e6363 MC |
390 | INIT_LIST_HEAD(&bnx2i_ep->link); |
391 | bnx2i_ep->state = EP_STATE_IDLE; | |
c19dcd01 | 392 | bnx2i_ep->ep_iscsi_cid = (u16) -1; |
cf4e6363 MC |
393 | bnx2i_ep->hba = hba; |
394 | bnx2i_ep->hba_age = hba->age; | |
395 | hba->ofld_conns_active++; | |
396 | init_waitqueue_head(&bnx2i_ep->ofld_wait); | |
397 | return ep; | |
398 | } | |
399 | ||
400 | ||
401 | /** | |
402 | * bnx2i_free_ep - free endpoint | |
403 | * @ep: pointer to iscsi endpoint structure | |
404 | */ | |
405 | static void bnx2i_free_ep(struct iscsi_endpoint *ep) | |
406 | { | |
407 | struct bnx2i_endpoint *bnx2i_ep = ep->dd_data; | |
408 | unsigned long flags; | |
409 | ||
410 | spin_lock_irqsave(&bnx2i_resc_lock, flags); | |
411 | bnx2i_ep->state = EP_STATE_IDLE; | |
412 | bnx2i_ep->hba->ofld_conns_active--; | |
413 | ||
414 | bnx2i_free_iscsi_cid(bnx2i_ep->hba, bnx2i_ep->ep_iscsi_cid); | |
415 | if (bnx2i_ep->conn) { | |
416 | bnx2i_ep->conn->ep = NULL; | |
417 | bnx2i_ep->conn = NULL; | |
418 | } | |
419 | ||
420 | bnx2i_ep->hba = NULL; | |
421 | spin_unlock_irqrestore(&bnx2i_resc_lock, flags); | |
422 | iscsi_destroy_endpoint(ep); | |
423 | } | |
424 | ||
425 | ||
426 | /** | |
427 | * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command | |
428 | * @hba: adapter instance pointer | |
429 | * @session: iscsi session pointer | |
430 | * @cmd: iscsi command structure | |
431 | */ | |
432 | static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session, | |
433 | struct bnx2i_cmd *cmd) | |
434 | { | |
435 | struct io_bdt *io = &cmd->io_tbl; | |
436 | struct iscsi_bd *bd; | |
437 | ||
438 | io->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, | |
439 | ISCSI_MAX_BDS_PER_CMD * sizeof(*bd), | |
440 | &io->bd_tbl_dma, GFP_KERNEL); | |
441 | if (!io->bd_tbl) { | |
442 | iscsi_session_printk(KERN_ERR, session, "Could not " | |
443 | "allocate bdt.\n"); | |
444 | return -ENOMEM; | |
445 | } | |
446 | io->bd_valid = 0; | |
447 | return 0; | |
448 | } | |
449 | ||
450 | /** | |
451 | * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table | |
452 | * @hba: adapter instance pointer | |
453 | * @session: iscsi session pointer | |
454 | * @cmd: iscsi command structure | |
455 | */ | |
456 | static void bnx2i_destroy_cmd_pool(struct bnx2i_hba *hba, | |
457 | struct iscsi_session *session) | |
458 | { | |
459 | int i; | |
460 | ||
461 | for (i = 0; i < session->cmds_max; i++) { | |
462 | struct iscsi_task *task = session->cmds[i]; | |
463 | struct bnx2i_cmd *cmd = task->dd_data; | |
464 | ||
465 | if (cmd->io_tbl.bd_tbl) | |
466 | dma_free_coherent(&hba->pcidev->dev, | |
467 | ISCSI_MAX_BDS_PER_CMD * | |
468 | sizeof(struct iscsi_bd), | |
469 | cmd->io_tbl.bd_tbl, | |
470 | cmd->io_tbl.bd_tbl_dma); | |
471 | } | |
472 | ||
473 | } | |
474 | ||
475 | ||
476 | /** | |
477 | * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session | |
478 | * @hba: adapter instance pointer | |
479 | * @session: iscsi session pointer | |
480 | */ | |
481 | static int bnx2i_setup_cmd_pool(struct bnx2i_hba *hba, | |
482 | struct iscsi_session *session) | |
483 | { | |
484 | int i; | |
485 | ||
486 | for (i = 0; i < session->cmds_max; i++) { | |
487 | struct iscsi_task *task = session->cmds[i]; | |
488 | struct bnx2i_cmd *cmd = task->dd_data; | |
489 | ||
cf4e6363 MC |
490 | task->hdr = &cmd->hdr; |
491 | task->hdr_max = sizeof(struct iscsi_hdr); | |
492 | ||
493 | if (bnx2i_alloc_bdt(hba, session, cmd)) | |
494 | goto free_bdts; | |
495 | } | |
496 | ||
497 | return 0; | |
498 | ||
499 | free_bdts: | |
500 | bnx2i_destroy_cmd_pool(hba, session); | |
501 | return -ENOMEM; | |
502 | } | |
503 | ||
504 | ||
505 | /** | |
506 | * bnx2i_setup_mp_bdt - allocate BD table resources | |
507 | * @hba: pointer to adapter structure | |
508 | * | |
509 | * Allocate memory for dummy buffer and associated BD | |
510 | * table to be used by middle path (MP) requests | |
511 | */ | |
512 | static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba) | |
513 | { | |
514 | int rc = 0; | |
515 | struct iscsi_bd *mp_bdt; | |
516 | u64 addr; | |
517 | ||
518 | hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
519 | &hba->mp_bd_dma, GFP_KERNEL); | |
520 | if (!hba->mp_bd_tbl) { | |
521 | printk(KERN_ERR "unable to allocate Middle Path BDT\n"); | |
522 | rc = -1; | |
523 | goto out; | |
524 | } | |
525 | ||
526 | hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
527 | &hba->dummy_buf_dma, GFP_KERNEL); | |
528 | if (!hba->dummy_buffer) { | |
529 | printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n"); | |
530 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
531 | hba->mp_bd_tbl, hba->mp_bd_dma); | |
532 | hba->mp_bd_tbl = NULL; | |
533 | rc = -1; | |
534 | goto out; | |
535 | } | |
536 | ||
537 | mp_bdt = (struct iscsi_bd *) hba->mp_bd_tbl; | |
538 | addr = (unsigned long) hba->dummy_buf_dma; | |
539 | mp_bdt->buffer_addr_lo = addr & 0xffffffff; | |
540 | mp_bdt->buffer_addr_hi = addr >> 32; | |
541 | mp_bdt->buffer_length = PAGE_SIZE; | |
542 | mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN | | |
543 | ISCSI_BD_FIRST_IN_BD_CHAIN; | |
544 | out: | |
545 | return rc; | |
546 | } | |
547 | ||
548 | ||
549 | /** | |
550 | * bnx2i_free_mp_bdt - releases ITT back to free pool | |
551 | * @hba: pointer to adapter instance | |
552 | * | |
553 | * free MP dummy buffer and associated BD table | |
554 | */ | |
555 | static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba) | |
556 | { | |
557 | if (hba->mp_bd_tbl) { | |
558 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
559 | hba->mp_bd_tbl, hba->mp_bd_dma); | |
560 | hba->mp_bd_tbl = NULL; | |
561 | } | |
562 | if (hba->dummy_buffer) { | |
563 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
564 | hba->dummy_buffer, hba->dummy_buf_dma); | |
565 | hba->dummy_buffer = NULL; | |
566 | } | |
567 | return; | |
568 | } | |
569 | ||
570 | /** | |
571 | * bnx2i_drop_session - notifies iscsid of connection error. | |
572 | * @hba: adapter instance pointer | |
573 | * @session: iscsi session pointer | |
574 | * | |
575 | * This notifies iscsid that there is a error, so it can initiate | |
576 | * recovery. | |
577 | * | |
578 | * This relies on caller using the iscsi class iterator so the object | |
579 | * is refcounted and does not disapper from under us. | |
580 | */ | |
581 | void bnx2i_drop_session(struct iscsi_cls_session *cls_session) | |
582 | { | |
583 | iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); | |
584 | } | |
585 | ||
586 | /** | |
587 | * bnx2i_ep_destroy_list_add - add an entry to EP destroy list | |
588 | * @hba: pointer to adapter instance | |
589 | * @ep: pointer to endpoint (transport indentifier) structure | |
590 | * | |
591 | * EP destroy queue manager | |
592 | */ | |
593 | static int bnx2i_ep_destroy_list_add(struct bnx2i_hba *hba, | |
594 | struct bnx2i_endpoint *ep) | |
595 | { | |
596 | write_lock_bh(&hba->ep_rdwr_lock); | |
597 | list_add_tail(&ep->link, &hba->ep_destroy_list); | |
598 | write_unlock_bh(&hba->ep_rdwr_lock); | |
599 | return 0; | |
600 | } | |
601 | ||
602 | /** | |
603 | * bnx2i_ep_destroy_list_del - add an entry to EP destroy list | |
604 | * | |
605 | * @hba: pointer to adapter instance | |
606 | * @ep: pointer to endpoint (transport indentifier) structure | |
607 | * | |
608 | * EP destroy queue manager | |
609 | */ | |
610 | static int bnx2i_ep_destroy_list_del(struct bnx2i_hba *hba, | |
611 | struct bnx2i_endpoint *ep) | |
612 | { | |
613 | write_lock_bh(&hba->ep_rdwr_lock); | |
614 | list_del_init(&ep->link); | |
615 | write_unlock_bh(&hba->ep_rdwr_lock); | |
616 | ||
617 | return 0; | |
618 | } | |
619 | ||
620 | /** | |
621 | * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list | |
622 | * @hba: pointer to adapter instance | |
623 | * @ep: pointer to endpoint (transport indentifier) structure | |
624 | * | |
625 | * pending conn offload completion queue manager | |
626 | */ | |
627 | static int bnx2i_ep_ofld_list_add(struct bnx2i_hba *hba, | |
628 | struct bnx2i_endpoint *ep) | |
629 | { | |
630 | write_lock_bh(&hba->ep_rdwr_lock); | |
631 | list_add_tail(&ep->link, &hba->ep_ofld_list); | |
632 | write_unlock_bh(&hba->ep_rdwr_lock); | |
633 | return 0; | |
634 | } | |
635 | ||
636 | /** | |
637 | * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list | |
638 | * @hba: pointer to adapter instance | |
639 | * @ep: pointer to endpoint (transport indentifier) structure | |
640 | * | |
641 | * pending conn offload completion queue manager | |
642 | */ | |
643 | static int bnx2i_ep_ofld_list_del(struct bnx2i_hba *hba, | |
644 | struct bnx2i_endpoint *ep) | |
645 | { | |
646 | write_lock_bh(&hba->ep_rdwr_lock); | |
647 | list_del_init(&ep->link); | |
648 | write_unlock_bh(&hba->ep_rdwr_lock); | |
649 | return 0; | |
650 | } | |
651 | ||
652 | ||
653 | /** | |
654 | * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints | |
655 | * | |
656 | * @hba: pointer to adapter instance | |
657 | * @iscsi_cid: iscsi context ID to find | |
658 | * | |
659 | */ | |
660 | struct bnx2i_endpoint * | |
661 | bnx2i_find_ep_in_ofld_list(struct bnx2i_hba *hba, u32 iscsi_cid) | |
662 | { | |
663 | struct list_head *list; | |
664 | struct list_head *tmp; | |
665 | struct bnx2i_endpoint *ep; | |
666 | ||
667 | read_lock_bh(&hba->ep_rdwr_lock); | |
668 | list_for_each_safe(list, tmp, &hba->ep_ofld_list) { | |
669 | ep = (struct bnx2i_endpoint *)list; | |
670 | ||
671 | if (ep->ep_iscsi_cid == iscsi_cid) | |
672 | break; | |
673 | ep = NULL; | |
674 | } | |
675 | read_unlock_bh(&hba->ep_rdwr_lock); | |
676 | ||
677 | if (!ep) | |
678 | printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid); | |
679 | return ep; | |
680 | } | |
681 | ||
cf4e6363 MC |
682 | /** |
683 | * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list | |
684 | * @hba: pointer to adapter instance | |
685 | * @iscsi_cid: iscsi context ID to find | |
686 | * | |
687 | */ | |
688 | struct bnx2i_endpoint * | |
689 | bnx2i_find_ep_in_destroy_list(struct bnx2i_hba *hba, u32 iscsi_cid) | |
690 | { | |
691 | struct list_head *list; | |
692 | struct list_head *tmp; | |
693 | struct bnx2i_endpoint *ep; | |
694 | ||
695 | read_lock_bh(&hba->ep_rdwr_lock); | |
696 | list_for_each_safe(list, tmp, &hba->ep_destroy_list) { | |
697 | ep = (struct bnx2i_endpoint *)list; | |
698 | ||
699 | if (ep->ep_iscsi_cid == iscsi_cid) | |
700 | break; | |
701 | ep = NULL; | |
702 | } | |
703 | read_unlock_bh(&hba->ep_rdwr_lock); | |
704 | ||
705 | if (!ep) | |
706 | printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid); | |
707 | ||
708 | return ep; | |
709 | } | |
710 | ||
46012e8b EW |
711 | /** |
712 | * bnx2i_ep_active_list_add - add an entry to ep active list | |
713 | * @hba: pointer to adapter instance | |
714 | * @ep: pointer to endpoint (transport indentifier) structure | |
715 | * | |
716 | * current active conn queue manager | |
717 | */ | |
718 | static void bnx2i_ep_active_list_add(struct bnx2i_hba *hba, | |
719 | struct bnx2i_endpoint *ep) | |
720 | { | |
721 | write_lock_bh(&hba->ep_rdwr_lock); | |
722 | list_add_tail(&ep->link, &hba->ep_active_list); | |
723 | write_unlock_bh(&hba->ep_rdwr_lock); | |
724 | } | |
725 | ||
726 | ||
727 | /** | |
728 | * bnx2i_ep_active_list_del - deletes an entry to ep active list | |
729 | * @hba: pointer to adapter instance | |
730 | * @ep: pointer to endpoint (transport indentifier) structure | |
731 | * | |
732 | * current active conn queue manager | |
733 | */ | |
734 | static void bnx2i_ep_active_list_del(struct bnx2i_hba *hba, | |
735 | struct bnx2i_endpoint *ep) | |
736 | { | |
737 | write_lock_bh(&hba->ep_rdwr_lock); | |
738 | list_del_init(&ep->link); | |
739 | write_unlock_bh(&hba->ep_rdwr_lock); | |
740 | } | |
741 | ||
742 | ||
cf4e6363 MC |
743 | /** |
744 | * bnx2i_setup_host_queue_size - assigns shost->can_queue param | |
745 | * @hba: pointer to adapter instance | |
746 | * @shost: scsi host pointer | |
747 | * | |
748 | * Initializes 'can_queue' parameter based on how many outstanding commands | |
749 | * the device can handle. Each device 5708/5709/57710 has different | |
750 | * capabilities | |
751 | */ | |
752 | static void bnx2i_setup_host_queue_size(struct bnx2i_hba *hba, | |
753 | struct Scsi_Host *shost) | |
754 | { | |
755 | if (test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type)) | |
756 | shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708; | |
757 | else if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) | |
758 | shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5709; | |
759 | else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) | |
760 | shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_57710; | |
761 | else | |
762 | shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708; | |
763 | } | |
764 | ||
765 | ||
766 | /** | |
767 | * bnx2i_alloc_hba - allocate and init adapter instance | |
768 | * @cnic: cnic device pointer | |
769 | * | |
770 | * allocate & initialize adapter structure and call other | |
771 | * support routines to do per adapter initialization | |
772 | */ | |
773 | struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic) | |
774 | { | |
775 | struct Scsi_Host *shost; | |
776 | struct bnx2i_hba *hba; | |
777 | ||
778 | shost = iscsi_host_alloc(&bnx2i_host_template, sizeof(*hba), 0); | |
779 | if (!shost) | |
780 | return NULL; | |
781 | shost->dma_boundary = cnic->pcidev->dma_mask; | |
782 | shost->transportt = bnx2i_scsi_xport_template; | |
783 | shost->max_id = ISCSI_MAX_CONNS_PER_HBA; | |
784 | shost->max_channel = 0; | |
785 | shost->max_lun = 512; | |
786 | shost->max_cmd_len = 16; | |
787 | ||
788 | hba = iscsi_host_priv(shost); | |
789 | hba->shost = shost; | |
790 | hba->netdev = cnic->netdev; | |
791 | /* Get PCI related information and update hba struct members */ | |
792 | hba->pcidev = cnic->pcidev; | |
793 | pci_dev_get(hba->pcidev); | |
794 | hba->pci_did = hba->pcidev->device; | |
795 | hba->pci_vid = hba->pcidev->vendor; | |
796 | hba->pci_sdid = hba->pcidev->subsystem_device; | |
797 | hba->pci_svid = hba->pcidev->subsystem_vendor; | |
798 | hba->pci_func = PCI_FUNC(hba->pcidev->devfn); | |
799 | hba->pci_devno = PCI_SLOT(hba->pcidev->devfn); | |
cf4e6363 MC |
800 | |
801 | bnx2i_identify_device(hba); | |
802 | bnx2i_setup_host_queue_size(hba, shost); | |
803 | ||
804 | if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) { | |
805 | hba->regview = ioremap_nocache(hba->netdev->base_addr, | |
806 | BNX2_MQ_CONFIG2); | |
807 | if (!hba->regview) | |
808 | goto ioreg_map_err; | |
809 | } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { | |
810 | hba->regview = ioremap_nocache(hba->netdev->base_addr, 4096); | |
811 | if (!hba->regview) | |
812 | goto ioreg_map_err; | |
813 | } | |
814 | ||
815 | if (bnx2i_setup_mp_bdt(hba)) | |
816 | goto mp_bdt_mem_err; | |
817 | ||
818 | INIT_LIST_HEAD(&hba->ep_ofld_list); | |
46012e8b | 819 | INIT_LIST_HEAD(&hba->ep_active_list); |
cf4e6363 MC |
820 | INIT_LIST_HEAD(&hba->ep_destroy_list); |
821 | rwlock_init(&hba->ep_rdwr_lock); | |
822 | ||
823 | hba->mtu_supported = BNX2I_MAX_MTU_SUPPORTED; | |
824 | ||
825 | /* different values for 5708/5709/57710 */ | |
826 | hba->max_active_conns = ISCSI_MAX_CONNS_PER_HBA; | |
827 | ||
828 | if (bnx2i_setup_free_cid_que(hba)) | |
829 | goto cid_que_err; | |
830 | ||
831 | /* SQ/RQ/CQ size can be changed via sysfx interface */ | |
832 | if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { | |
833 | if (sq_size && sq_size <= BNX2I_5770X_SQ_WQES_MAX) | |
834 | hba->max_sqes = sq_size; | |
835 | else | |
836 | hba->max_sqes = BNX2I_5770X_SQ_WQES_DEFAULT; | |
837 | } else { /* 5706/5708/5709 */ | |
838 | if (sq_size && sq_size <= BNX2I_570X_SQ_WQES_MAX) | |
839 | hba->max_sqes = sq_size; | |
840 | else | |
841 | hba->max_sqes = BNX2I_570X_SQ_WQES_DEFAULT; | |
842 | } | |
843 | ||
844 | hba->max_rqes = rq_size; | |
845 | hba->max_cqes = hba->max_sqes + rq_size; | |
846 | if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { | |
847 | if (hba->max_cqes > BNX2I_5770X_CQ_WQES_MAX) | |
848 | hba->max_cqes = BNX2I_5770X_CQ_WQES_MAX; | |
849 | } else if (hba->max_cqes > BNX2I_570X_CQ_WQES_MAX) | |
850 | hba->max_cqes = BNX2I_570X_CQ_WQES_MAX; | |
851 | ||
852 | hba->num_ccell = hba->max_sqes / 2; | |
853 | ||
854 | spin_lock_init(&hba->lock); | |
855 | mutex_init(&hba->net_dev_lock); | |
490475a9 | 856 | init_waitqueue_head(&hba->eh_wait); |
e37d2c47 | 857 | if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) { |
55e15c97 | 858 | hba->hba_shutdown_tmo = 20 * HZ; |
e37d2c47 EW |
859 | hba->conn_teardown_tmo = 20 * HZ; |
860 | hba->conn_ctx_destroy_tmo = 6 * HZ; | |
861 | } else { /* 5706/5708/5709 */ | |
55e15c97 | 862 | hba->hba_shutdown_tmo = 20 * HZ; |
e37d2c47 EW |
863 | hba->conn_teardown_tmo = 10 * HZ; |
864 | hba->conn_ctx_destroy_tmo = 2 * HZ; | |
865 | } | |
cf4e6363 MC |
866 | |
867 | if (iscsi_host_add(shost, &hba->pcidev->dev)) | |
868 | goto free_dump_mem; | |
869 | return hba; | |
870 | ||
871 | free_dump_mem: | |
872 | bnx2i_release_free_cid_que(hba); | |
873 | cid_que_err: | |
874 | bnx2i_free_mp_bdt(hba); | |
875 | mp_bdt_mem_err: | |
876 | if (hba->regview) { | |
877 | iounmap(hba->regview); | |
878 | hba->regview = NULL; | |
879 | } | |
880 | ioreg_map_err: | |
881 | pci_dev_put(hba->pcidev); | |
882 | scsi_host_put(shost); | |
883 | return NULL; | |
884 | } | |
885 | ||
886 | /** | |
887 | * bnx2i_free_hba- releases hba structure and resources held by the adapter | |
888 | * @hba: pointer to adapter instance | |
889 | * | |
890 | * free adapter structure and call various cleanup routines. | |
891 | */ | |
892 | void bnx2i_free_hba(struct bnx2i_hba *hba) | |
893 | { | |
894 | struct Scsi_Host *shost = hba->shost; | |
895 | ||
896 | iscsi_host_remove(shost); | |
897 | INIT_LIST_HEAD(&hba->ep_ofld_list); | |
46012e8b | 898 | INIT_LIST_HEAD(&hba->ep_active_list); |
cf4e6363 MC |
899 | INIT_LIST_HEAD(&hba->ep_destroy_list); |
900 | pci_dev_put(hba->pcidev); | |
901 | ||
902 | if (hba->regview) { | |
903 | iounmap(hba->regview); | |
904 | hba->regview = NULL; | |
905 | } | |
906 | bnx2i_free_mp_bdt(hba); | |
907 | bnx2i_release_free_cid_que(hba); | |
908 | iscsi_host_free(shost); | |
909 | } | |
910 | ||
911 | /** | |
912 | * bnx2i_conn_free_login_resources - free DMA resources used for login process | |
913 | * @hba: pointer to adapter instance | |
914 | * @bnx2i_conn: iscsi connection pointer | |
915 | * | |
916 | * Login related resources, mostly BDT & payload DMA memory is freed | |
917 | */ | |
918 | static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba, | |
919 | struct bnx2i_conn *bnx2i_conn) | |
920 | { | |
921 | if (bnx2i_conn->gen_pdu.resp_bd_tbl) { | |
922 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
923 | bnx2i_conn->gen_pdu.resp_bd_tbl, | |
924 | bnx2i_conn->gen_pdu.resp_bd_dma); | |
925 | bnx2i_conn->gen_pdu.resp_bd_tbl = NULL; | |
926 | } | |
927 | ||
928 | if (bnx2i_conn->gen_pdu.req_bd_tbl) { | |
929 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
930 | bnx2i_conn->gen_pdu.req_bd_tbl, | |
931 | bnx2i_conn->gen_pdu.req_bd_dma); | |
932 | bnx2i_conn->gen_pdu.req_bd_tbl = NULL; | |
933 | } | |
934 | ||
935 | if (bnx2i_conn->gen_pdu.resp_buf) { | |
936 | dma_free_coherent(&hba->pcidev->dev, | |
937 | ISCSI_DEF_MAX_RECV_SEG_LEN, | |
938 | bnx2i_conn->gen_pdu.resp_buf, | |
939 | bnx2i_conn->gen_pdu.resp_dma_addr); | |
940 | bnx2i_conn->gen_pdu.resp_buf = NULL; | |
941 | } | |
942 | ||
943 | if (bnx2i_conn->gen_pdu.req_buf) { | |
944 | dma_free_coherent(&hba->pcidev->dev, | |
945 | ISCSI_DEF_MAX_RECV_SEG_LEN, | |
946 | bnx2i_conn->gen_pdu.req_buf, | |
947 | bnx2i_conn->gen_pdu.req_dma_addr); | |
948 | bnx2i_conn->gen_pdu.req_buf = NULL; | |
949 | } | |
950 | } | |
951 | ||
952 | /** | |
953 | * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop. | |
954 | * @hba: pointer to adapter instance | |
955 | * @bnx2i_conn: iscsi connection pointer | |
956 | * | |
957 | * Mgmt task DNA resources are allocated in this routine. | |
958 | */ | |
959 | static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba, | |
960 | struct bnx2i_conn *bnx2i_conn) | |
961 | { | |
962 | /* Allocate memory for login request/response buffers */ | |
963 | bnx2i_conn->gen_pdu.req_buf = | |
964 | dma_alloc_coherent(&hba->pcidev->dev, | |
965 | ISCSI_DEF_MAX_RECV_SEG_LEN, | |
966 | &bnx2i_conn->gen_pdu.req_dma_addr, | |
967 | GFP_KERNEL); | |
968 | if (bnx2i_conn->gen_pdu.req_buf == NULL) | |
969 | goto login_req_buf_failure; | |
970 | ||
971 | bnx2i_conn->gen_pdu.req_buf_size = 0; | |
972 | bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf; | |
973 | ||
974 | bnx2i_conn->gen_pdu.resp_buf = | |
975 | dma_alloc_coherent(&hba->pcidev->dev, | |
976 | ISCSI_DEF_MAX_RECV_SEG_LEN, | |
977 | &bnx2i_conn->gen_pdu.resp_dma_addr, | |
978 | GFP_KERNEL); | |
979 | if (bnx2i_conn->gen_pdu.resp_buf == NULL) | |
980 | goto login_resp_buf_failure; | |
981 | ||
982 | bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN; | |
983 | bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf; | |
984 | ||
985 | bnx2i_conn->gen_pdu.req_bd_tbl = | |
986 | dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
987 | &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL); | |
988 | if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL) | |
989 | goto login_req_bd_tbl_failure; | |
990 | ||
991 | bnx2i_conn->gen_pdu.resp_bd_tbl = | |
992 | dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
993 | &bnx2i_conn->gen_pdu.resp_bd_dma, | |
994 | GFP_KERNEL); | |
995 | if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL) | |
996 | goto login_resp_bd_tbl_failure; | |
997 | ||
998 | return 0; | |
999 | ||
1000 | login_resp_bd_tbl_failure: | |
1001 | dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, | |
1002 | bnx2i_conn->gen_pdu.req_bd_tbl, | |
1003 | bnx2i_conn->gen_pdu.req_bd_dma); | |
1004 | bnx2i_conn->gen_pdu.req_bd_tbl = NULL; | |
1005 | ||
1006 | login_req_bd_tbl_failure: | |
1007 | dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN, | |
1008 | bnx2i_conn->gen_pdu.resp_buf, | |
1009 | bnx2i_conn->gen_pdu.resp_dma_addr); | |
1010 | bnx2i_conn->gen_pdu.resp_buf = NULL; | |
1011 | login_resp_buf_failure: | |
1012 | dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN, | |
1013 | bnx2i_conn->gen_pdu.req_buf, | |
1014 | bnx2i_conn->gen_pdu.req_dma_addr); | |
1015 | bnx2i_conn->gen_pdu.req_buf = NULL; | |
1016 | login_req_buf_failure: | |
1017 | iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data, | |
1018 | "login resource alloc failed!!\n"); | |
1019 | return -ENOMEM; | |
1020 | ||
1021 | } | |
1022 | ||
1023 | ||
1024 | /** | |
1025 | * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table. | |
1026 | * @bnx2i_conn: iscsi connection pointer | |
1027 | * | |
1028 | * Allocates buffers and BD tables before shipping requests to cnic | |
1029 | * for PDUs prepared by 'iscsid' daemon | |
1030 | */ | |
1031 | static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn *bnx2i_conn) | |
1032 | { | |
1033 | struct iscsi_bd *bd_tbl; | |
1034 | ||
1035 | bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl; | |
1036 | ||
1037 | bd_tbl->buffer_addr_hi = | |
1038 | (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32); | |
1039 | bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr; | |
1040 | bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr - | |
1041 | bnx2i_conn->gen_pdu.req_buf; | |
1042 | bd_tbl->reserved0 = 0; | |
1043 | bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN | | |
1044 | ISCSI_BD_FIRST_IN_BD_CHAIN; | |
1045 | ||
1046 | bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl; | |
1047 | bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32; | |
1048 | bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr; | |
1049 | bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN; | |
1050 | bd_tbl->reserved0 = 0; | |
1051 | bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN | | |
1052 | ISCSI_BD_FIRST_IN_BD_CHAIN; | |
1053 | } | |
1054 | ||
1055 | ||
1056 | /** | |
1057 | * bnx2i_iscsi_send_generic_request - called to send mgmt tasks. | |
1058 | * @task: transport layer task pointer | |
1059 | * | |
1060 | * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login, | |
1061 | * Nop-out and Logout requests flow through this path. | |
1062 | */ | |
1063 | static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task) | |
1064 | { | |
1065 | struct bnx2i_cmd *cmd = task->dd_data; | |
1066 | struct bnx2i_conn *bnx2i_conn = cmd->conn; | |
1067 | int rc = 0; | |
1068 | char *buf; | |
1069 | int data_len; | |
1070 | ||
1071 | bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn); | |
1072 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { | |
1073 | case ISCSI_OP_LOGIN: | |
1074 | bnx2i_send_iscsi_login(bnx2i_conn, task); | |
1075 | break; | |
1076 | case ISCSI_OP_NOOP_OUT: | |
1077 | data_len = bnx2i_conn->gen_pdu.req_buf_size; | |
1078 | buf = bnx2i_conn->gen_pdu.req_buf; | |
1079 | if (data_len) | |
1080 | rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task, | |
cf4e6363 MC |
1081 | buf, data_len, 1); |
1082 | else | |
1083 | rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task, | |
cf4e6363 MC |
1084 | NULL, 0, 1); |
1085 | break; | |
1086 | case ISCSI_OP_LOGOUT: | |
1087 | rc = bnx2i_send_iscsi_logout(bnx2i_conn, task); | |
1088 | break; | |
1089 | case ISCSI_OP_SCSI_TMFUNC: | |
1090 | rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task); | |
1091 | break; | |
1092 | default: | |
1093 | iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data, | |
1094 | "send_gen: unsupported op 0x%x\n", | |
1095 | task->hdr->opcode); | |
1096 | } | |
1097 | return rc; | |
1098 | } | |
1099 | ||
1100 | ||
1101 | /********************************************************************** | |
1102 | * SCSI-ML Interface | |
1103 | **********************************************************************/ | |
1104 | ||
1105 | /** | |
1106 | * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe | |
1107 | * @sc: SCSI-ML command pointer | |
1108 | * @cmd: iscsi cmd pointer | |
1109 | */ | |
1110 | static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd) | |
1111 | { | |
1112 | u32 dword; | |
1113 | int lpcnt; | |
1114 | u8 *srcp; | |
1115 | u32 *dstp; | |
1116 | u32 scsi_lun[2]; | |
1117 | ||
1118 | int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun); | |
1119 | cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]); | |
1120 | cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]); | |
1121 | ||
1122 | lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword); | |
1123 | srcp = (u8 *) sc->cmnd; | |
1124 | dstp = (u32 *) cmd->req.cdb; | |
1125 | while (lpcnt--) { | |
1126 | memcpy(&dword, (const void *) srcp, 4); | |
1127 | *dstp = cpu_to_be32(dword); | |
1128 | srcp += 4; | |
1129 | dstp++; | |
1130 | } | |
1131 | if (sc->cmd_len & 0x3) { | |
1132 | dword = (u32) srcp[0] | ((u32) srcp[1] << 8); | |
1133 | *dstp = cpu_to_be32(dword); | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | static void bnx2i_cleanup_task(struct iscsi_task *task) | |
1138 | { | |
1139 | struct iscsi_conn *conn = task->conn; | |
1140 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1141 | struct bnx2i_hba *hba = bnx2i_conn->hba; | |
1142 | ||
1143 | /* | |
1144 | * mgmt task or cmd was never sent to us to transmit. | |
1145 | */ | |
1146 | if (!task->sc || task->state == ISCSI_TASK_PENDING) | |
1147 | return; | |
1148 | /* | |
1149 | * need to clean-up task context to claim dma buffers | |
1150 | */ | |
1151 | if (task->state == ISCSI_TASK_ABRT_TMF) { | |
1152 | bnx2i_send_cmd_cleanup_req(hba, task->dd_data); | |
1153 | ||
1154 | spin_unlock_bh(&conn->session->lock); | |
1155 | wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl, | |
1156 | msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT)); | |
1157 | spin_lock_bh(&conn->session->lock); | |
1158 | } | |
1159 | bnx2i_iscsi_unmap_sg_list(task->dd_data); | |
1160 | } | |
1161 | ||
1162 | /** | |
1163 | * bnx2i_mtask_xmit - transmit mtask to chip for further processing | |
1164 | * @conn: transport layer conn structure pointer | |
1165 | * @task: transport layer command structure pointer | |
1166 | */ | |
1167 | static int | |
1168 | bnx2i_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task) | |
1169 | { | |
1170 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1171 | struct bnx2i_cmd *cmd = task->dd_data; | |
1172 | ||
1173 | memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN); | |
1174 | ||
1175 | bnx2i_setup_cmd_wqe_template(cmd); | |
1176 | bnx2i_conn->gen_pdu.req_buf_size = task->data_count; | |
1177 | if (task->data_count) { | |
1178 | memcpy(bnx2i_conn->gen_pdu.req_buf, task->data, | |
1179 | task->data_count); | |
1180 | bnx2i_conn->gen_pdu.req_wr_ptr = | |
1181 | bnx2i_conn->gen_pdu.req_buf + task->data_count; | |
1182 | } | |
1183 | cmd->conn = conn->dd_data; | |
1184 | cmd->scsi_cmd = NULL; | |
1185 | return bnx2i_iscsi_send_generic_request(task); | |
1186 | } | |
1187 | ||
1188 | /** | |
1189 | * bnx2i_task_xmit - transmit iscsi command to chip for further processing | |
1190 | * @task: transport layer command structure pointer | |
1191 | * | |
1192 | * maps SG buffers and send request to chip/firmware in the form of SQ WQE | |
1193 | */ | |
1194 | static int bnx2i_task_xmit(struct iscsi_task *task) | |
1195 | { | |
1196 | struct iscsi_conn *conn = task->conn; | |
1197 | struct iscsi_session *session = conn->session; | |
1198 | struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); | |
1199 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
1200 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1201 | struct scsi_cmnd *sc = task->sc; | |
1202 | struct bnx2i_cmd *cmd = task->dd_data; | |
1203 | struct iscsi_cmd *hdr = (struct iscsi_cmd *) task->hdr; | |
1204 | ||
cf4e6363 MC |
1205 | /* |
1206 | * If there is no scsi_cmnd this must be a mgmt task | |
1207 | */ | |
1208 | if (!sc) | |
1209 | return bnx2i_mtask_xmit(conn, task); | |
1210 | ||
1211 | bnx2i_setup_cmd_wqe_template(cmd); | |
1212 | cmd->req.op_code = ISCSI_OP_SCSI_CMD; | |
1213 | cmd->conn = bnx2i_conn; | |
1214 | cmd->scsi_cmd = sc; | |
1215 | cmd->req.total_data_transfer_length = scsi_bufflen(sc); | |
1216 | cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn); | |
1217 | ||
1218 | bnx2i_iscsi_map_sg_list(cmd); | |
1219 | bnx2i_cpy_scsi_cdb(sc, cmd); | |
1220 | ||
1221 | cmd->req.op_attr = ISCSI_ATTR_SIMPLE; | |
1222 | if (sc->sc_data_direction == DMA_TO_DEVICE) { | |
1223 | cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE; | |
1224 | cmd->req.itt = task->itt | | |
1225 | (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT); | |
1226 | bnx2i_setup_write_cmd_bd_info(task); | |
1227 | } else { | |
1228 | if (scsi_bufflen(sc)) | |
1229 | cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ; | |
1230 | cmd->req.itt = task->itt | | |
1231 | (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT); | |
1232 | } | |
1233 | ||
1234 | cmd->req.num_bds = cmd->io_tbl.bd_valid; | |
1235 | if (!cmd->io_tbl.bd_valid) { | |
1236 | cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma; | |
1237 | cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32); | |
1238 | cmd->req.num_bds = 1; | |
1239 | } | |
1240 | ||
1241 | bnx2i_send_iscsi_scsicmd(bnx2i_conn, cmd); | |
1242 | return 0; | |
1243 | } | |
1244 | ||
1245 | /** | |
1246 | * bnx2i_session_create - create a new iscsi session | |
1247 | * @cmds_max: max commands supported | |
1248 | * @qdepth: scsi queue depth to support | |
1249 | * @initial_cmdsn: initial iscsi CMDSN to be used for this session | |
1250 | * | |
1251 | * Creates a new iSCSI session instance on given device. | |
1252 | */ | |
1253 | static struct iscsi_cls_session * | |
1254 | bnx2i_session_create(struct iscsi_endpoint *ep, | |
1255 | uint16_t cmds_max, uint16_t qdepth, | |
1256 | uint32_t initial_cmdsn) | |
1257 | { | |
1258 | struct Scsi_Host *shost; | |
1259 | struct iscsi_cls_session *cls_session; | |
1260 | struct bnx2i_hba *hba; | |
1261 | struct bnx2i_endpoint *bnx2i_ep; | |
1262 | ||
1263 | if (!ep) { | |
1264 | printk(KERN_ERR "bnx2i: missing ep.\n"); | |
1265 | return NULL; | |
1266 | } | |
1267 | ||
1268 | bnx2i_ep = ep->dd_data; | |
1269 | shost = bnx2i_ep->hba->shost; | |
1270 | hba = iscsi_host_priv(shost); | |
1271 | if (bnx2i_adapter_ready(hba)) | |
1272 | return NULL; | |
1273 | ||
1274 | /* | |
1275 | * user can override hw limit as long as it is within | |
1276 | * the min/max. | |
1277 | */ | |
1278 | if (cmds_max > hba->max_sqes) | |
1279 | cmds_max = hba->max_sqes; | |
1280 | else if (cmds_max < BNX2I_SQ_WQES_MIN) | |
1281 | cmds_max = BNX2I_SQ_WQES_MIN; | |
1282 | ||
1283 | cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost, | |
b8b9e1b8 | 1284 | cmds_max, 0, sizeof(struct bnx2i_cmd), |
cf4e6363 MC |
1285 | initial_cmdsn, ISCSI_MAX_TARGET); |
1286 | if (!cls_session) | |
1287 | return NULL; | |
1288 | ||
1289 | if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data)) | |
1290 | goto session_teardown; | |
1291 | return cls_session; | |
1292 | ||
1293 | session_teardown: | |
1294 | iscsi_session_teardown(cls_session); | |
1295 | return NULL; | |
1296 | } | |
1297 | ||
1298 | ||
1299 | /** | |
1300 | * bnx2i_session_destroy - destroys iscsi session | |
1301 | * @cls_session: pointer to iscsi cls session | |
1302 | * | |
1303 | * Destroys previously created iSCSI session instance and releases | |
1304 | * all resources held by it | |
1305 | */ | |
1306 | static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session) | |
1307 | { | |
1308 | struct iscsi_session *session = cls_session->dd_data; | |
1309 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | |
1310 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
1311 | ||
1312 | bnx2i_destroy_cmd_pool(hba, session); | |
1313 | iscsi_session_teardown(cls_session); | |
1314 | } | |
1315 | ||
1316 | ||
1317 | /** | |
1318 | * bnx2i_conn_create - create iscsi connection instance | |
1319 | * @cls_session: pointer to iscsi cls session | |
1320 | * @cid: iscsi cid as per rfc (not NX2's CID terminology) | |
1321 | * | |
1322 | * Creates a new iSCSI connection instance for a given session | |
1323 | */ | |
1324 | static struct iscsi_cls_conn * | |
1325 | bnx2i_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid) | |
1326 | { | |
1327 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | |
1328 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
1329 | struct bnx2i_conn *bnx2i_conn; | |
1330 | struct iscsi_cls_conn *cls_conn; | |
1331 | struct iscsi_conn *conn; | |
1332 | ||
1333 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*bnx2i_conn), | |
1334 | cid); | |
1335 | if (!cls_conn) | |
1336 | return NULL; | |
1337 | conn = cls_conn->dd_data; | |
1338 | ||
1339 | bnx2i_conn = conn->dd_data; | |
1340 | bnx2i_conn->cls_conn = cls_conn; | |
1341 | bnx2i_conn->hba = hba; | |
1342 | /* 'ep' ptr will be assigned in bind() call */ | |
1343 | bnx2i_conn->ep = NULL; | |
1344 | init_completion(&bnx2i_conn->cmd_cleanup_cmpl); | |
1345 | ||
1346 | if (bnx2i_conn_alloc_login_resources(hba, bnx2i_conn)) { | |
1347 | iscsi_conn_printk(KERN_ALERT, conn, | |
1348 | "conn_new: login resc alloc failed!!\n"); | |
1349 | goto free_conn; | |
1350 | } | |
1351 | ||
1352 | return cls_conn; | |
1353 | ||
1354 | free_conn: | |
1355 | iscsi_conn_teardown(cls_conn); | |
1356 | return NULL; | |
1357 | } | |
1358 | ||
1359 | /** | |
1360 | * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together | |
1361 | * @cls_session: pointer to iscsi cls session | |
1362 | * @cls_conn: pointer to iscsi cls conn | |
1363 | * @transport_fd: 64-bit EP handle | |
1364 | * @is_leading: leading connection on this session? | |
1365 | * | |
1366 | * Binds together iSCSI session instance, iSCSI connection instance | |
1367 | * and the TCP connection. This routine returns error code if | |
1368 | * TCP connection does not belong on the device iSCSI sess/conn | |
1369 | * is bound | |
1370 | */ | |
1371 | static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, | |
1372 | struct iscsi_cls_conn *cls_conn, | |
1373 | uint64_t transport_fd, int is_leading) | |
1374 | { | |
1375 | struct iscsi_conn *conn = cls_conn->dd_data; | |
1376 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1377 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | |
1378 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
1379 | struct bnx2i_endpoint *bnx2i_ep; | |
1380 | struct iscsi_endpoint *ep; | |
1381 | int ret_code; | |
1382 | ||
1383 | ep = iscsi_lookup_endpoint(transport_fd); | |
1384 | if (!ep) | |
1385 | return -EINVAL; | |
1386 | ||
1387 | bnx2i_ep = ep->dd_data; | |
1388 | if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) || | |
1389 | (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) | |
1390 | /* Peer disconnect via' FIN or RST */ | |
1391 | return -EINVAL; | |
1392 | ||
1393 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) | |
1394 | return -EINVAL; | |
1395 | ||
1396 | if (bnx2i_ep->hba != hba) { | |
1397 | /* Error - TCP connection does not belong to this device | |
1398 | */ | |
1399 | iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, | |
1400 | "conn bind, ep=0x%p (%s) does not", | |
1401 | bnx2i_ep, bnx2i_ep->hba->netdev->name); | |
1402 | iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, | |
1403 | "belong to hba (%s)\n", | |
1404 | hba->netdev->name); | |
1405 | return -EEXIST; | |
1406 | } | |
1407 | ||
1408 | bnx2i_ep->conn = bnx2i_conn; | |
1409 | bnx2i_conn->ep = bnx2i_ep; | |
1410 | bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid; | |
1411 | bnx2i_conn->fw_cid = bnx2i_ep->ep_cid; | |
cf4e6363 MC |
1412 | |
1413 | ret_code = bnx2i_bind_conn_to_iscsi_cid(hba, bnx2i_conn, | |
1414 | bnx2i_ep->ep_iscsi_cid); | |
1415 | ||
1416 | /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710 | |
1417 | * driver needs to explicitly replenish RQ index during setup. | |
1418 | */ | |
1419 | if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type)) | |
1420 | bnx2i_put_rq_buf(bnx2i_conn, 0); | |
1421 | ||
1422 | bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE); | |
1423 | return ret_code; | |
1424 | } | |
1425 | ||
1426 | ||
1427 | /** | |
1428 | * bnx2i_conn_destroy - destroy iscsi connection instance & release resources | |
1429 | * @cls_conn: pointer to iscsi cls conn | |
1430 | * | |
1431 | * Destroy an iSCSI connection instance and release memory resources held by | |
1432 | * this connection | |
1433 | */ | |
1434 | static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn) | |
1435 | { | |
1436 | struct iscsi_conn *conn = cls_conn->dd_data; | |
1437 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1438 | struct Scsi_Host *shost; | |
1439 | struct bnx2i_hba *hba; | |
1440 | ||
1441 | shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn)); | |
1442 | hba = iscsi_host_priv(shost); | |
1443 | ||
1444 | bnx2i_conn_free_login_resources(hba, bnx2i_conn); | |
1445 | iscsi_conn_teardown(cls_conn); | |
1446 | } | |
1447 | ||
1448 | ||
1449 | /** | |
1450 | * bnx2i_conn_get_param - return iscsi connection parameter to caller | |
1451 | * @cls_conn: pointer to iscsi cls conn | |
1452 | * @param: parameter type identifier | |
1453 | * @buf: buffer pointer | |
1454 | * | |
1455 | * returns iSCSI connection parameters | |
1456 | */ | |
1457 | static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn, | |
1458 | enum iscsi_param param, char *buf) | |
1459 | { | |
1460 | struct iscsi_conn *conn = cls_conn->dd_data; | |
1461 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1462 | int len = 0; | |
1463 | ||
1464 | switch (param) { | |
1465 | case ISCSI_PARAM_CONN_PORT: | |
1466 | if (bnx2i_conn->ep) | |
1467 | len = sprintf(buf, "%hu\n", | |
1468 | bnx2i_conn->ep->cm_sk->dst_port); | |
1469 | break; | |
1470 | case ISCSI_PARAM_CONN_ADDRESS: | |
1471 | if (bnx2i_conn->ep) | |
d9573e7a JP |
1472 | len = sprintf(buf, "%pI4\n", |
1473 | &bnx2i_conn->ep->cm_sk->dst_ip); | |
cf4e6363 MC |
1474 | break; |
1475 | default: | |
1476 | return iscsi_conn_get_param(cls_conn, param, buf); | |
1477 | } | |
1478 | ||
1479 | return len; | |
1480 | } | |
1481 | ||
1482 | /** | |
1483 | * bnx2i_host_get_param - returns host (adapter) related parameters | |
1484 | * @shost: scsi host pointer | |
1485 | * @param: parameter type identifier | |
1486 | * @buf: buffer pointer | |
1487 | */ | |
1488 | static int bnx2i_host_get_param(struct Scsi_Host *shost, | |
1489 | enum iscsi_host_param param, char *buf) | |
1490 | { | |
1491 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
1492 | int len = 0; | |
1493 | ||
1494 | switch (param) { | |
1495 | case ISCSI_HOST_PARAM_HWADDRESS: | |
1496 | len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6); | |
1497 | break; | |
1498 | case ISCSI_HOST_PARAM_NETDEV_NAME: | |
1499 | len = sprintf(buf, "%s\n", hba->netdev->name); | |
1500 | break; | |
625986c2 MC |
1501 | case ISCSI_HOST_PARAM_IPADDRESS: { |
1502 | struct list_head *active_list = &hba->ep_active_list; | |
1503 | ||
1504 | read_lock_bh(&hba->ep_rdwr_lock); | |
1505 | if (!list_empty(&hba->ep_active_list)) { | |
1506 | struct bnx2i_endpoint *bnx2i_ep; | |
1507 | struct cnic_sock *csk; | |
1508 | ||
1509 | bnx2i_ep = list_first_entry(active_list, | |
1510 | struct bnx2i_endpoint, | |
1511 | link); | |
1512 | csk = bnx2i_ep->cm_sk; | |
1513 | if (test_bit(SK_F_IPV6, &csk->flags)) | |
1514 | len = sprintf(buf, "%pI6\n", csk->src_ip); | |
1515 | else | |
1516 | len = sprintf(buf, "%pI4\n", csk->src_ip); | |
1517 | } | |
1518 | read_unlock_bh(&hba->ep_rdwr_lock); | |
1519 | break; | |
1520 | } | |
cf4e6363 MC |
1521 | default: |
1522 | return iscsi_host_get_param(shost, param, buf); | |
1523 | } | |
1524 | return len; | |
1525 | } | |
1526 | ||
1527 | /** | |
1528 | * bnx2i_conn_start - completes iscsi connection migration to FFP | |
1529 | * @cls_conn: pointer to iscsi cls conn | |
1530 | * | |
1531 | * last call in FFP migration to handover iscsi conn to the driver | |
1532 | */ | |
1533 | static int bnx2i_conn_start(struct iscsi_cls_conn *cls_conn) | |
1534 | { | |
1535 | struct iscsi_conn *conn = cls_conn->dd_data; | |
1536 | struct bnx2i_conn *bnx2i_conn = conn->dd_data; | |
1537 | ||
1538 | bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START; | |
1539 | bnx2i_update_iscsi_conn(conn); | |
1540 | ||
1541 | /* | |
1542 | * this should normally not sleep for a long time so it should | |
1543 | * not disrupt the caller. | |
1544 | */ | |
1545 | bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies; | |
1546 | bnx2i_conn->ep->ofld_timer.function = bnx2i_ep_ofld_timer; | |
1547 | bnx2i_conn->ep->ofld_timer.data = (unsigned long) bnx2i_conn->ep; | |
1548 | add_timer(&bnx2i_conn->ep->ofld_timer); | |
1549 | /* update iSCSI context for this conn, wait for CNIC to complete */ | |
1550 | wait_event_interruptible(bnx2i_conn->ep->ofld_wait, | |
1551 | bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START); | |
1552 | ||
1553 | if (signal_pending(current)) | |
1554 | flush_signals(current); | |
1555 | del_timer_sync(&bnx2i_conn->ep->ofld_timer); | |
1556 | ||
1557 | iscsi_conn_start(cls_conn); | |
1558 | return 0; | |
1559 | } | |
1560 | ||
1561 | ||
1562 | /** | |
1563 | * bnx2i_conn_get_stats - returns iSCSI stats | |
1564 | * @cls_conn: pointer to iscsi cls conn | |
1565 | * @stats: pointer to iscsi statistic struct | |
1566 | */ | |
1567 | static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn, | |
1568 | struct iscsi_stats *stats) | |
1569 | { | |
1570 | struct iscsi_conn *conn = cls_conn->dd_data; | |
1571 | ||
1572 | stats->txdata_octets = conn->txdata_octets; | |
1573 | stats->rxdata_octets = conn->rxdata_octets; | |
1574 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; | |
1575 | stats->dataout_pdus = conn->dataout_pdus_cnt; | |
1576 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; | |
1577 | stats->datain_pdus = conn->datain_pdus_cnt; | |
1578 | stats->r2t_pdus = conn->r2t_pdus_cnt; | |
1579 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; | |
1580 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; | |
1581 | stats->custom_length = 3; | |
1582 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); | |
1583 | stats->custom[2].value = conn->eh_abort_cnt; | |
1584 | stats->digest_err = 0; | |
1585 | stats->timeout_err = 0; | |
1586 | stats->custom_length = 0; | |
1587 | } | |
1588 | ||
1589 | ||
1590 | /** | |
1591 | * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices | |
1592 | * @dst_addr: target IP address | |
1593 | * | |
1594 | * check if route resolves to BNX2 device | |
1595 | */ | |
1596 | static struct bnx2i_hba *bnx2i_check_route(struct sockaddr *dst_addr) | |
1597 | { | |
1598 | struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr; | |
1599 | struct bnx2i_hba *hba; | |
1600 | struct cnic_dev *cnic = NULL; | |
1601 | ||
1602 | bnx2i_reg_dev_all(); | |
1603 | ||
1604 | hba = get_adapter_list_head(); | |
1605 | if (hba && hba->cnic) | |
1606 | cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI); | |
1607 | if (!cnic) { | |
1608 | printk(KERN_ALERT "bnx2i: no route," | |
1609 | "can't connect using cnic\n"); | |
1610 | goto no_nx2_route; | |
1611 | } | |
1612 | hba = bnx2i_find_hba_for_cnic(cnic); | |
1613 | if (!hba) | |
1614 | goto no_nx2_route; | |
1615 | ||
1616 | if (bnx2i_adapter_ready(hba)) { | |
1617 | printk(KERN_ALERT "bnx2i: check route, hba not found\n"); | |
1618 | goto no_nx2_route; | |
1619 | } | |
1620 | if (hba->netdev->mtu > hba->mtu_supported) { | |
1621 | printk(KERN_ALERT "bnx2i: %s network i/f mtu is set to %d\n", | |
1622 | hba->netdev->name, hba->netdev->mtu); | |
1623 | printk(KERN_ALERT "bnx2i: iSCSI HBA can support mtu of %d\n", | |
1624 | hba->mtu_supported); | |
1625 | goto no_nx2_route; | |
1626 | } | |
1627 | return hba; | |
1628 | no_nx2_route: | |
1629 | return NULL; | |
1630 | } | |
1631 | ||
1632 | ||
1633 | /** | |
1634 | * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources | |
1635 | * @hba: pointer to adapter instance | |
1636 | * @ep: endpoint (transport indentifier) structure | |
1637 | * | |
1638 | * destroys cm_sock structure and on chip iscsi context | |
1639 | */ | |
1640 | static int bnx2i_tear_down_conn(struct bnx2i_hba *hba, | |
1641 | struct bnx2i_endpoint *ep) | |
1642 | { | |
1643 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) | |
1644 | hba->cnic->cm_destroy(ep->cm_sk); | |
1645 | ||
1646 | if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state)) | |
1647 | ep->state = EP_STATE_DISCONN_COMPL; | |
1648 | ||
1649 | if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) && | |
1650 | ep->state == EP_STATE_DISCONN_TIMEDOUT) { | |
1651 | printk(KERN_ALERT "bnx2i - ERROR - please submit GRC Dump," | |
1652 | " NW/PCIe trace, driver msgs to developers" | |
1653 | " for analysis\n"); | |
1654 | return 1; | |
1655 | } | |
1656 | ||
1657 | ep->state = EP_STATE_CLEANUP_START; | |
1658 | init_timer(&ep->ofld_timer); | |
e37d2c47 | 1659 | ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies; |
cf4e6363 MC |
1660 | ep->ofld_timer.function = bnx2i_ep_ofld_timer; |
1661 | ep->ofld_timer.data = (unsigned long) ep; | |
1662 | add_timer(&ep->ofld_timer); | |
1663 | ||
1664 | bnx2i_ep_destroy_list_add(hba, ep); | |
1665 | ||
1666 | /* destroy iSCSI context, wait for it to complete */ | |
1667 | bnx2i_send_conn_destroy(hba, ep); | |
1668 | wait_event_interruptible(ep->ofld_wait, | |
1669 | (ep->state != EP_STATE_CLEANUP_START)); | |
1670 | ||
1671 | if (signal_pending(current)) | |
1672 | flush_signals(current); | |
1673 | del_timer_sync(&ep->ofld_timer); | |
1674 | ||
1675 | bnx2i_ep_destroy_list_del(hba, ep); | |
1676 | ||
1677 | if (ep->state != EP_STATE_CLEANUP_CMPL) | |
1678 | /* should never happen */ | |
1679 | printk(KERN_ALERT "bnx2i - conn destroy failed\n"); | |
1680 | ||
1681 | return 0; | |
1682 | } | |
1683 | ||
1684 | ||
1685 | /** | |
1686 | * bnx2i_ep_connect - establish TCP connection to target portal | |
1687 | * @shost: scsi host | |
1688 | * @dst_addr: target IP address | |
1689 | * @non_blocking: blocking or non-blocking call | |
1690 | * | |
1691 | * this routine initiates the TCP/IP connection by invoking Option-2 i/f | |
1692 | * with l5_core and the CNIC. This is a multi-step process of resolving | |
1693 | * route to target, create a iscsi connection context, handshaking with | |
1694 | * CNIC module to create/initialize the socket struct and finally | |
1695 | * sending down option-2 request to complete TCP 3-way handshake | |
1696 | */ | |
1697 | static struct iscsi_endpoint *bnx2i_ep_connect(struct Scsi_Host *shost, | |
1698 | struct sockaddr *dst_addr, | |
1699 | int non_blocking) | |
1700 | { | |
1701 | u32 iscsi_cid = BNX2I_CID_RESERVED; | |
1702 | struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr; | |
1703 | struct sockaddr_in6 *desti6; | |
1704 | struct bnx2i_endpoint *bnx2i_ep; | |
1705 | struct bnx2i_hba *hba; | |
1706 | struct cnic_dev *cnic; | |
1707 | struct cnic_sockaddr saddr; | |
1708 | struct iscsi_endpoint *ep; | |
1709 | int rc = 0; | |
1710 | ||
fac3cc45 | 1711 | if (shost) { |
cf4e6363 MC |
1712 | /* driver is given scsi host to work with */ |
1713 | hba = iscsi_host_priv(shost); | |
fac3cc45 AV |
1714 | /* Register the device with cnic if not already done so */ |
1715 | bnx2i_register_device(hba); | |
1716 | } else | |
cf4e6363 MC |
1717 | /* |
1718 | * check if the given destination can be reached through | |
1719 | * a iscsi capable NetXtreme2 device | |
1720 | */ | |
1721 | hba = bnx2i_check_route(dst_addr); | |
fac3cc45 | 1722 | |
490475a9 AV |
1723 | if (!hba || test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state)) { |
1724 | rc = -EINVAL; | |
55e15c97 | 1725 | goto nohba; |
cf4e6363 MC |
1726 | } |
1727 | ||
1728 | cnic = hba->cnic; | |
55e15c97 | 1729 | mutex_lock(&hba->net_dev_lock); |
cf4e6363 MC |
1730 | ep = bnx2i_alloc_ep(hba); |
1731 | if (!ep) { | |
1732 | rc = -ENOMEM; | |
1733 | goto check_busy; | |
1734 | } | |
1735 | bnx2i_ep = ep->dd_data; | |
1736 | ||
cf4e6363 MC |
1737 | if (bnx2i_adapter_ready(hba)) { |
1738 | rc = -EPERM; | |
1739 | goto net_if_down; | |
1740 | } | |
1741 | ||
cf4e6363 MC |
1742 | bnx2i_ep->num_active_cmds = 0; |
1743 | iscsi_cid = bnx2i_alloc_iscsi_cid(hba); | |
1744 | if (iscsi_cid == -1) { | |
1745 | printk(KERN_ALERT "alloc_ep: unable to allocate iscsi cid\n"); | |
1746 | rc = -ENOMEM; | |
1747 | goto iscsi_cid_err; | |
1748 | } | |
1749 | bnx2i_ep->hba_age = hba->age; | |
1750 | ||
1751 | rc = bnx2i_alloc_qp_resc(hba, bnx2i_ep); | |
1752 | if (rc != 0) { | |
1753 | printk(KERN_ALERT "bnx2i: ep_conn, alloc QP resc error\n"); | |
1754 | rc = -ENOMEM; | |
1755 | goto qp_resc_err; | |
1756 | } | |
1757 | ||
1758 | bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid; | |
1759 | bnx2i_ep->state = EP_STATE_OFLD_START; | |
1760 | bnx2i_ep_ofld_list_add(hba, bnx2i_ep); | |
1761 | ||
1762 | init_timer(&bnx2i_ep->ofld_timer); | |
1763 | bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies; | |
1764 | bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer; | |
1765 | bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep; | |
1766 | add_timer(&bnx2i_ep->ofld_timer); | |
1767 | ||
1768 | bnx2i_send_conn_ofld_req(hba, bnx2i_ep); | |
1769 | ||
1770 | /* Wait for CNIC hardware to setup conn context and return 'cid' */ | |
1771 | wait_event_interruptible(bnx2i_ep->ofld_wait, | |
1772 | bnx2i_ep->state != EP_STATE_OFLD_START); | |
1773 | ||
1774 | if (signal_pending(current)) | |
1775 | flush_signals(current); | |
1776 | del_timer_sync(&bnx2i_ep->ofld_timer); | |
1777 | ||
1778 | bnx2i_ep_ofld_list_del(hba, bnx2i_ep); | |
1779 | ||
1780 | if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) { | |
1781 | rc = -ENOSPC; | |
1782 | goto conn_failed; | |
1783 | } | |
1784 | ||
1785 | rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid, | |
1786 | iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep); | |
1787 | if (rc) { | |
1788 | rc = -EINVAL; | |
1789 | goto conn_failed; | |
1790 | } | |
1791 | ||
1792 | bnx2i_ep->cm_sk->rcv_buf = 256 * 1024; | |
1793 | bnx2i_ep->cm_sk->snd_buf = 256 * 1024; | |
1794 | clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags); | |
1795 | ||
1796 | memset(&saddr, 0, sizeof(saddr)); | |
1797 | if (dst_addr->sa_family == AF_INET) { | |
1798 | desti = (struct sockaddr_in *) dst_addr; | |
1799 | saddr.remote.v4 = *desti; | |
1800 | saddr.local.v4.sin_family = desti->sin_family; | |
1801 | } else if (dst_addr->sa_family == AF_INET6) { | |
1802 | desti6 = (struct sockaddr_in6 *) dst_addr; | |
1803 | saddr.remote.v6 = *desti6; | |
1804 | saddr.local.v6.sin6_family = desti6->sin6_family; | |
1805 | } | |
1806 | ||
1807 | bnx2i_ep->timestamp = jiffies; | |
1808 | bnx2i_ep->state = EP_STATE_CONNECT_START; | |
1809 | if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { | |
1810 | rc = -EINVAL; | |
1811 | goto conn_failed; | |
1812 | } else | |
1813 | rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr); | |
cf4e6363 MC |
1814 | if (rc) |
1815 | goto release_ep; | |
1816 | ||
46012e8b EW |
1817 | bnx2i_ep_active_list_add(hba, bnx2i_ep); |
1818 | ||
cf4e6363 | 1819 | if (bnx2i_map_ep_dbell_regs(bnx2i_ep)) |
46012e8b EW |
1820 | goto del_active_ep; |
1821 | ||
cf4e6363 MC |
1822 | mutex_unlock(&hba->net_dev_lock); |
1823 | return ep; | |
1824 | ||
46012e8b EW |
1825 | del_active_ep: |
1826 | bnx2i_ep_active_list_del(hba, bnx2i_ep); | |
cf4e6363 MC |
1827 | release_ep: |
1828 | if (bnx2i_tear_down_conn(hba, bnx2i_ep)) { | |
1829 | mutex_unlock(&hba->net_dev_lock); | |
1830 | return ERR_PTR(rc); | |
1831 | } | |
1832 | conn_failed: | |
1833 | net_if_down: | |
1834 | iscsi_cid_err: | |
1835 | bnx2i_free_qp_resc(hba, bnx2i_ep); | |
1836 | qp_resc_err: | |
1837 | bnx2i_free_ep(ep); | |
cf4e6363 | 1838 | check_busy: |
55e15c97 EW |
1839 | mutex_unlock(&hba->net_dev_lock); |
1840 | nohba: | |
cf4e6363 MC |
1841 | bnx2i_unreg_dev_all(); |
1842 | return ERR_PTR(rc); | |
1843 | } | |
1844 | ||
1845 | ||
1846 | /** | |
1847 | * bnx2i_ep_poll - polls for TCP connection establishement | |
1848 | * @ep: TCP connection (endpoint) handle | |
1849 | * @timeout_ms: timeout value in milli secs | |
1850 | * | |
1851 | * polls for TCP connect request to complete | |
1852 | */ | |
1853 | static int bnx2i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) | |
1854 | { | |
1855 | struct bnx2i_endpoint *bnx2i_ep; | |
1856 | int rc = 0; | |
1857 | ||
1858 | bnx2i_ep = ep->dd_data; | |
1859 | if ((bnx2i_ep->state == EP_STATE_IDLE) || | |
1860 | (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) || | |
1861 | (bnx2i_ep->state == EP_STATE_OFLD_FAILED)) | |
1862 | return -1; | |
1863 | if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL) | |
1864 | return 1; | |
1865 | ||
1866 | rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait, | |
1867 | ((bnx2i_ep->state == | |
1868 | EP_STATE_OFLD_FAILED) || | |
1869 | (bnx2i_ep->state == | |
1870 | EP_STATE_CONNECT_FAILED) || | |
1871 | (bnx2i_ep->state == | |
1872 | EP_STATE_CONNECT_COMPL)), | |
1873 | msecs_to_jiffies(timeout_ms)); | |
490475a9 | 1874 | if (bnx2i_ep->state == EP_STATE_OFLD_FAILED) |
cf4e6363 MC |
1875 | rc = -1; |
1876 | ||
1877 | if (rc > 0) | |
1878 | return 1; | |
1879 | else if (!rc) | |
1880 | return 0; /* timeout */ | |
1881 | else | |
1882 | return rc; | |
1883 | } | |
1884 | ||
1885 | ||
1886 | /** | |
1887 | * bnx2i_ep_tcp_conn_active - check EP state transition | |
1888 | * @ep: endpoint pointer | |
1889 | * | |
1890 | * check if underlying TCP connection is active | |
1891 | */ | |
1892 | static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep) | |
1893 | { | |
1894 | int ret; | |
1895 | int cnic_dev_10g = 0; | |
1896 | ||
1897 | if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type)) | |
1898 | cnic_dev_10g = 1; | |
1899 | ||
1900 | switch (bnx2i_ep->state) { | |
1901 | case EP_STATE_CONNECT_START: | |
1902 | case EP_STATE_CLEANUP_FAILED: | |
1903 | case EP_STATE_OFLD_FAILED: | |
1904 | case EP_STATE_DISCONN_TIMEDOUT: | |
1905 | ret = 0; | |
1906 | break; | |
1907 | case EP_STATE_CONNECT_COMPL: | |
1908 | case EP_STATE_ULP_UPDATE_START: | |
1909 | case EP_STATE_ULP_UPDATE_COMPL: | |
1910 | case EP_STATE_TCP_FIN_RCVD: | |
2eefb20d EW |
1911 | case EP_STATE_LOGOUT_SENT: |
1912 | case EP_STATE_LOGOUT_RESP_RCVD: | |
cf4e6363 MC |
1913 | case EP_STATE_ULP_UPDATE_FAILED: |
1914 | ret = 1; | |
1915 | break; | |
1916 | case EP_STATE_TCP_RST_RCVD: | |
1917 | ret = 0; | |
1918 | break; | |
1919 | case EP_STATE_CONNECT_FAILED: | |
1920 | if (cnic_dev_10g) | |
1921 | ret = 1; | |
1922 | else | |
1923 | ret = 0; | |
1924 | break; | |
1925 | default: | |
1926 | ret = 0; | |
1927 | } | |
1928 | ||
1929 | return ret; | |
1930 | } | |
1931 | ||
1932 | ||
6447f286 EW |
1933 | /* |
1934 | * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw | |
1935 | * @ep: TCP connection (bnx2i endpoint) handle | |
cf4e6363 MC |
1936 | * |
1937 | * executes TCP connection teardown process | |
1938 | */ | |
6447f286 | 1939 | int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep) |
cf4e6363 | 1940 | { |
6447f286 | 1941 | struct bnx2i_hba *hba = bnx2i_ep->hba; |
cf4e6363 | 1942 | struct cnic_dev *cnic; |
6447f286 EW |
1943 | struct iscsi_session *session = NULL; |
1944 | struct iscsi_conn *conn = NULL; | |
1945 | int ret = 0; | |
2eefb20d EW |
1946 | int close = 0; |
1947 | int close_ret = 0; | |
cf4e6363 | 1948 | |
6447f286 EW |
1949 | if (!hba) |
1950 | return 0; | |
cf4e6363 | 1951 | |
6447f286 EW |
1952 | cnic = hba->cnic; |
1953 | if (!cnic) | |
1954 | return 0; | |
1955 | ||
1956 | if (!bnx2i_ep_tcp_conn_active(bnx2i_ep)) | |
1957 | goto destroy_conn; | |
cf4e6363 MC |
1958 | |
1959 | if (bnx2i_ep->conn) { | |
6447f286 | 1960 | conn = bnx2i_ep->conn->cls_conn->dd_data; |
cf4e6363 | 1961 | session = conn->session; |
cf4e6363 MC |
1962 | } |
1963 | ||
cf4e6363 | 1964 | init_timer(&bnx2i_ep->ofld_timer); |
e37d2c47 | 1965 | bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies; |
cf4e6363 MC |
1966 | bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer; |
1967 | bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep; | |
1968 | add_timer(&bnx2i_ep->ofld_timer); | |
1969 | ||
2eefb20d | 1970 | if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) |
6447f286 | 1971 | goto out; |
cf4e6363 | 1972 | |
2eefb20d EW |
1973 | if (session) { |
1974 | spin_lock_bh(&session->lock); | |
1975 | if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) { | |
1976 | if (session->state == ISCSI_STATE_LOGGING_OUT) { | |
1977 | if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) { | |
1978 | /* Logout sent, but no resp */ | |
1979 | printk(KERN_ALERT "bnx2i - WARNING " | |
1980 | "logout response was not " | |
1981 | "received!\n"); | |
1982 | } else if (bnx2i_ep->state == | |
1983 | EP_STATE_LOGOUT_RESP_RCVD) | |
1984 | close = 1; | |
1985 | } | |
1986 | } else | |
1987 | close = 1; | |
1988 | ||
1989 | spin_unlock_bh(&session->lock); | |
1990 | } | |
1991 | ||
1992 | bnx2i_ep->state = EP_STATE_DISCONN_START; | |
1993 | ||
1994 | if (close) | |
1995 | close_ret = cnic->cm_close(bnx2i_ep->cm_sk); | |
1996 | else | |
1997 | close_ret = cnic->cm_abort(bnx2i_ep->cm_sk); | |
1998 | ||
2c2255e0 | 1999 | /* No longer allow CFC delete if cm_close/abort fails the request */ |
2eefb20d | 2000 | if (close_ret) |
2c2255e0 EW |
2001 | printk(KERN_ALERT "bnx2i: %s close/abort(%d) returned %d\n", |
2002 | bnx2i_ep->hba->netdev->name, close, close_ret); | |
2003 | else | |
2004 | /* wait for option-2 conn teardown */ | |
2005 | wait_event_interruptible(bnx2i_ep->ofld_wait, | |
cf4e6363 MC |
2006 | bnx2i_ep->state != EP_STATE_DISCONN_START); |
2007 | ||
2008 | if (signal_pending(current)) | |
2009 | flush_signals(current); | |
2010 | del_timer_sync(&bnx2i_ep->ofld_timer); | |
2011 | ||
6447f286 | 2012 | destroy_conn: |
46012e8b | 2013 | bnx2i_ep_active_list_del(hba, bnx2i_ep); |
6447f286 EW |
2014 | if (bnx2i_tear_down_conn(hba, bnx2i_ep)) |
2015 | ret = -EINVAL; | |
2016 | out: | |
2017 | bnx2i_ep->state = EP_STATE_IDLE; | |
2018 | return ret; | |
2019 | } | |
2020 | ||
2021 | ||
2022 | /** | |
2023 | * bnx2i_ep_disconnect - executes TCP connection teardown process | |
2024 | * @ep: TCP connection (iscsi endpoint) handle | |
2025 | * | |
2026 | * executes TCP connection teardown process | |
2027 | */ | |
2028 | static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep) | |
2029 | { | |
2030 | struct bnx2i_endpoint *bnx2i_ep; | |
2031 | struct bnx2i_conn *bnx2i_conn = NULL; | |
2032 | struct iscsi_conn *conn = NULL; | |
2033 | struct bnx2i_hba *hba; | |
2034 | ||
2035 | bnx2i_ep = ep->dd_data; | |
2036 | ||
2037 | /* driver should not attempt connection cleanup until TCP_CONNECT | |
2038 | * completes either successfully or fails. Timeout is 9-secs, so | |
2039 | * wait for it to complete | |
2040 | */ | |
2041 | while ((bnx2i_ep->state == EP_STATE_CONNECT_START) && | |
2042 | !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ))) | |
2043 | msleep(250); | |
2044 | ||
2045 | if (bnx2i_ep->conn) { | |
2046 | bnx2i_conn = bnx2i_ep->conn; | |
2047 | conn = bnx2i_conn->cls_conn->dd_data; | |
2048 | iscsi_suspend_queue(conn); | |
2049 | } | |
2050 | hba = bnx2i_ep->hba; | |
2051 | ||
2052 | mutex_lock(&hba->net_dev_lock); | |
2053 | ||
2054 | if (bnx2i_ep->state == EP_STATE_IDLE) | |
2055 | goto return_bnx2i_ep; | |
2056 | ||
2057 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) | |
2058 | goto free_resc; | |
2059 | ||
2060 | if (bnx2i_ep->hba_age != hba->age) | |
2061 | goto free_resc; | |
2062 | ||
2063 | /* Do all chip cleanup here */ | |
2064 | if (bnx2i_hw_ep_disconnect(bnx2i_ep)) { | |
cf4e6363 MC |
2065 | mutex_unlock(&hba->net_dev_lock); |
2066 | return; | |
2067 | } | |
2068 | free_resc: | |
cf4e6363 MC |
2069 | bnx2i_free_qp_resc(hba, bnx2i_ep); |
2070 | return_bnx2i_ep: | |
2071 | if (bnx2i_conn) | |
2072 | bnx2i_conn->ep = NULL; | |
2073 | ||
2074 | bnx2i_free_ep(ep); | |
6447f286 | 2075 | mutex_unlock(&hba->net_dev_lock); |
cf4e6363 MC |
2076 | if (!hba->ofld_conns_active) |
2077 | bnx2i_unreg_dev_all(); | |
490475a9 AV |
2078 | |
2079 | wake_up_interruptible(&hba->eh_wait); | |
cf4e6363 MC |
2080 | } |
2081 | ||
2082 | ||
2083 | /** | |
2084 | * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler | |
2085 | * @buf: pointer to buffer containing iscsi path message | |
2086 | * | |
2087 | */ | |
2088 | static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params) | |
2089 | { | |
2090 | struct bnx2i_hba *hba = iscsi_host_priv(shost); | |
2091 | char *buf = (char *) params; | |
2092 | u16 len = sizeof(*params); | |
2093 | ||
2094 | /* handled by cnic driver */ | |
2095 | hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf, | |
2096 | len); | |
2097 | ||
2098 | return 0; | |
2099 | } | |
2100 | ||
2101 | ||
2102 | /* | |
2103 | * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template | |
2104 | * used while registering with the scsi host and iSCSI transport module. | |
2105 | */ | |
2106 | static struct scsi_host_template bnx2i_host_template = { | |
2107 | .module = THIS_MODULE, | |
2108 | .name = "Broadcom Offload iSCSI Initiator", | |
2109 | .proc_name = "bnx2i", | |
2110 | .queuecommand = iscsi_queuecommand, | |
2111 | .eh_abort_handler = iscsi_eh_abort, | |
2112 | .eh_device_reset_handler = iscsi_eh_device_reset, | |
309ce156 | 2113 | .eh_target_reset_handler = iscsi_eh_recover_target, |
9f9127fd | 2114 | .change_queue_depth = iscsi_change_queue_depth, |
cf4e6363 MC |
2115 | .can_queue = 1024, |
2116 | .max_sectors = 127, | |
2117 | .cmd_per_lun = 32, | |
2118 | .this_id = -1, | |
2119 | .use_clustering = ENABLE_CLUSTERING, | |
2120 | .sg_tablesize = ISCSI_MAX_BDS_PER_CMD, | |
2121 | .shost_attrs = bnx2i_dev_attributes, | |
2122 | }; | |
2123 | ||
2124 | struct iscsi_transport bnx2i_iscsi_transport = { | |
2125 | .owner = THIS_MODULE, | |
2126 | .name = "bnx2i", | |
2127 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | | |
2128 | CAP_MULTI_R2T | CAP_DATADGST | | |
2129 | CAP_DATA_PATH_OFFLOAD, | |
2130 | .param_mask = ISCSI_MAX_RECV_DLENGTH | | |
2131 | ISCSI_MAX_XMIT_DLENGTH | | |
2132 | ISCSI_HDRDGST_EN | | |
2133 | ISCSI_DATADGST_EN | | |
2134 | ISCSI_INITIAL_R2T_EN | | |
2135 | ISCSI_MAX_R2T | | |
2136 | ISCSI_IMM_DATA_EN | | |
2137 | ISCSI_FIRST_BURST | | |
2138 | ISCSI_MAX_BURST | | |
2139 | ISCSI_PDU_INORDER_EN | | |
2140 | ISCSI_DATASEQ_INORDER_EN | | |
2141 | ISCSI_ERL | | |
2142 | ISCSI_CONN_PORT | | |
2143 | ISCSI_CONN_ADDRESS | | |
2144 | ISCSI_EXP_STATSN | | |
2145 | ISCSI_PERSISTENT_PORT | | |
2146 | ISCSI_PERSISTENT_ADDRESS | | |
2147 | ISCSI_TARGET_NAME | ISCSI_TPGT | | |
2148 | ISCSI_USERNAME | ISCSI_PASSWORD | | |
2149 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | | |
2150 | ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | | |
3fe5ae8b | 2151 | ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO | |
cf4e6363 MC |
2152 | ISCSI_PING_TMO | ISCSI_RECV_TMO | |
2153 | ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME, | |
625986c2 MC |
2154 | .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | |
2155 | ISCSI_HOST_NETDEV_NAME, | |
cf4e6363 MC |
2156 | .create_session = bnx2i_session_create, |
2157 | .destroy_session = bnx2i_session_destroy, | |
2158 | .create_conn = bnx2i_conn_create, | |
2159 | .bind_conn = bnx2i_conn_bind, | |
2160 | .destroy_conn = bnx2i_conn_destroy, | |
2161 | .set_param = iscsi_set_param, | |
2162 | .get_conn_param = bnx2i_conn_get_param, | |
2163 | .get_session_param = iscsi_session_get_param, | |
2164 | .get_host_param = bnx2i_host_get_param, | |
2165 | .start_conn = bnx2i_conn_start, | |
2166 | .stop_conn = iscsi_conn_stop, | |
2167 | .send_pdu = iscsi_conn_send_pdu, | |
2168 | .xmit_task = bnx2i_task_xmit, | |
2169 | .get_stats = bnx2i_conn_get_stats, | |
2170 | /* TCP connect - disconnect - option-2 interface calls */ | |
2171 | .ep_connect = bnx2i_ep_connect, | |
2172 | .ep_poll = bnx2i_ep_poll, | |
2173 | .ep_disconnect = bnx2i_ep_disconnect, | |
2174 | .set_path = bnx2i_nl_set_path, | |
2175 | /* Error recovery timeout call */ | |
2176 | .session_recovery_timedout = iscsi_session_recovery_timedout, | |
2177 | .cleanup_task = bnx2i_cleanup_task, | |
2178 | }; |