diff options
author | Jayamohan Kallickal <jayamohank@serverengines.com> | 2009-09-04 22:06:35 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2009-10-02 10:50:33 -0400 |
commit | 6733b39a1301b0b020bbcbf3295852e93e624cb1 (patch) | |
tree | 91f26838b430933f05fff0101dbd81e2b1c6d4e9 /drivers/scsi/be2iscsi/be_iscsi.c | |
parent | d74cf7c3e9c4a6a659e0442aafb550b162d15e72 (diff) |
[SCSI] be2iscsi: add 10Gbps iSCSI - BladeEngine 2 driver
[v2: fixed up virt_to_bus() issue spotted by sfr]
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: Jayamohan Kallickal <jayamohank@serverengines.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/be2iscsi/be_iscsi.c')
-rw-r--r-- | drivers/scsi/be2iscsi/be_iscsi.c | 646 |
1 files changed, 646 insertions, 0 deletions
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c new file mode 100644 index 000000000000..b23526cb39d7 --- /dev/null +++ b/drivers/scsi/be2iscsi/be_iscsi.c | |||
@@ -0,0 +1,646 @@ | |||
1 | /** | ||
2 | * Copyright (C) 2005 - 2009 ServerEngines | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License version 2 | ||
7 | * as published by the Free Software Foundation. The full GNU General | ||
8 | * Public License is included in this distribution in the file called COPYING. | ||
9 | * | ||
10 | * Written by: Jayamohan Kallickal (jayamohank@serverengines.com) | ||
11 | * | ||
12 | * Contact Information: | ||
13 | * linux-drivers@serverengines.com | ||
14 | * | ||
15 | * ServerEngines | ||
16 | * 209 N. Fair Oaks Ave | ||
17 | * Sunnyvale, CA 94085 | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <scsi/libiscsi.h> | ||
22 | #include <scsi/scsi_transport_iscsi.h> | ||
23 | #include <scsi/scsi_transport.h> | ||
24 | #include <scsi/scsi_cmnd.h> | ||
25 | #include <scsi/scsi_device.h> | ||
26 | #include <scsi/scsi_host.h> | ||
27 | #include <scsi/scsi.h> | ||
28 | |||
29 | #include "be_iscsi.h" | ||
30 | |||
31 | extern struct iscsi_transport beiscsi_iscsi_transport; | ||
32 | |||
33 | /** | ||
34 | * beiscsi_session_create - creates a new iscsi session | ||
35 | * @cmds_max: max commands supported | ||
36 | * @qdepth: max queue depth supported | ||
37 | * @initial_cmdsn: initial iscsi CMDSN | ||
38 | */ | ||
39 | struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep, | ||
40 | u16 cmds_max, | ||
41 | u16 qdepth, | ||
42 | u32 initial_cmdsn) | ||
43 | { | ||
44 | struct Scsi_Host *shost; | ||
45 | struct beiscsi_endpoint *beiscsi_ep; | ||
46 | struct iscsi_cls_session *cls_session; | ||
47 | struct iscsi_session *sess; | ||
48 | struct beiscsi_hba *phba; | ||
49 | struct iscsi_task *task; | ||
50 | struct beiscsi_io_task *io_task; | ||
51 | unsigned int max_size, num_cmd; | ||
52 | dma_addr_t bus_add; | ||
53 | u64 pa_addr; | ||
54 | void *vaddr; | ||
55 | |||
56 | SE_DEBUG(DBG_LVL_8, "In beiscsi_session_create\n"); | ||
57 | |||
58 | if (!ep) { | ||
59 | SE_DEBUG(DBG_LVL_1, "beiscsi_session_create: invalid ep \n"); | ||
60 | return NULL; | ||
61 | } | ||
62 | beiscsi_ep = ep->dd_data; | ||
63 | phba = beiscsi_ep->phba; | ||
64 | shost = phba->shost; | ||
65 | if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) { | ||
66 | shost_printk(KERN_ERR, shost, "Cannot handle %d cmds." | ||
67 | "Max cmds per session supported is %d. Using %d. " | ||
68 | "\n", cmds_max, | ||
69 | beiscsi_ep->phba->params.wrbs_per_cxn, | ||
70 | beiscsi_ep->phba->params.wrbs_per_cxn); | ||
71 | cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn; | ||
72 | } | ||
73 | |||
74 | cls_session = iscsi_session_setup(&beiscsi_iscsi_transport, | ||
75 | shost, cmds_max, | ||
76 | sizeof(struct beiscsi_io_task), | ||
77 | initial_cmdsn, ISCSI_MAX_TARGET); | ||
78 | if (!cls_session) | ||
79 | return NULL; | ||
80 | sess = cls_session->dd_data; | ||
81 | max_size = ALIGN(sizeof(struct be_cmd_bhs), 64) * sess->cmds_max; | ||
82 | vaddr = pci_alloc_consistent(phba->pcidev, max_size, &bus_add); | ||
83 | pa_addr = (__u64) bus_add; | ||
84 | |||
85 | for (num_cmd = 0; num_cmd < sess->cmds_max; num_cmd++) { | ||
86 | task = sess->cmds[num_cmd]; | ||
87 | io_task = task->dd_data; | ||
88 | io_task->cmd_bhs = vaddr; | ||
89 | io_task->bhs_pa.u.a64.address = pa_addr; | ||
90 | io_task->alloc_size = max_size; | ||
91 | vaddr += ALIGN(sizeof(struct be_cmd_bhs), 64); | ||
92 | pa_addr += ALIGN(sizeof(struct be_cmd_bhs), 64); | ||
93 | } | ||
94 | return cls_session; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * beiscsi_session_destroy - destroys iscsi session | ||
99 | * @cls_session: pointer to iscsi cls session | ||
100 | * | ||
101 | * Destroys iSCSI session instance and releases | ||
102 | * resources allocated for it. | ||
103 | */ | ||
104 | void beiscsi_session_destroy(struct iscsi_cls_session *cls_session) | ||
105 | { | ||
106 | struct iscsi_task *task; | ||
107 | struct beiscsi_io_task *io_task; | ||
108 | struct iscsi_session *sess = cls_session->dd_data; | ||
109 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | ||
110 | struct beiscsi_hba *phba = iscsi_host_priv(shost); | ||
111 | |||
112 | task = sess->cmds[0]; | ||
113 | io_task = task->dd_data; | ||
114 | pci_free_consistent(phba->pcidev, | ||
115 | io_task->alloc_size, | ||
116 | io_task->cmd_bhs, | ||
117 | io_task->bhs_pa.u.a64.address); | ||
118 | iscsi_session_teardown(cls_session); | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * beiscsi_conn_create - create an instance of iscsi connection | ||
123 | * @cls_session: ptr to iscsi_cls_session | ||
124 | * @cid: iscsi cid | ||
125 | */ | ||
126 | struct iscsi_cls_conn * | ||
127 | beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid) | ||
128 | { | ||
129 | struct beiscsi_hba *phba; | ||
130 | struct Scsi_Host *shost; | ||
131 | struct iscsi_cls_conn *cls_conn; | ||
132 | struct beiscsi_conn *beiscsi_conn; | ||
133 | struct iscsi_conn *conn; | ||
134 | |||
135 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_create ,cid" | ||
136 | "from iscsi layer=%d\n", cid); | ||
137 | shost = iscsi_session_to_shost(cls_session); | ||
138 | phba = iscsi_host_priv(shost); | ||
139 | |||
140 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid); | ||
141 | if (!cls_conn) | ||
142 | return NULL; | ||
143 | |||
144 | conn = cls_conn->dd_data; | ||
145 | beiscsi_conn = conn->dd_data; | ||
146 | beiscsi_conn->ep = NULL; | ||
147 | beiscsi_conn->phba = phba; | ||
148 | beiscsi_conn->conn = conn; | ||
149 | return cls_conn; | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table | ||
154 | * @beiscsi_conn: The pointer to beiscsi_conn structure | ||
155 | * @phba: The phba instance | ||
156 | * @cid: The cid to free | ||
157 | */ | ||
158 | static int beiscsi_bindconn_cid(struct beiscsi_hba *phba, | ||
159 | struct beiscsi_conn *beiscsi_conn, | ||
160 | unsigned int cid) | ||
161 | { | ||
162 | if (phba->conn_table[cid]) { | ||
163 | SE_DEBUG(DBG_LVL_1, | ||
164 | "Connection table already occupied. Detected clash\n"); | ||
165 | return -EINVAL; | ||
166 | } else { | ||
167 | SE_DEBUG(DBG_LVL_8, "phba->conn_table[%d]=%p(beiscsi_conn) \n", | ||
168 | cid, beiscsi_conn); | ||
169 | phba->conn_table[cid] = beiscsi_conn; | ||
170 | } | ||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection | ||
176 | * @cls_session: pointer to iscsi cls session | ||
177 | * @cls_conn: pointer to iscsi cls conn | ||
178 | * @transport_fd: EP handle(64 bit) | ||
179 | * | ||
180 | * This function binds the TCP Conn with iSCSI Connection and Session. | ||
181 | */ | ||
182 | int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, | ||
183 | struct iscsi_cls_conn *cls_conn, | ||
184 | u64 transport_fd, int is_leading) | ||
185 | { | ||
186 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
187 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | ||
188 | struct Scsi_Host *shost = | ||
189 | (struct Scsi_Host *)iscsi_session_to_shost(cls_session); | ||
190 | struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); | ||
191 | struct beiscsi_endpoint *beiscsi_ep; | ||
192 | struct iscsi_endpoint *ep; | ||
193 | |||
194 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_bind\n"); | ||
195 | ep = iscsi_lookup_endpoint(transport_fd); | ||
196 | if (!ep) | ||
197 | return -EINVAL; | ||
198 | |||
199 | beiscsi_ep = ep->dd_data; | ||
200 | |||
201 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) | ||
202 | return -EINVAL; | ||
203 | |||
204 | if (beiscsi_ep->phba != phba) { | ||
205 | SE_DEBUG(DBG_LVL_8, | ||
206 | "beiscsi_ep->hba=%p not equal to phba=%p \n", | ||
207 | beiscsi_ep->phba, phba); | ||
208 | return -EEXIST; | ||
209 | } | ||
210 | |||
211 | beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid; | ||
212 | beiscsi_conn->ep = beiscsi_ep; | ||
213 | beiscsi_ep->conn = beiscsi_conn; | ||
214 | SE_DEBUG(DBG_LVL_8, "beiscsi_conn=%p conn=%p ep_cid=%d \n", | ||
215 | beiscsi_conn, conn, beiscsi_ep->ep_cid); | ||
216 | return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * beiscsi_conn_get_param - get the iscsi parameter | ||
221 | * @cls_conn: pointer to iscsi cls conn | ||
222 | * @param: parameter type identifier | ||
223 | * @buf: buffer pointer | ||
224 | * | ||
225 | * returns iscsi parameter | ||
226 | */ | ||
227 | int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, | ||
228 | enum iscsi_param param, char *buf) | ||
229 | { | ||
230 | struct beiscsi_endpoint *beiscsi_ep; | ||
231 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
232 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | ||
233 | int len = 0; | ||
234 | |||
235 | beiscsi_ep = beiscsi_conn->ep; | ||
236 | if (!beiscsi_ep) { | ||
237 | SE_DEBUG(DBG_LVL_1, | ||
238 | "In beiscsi_conn_get_param , no beiscsi_ep\n"); | ||
239 | return -1; | ||
240 | } | ||
241 | |||
242 | switch (param) { | ||
243 | case ISCSI_PARAM_CONN_PORT: | ||
244 | len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport); | ||
245 | break; | ||
246 | case ISCSI_PARAM_CONN_ADDRESS: | ||
247 | if (beiscsi_ep->ip_type == BE2_IPV4) | ||
248 | len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr); | ||
249 | else | ||
250 | len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr); | ||
251 | break; | ||
252 | default: | ||
253 | return iscsi_conn_get_param(cls_conn, param, buf); | ||
254 | } | ||
255 | return len; | ||
256 | } | ||
257 | |||
258 | int beiscsi_set_param(struct iscsi_cls_conn *cls_conn, | ||
259 | enum iscsi_param param, char *buf, int buflen) | ||
260 | { | ||
261 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
262 | struct iscsi_session *session = conn->session; | ||
263 | int ret; | ||
264 | |||
265 | ret = iscsi_set_param(cls_conn, param, buf, buflen); | ||
266 | if (ret) | ||
267 | return ret; | ||
268 | /* | ||
269 | * If userspace tried to set the value to higher than we can | ||
270 | * support override here. | ||
271 | */ | ||
272 | switch (param) { | ||
273 | case ISCSI_PARAM_FIRST_BURST: | ||
274 | if (session->first_burst > 8192) | ||
275 | session->first_burst = 8192; | ||
276 | break; | ||
277 | case ISCSI_PARAM_MAX_RECV_DLENGTH: | ||
278 | if (conn->max_recv_dlength > 65536) | ||
279 | conn->max_recv_dlength = 65536; | ||
280 | break; | ||
281 | case ISCSI_PARAM_MAX_BURST: | ||
282 | if (session->first_burst > 262144) | ||
283 | session->first_burst = 262144; | ||
284 | break; | ||
285 | default: | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * beiscsi_get_host_param - get the iscsi parameter | ||
294 | * @shost: pointer to scsi_host structure | ||
295 | * @param: parameter type identifier | ||
296 | * @buf: buffer pointer | ||
297 | * | ||
298 | * returns host parameter | ||
299 | */ | ||
300 | int beiscsi_get_host_param(struct Scsi_Host *shost, | ||
301 | enum iscsi_host_param param, char *buf) | ||
302 | { | ||
303 | struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); | ||
304 | int len = 0; | ||
305 | |||
306 | switch (param) { | ||
307 | case ISCSI_HOST_PARAM_HWADDRESS: | ||
308 | be_cmd_get_mac_addr(&phba->ctrl, phba->mac_address); | ||
309 | len = sysfs_format_mac(buf, phba->mac_address, ETH_ALEN); | ||
310 | break; | ||
311 | default: | ||
312 | return iscsi_host_get_param(shost, param, buf); | ||
313 | } | ||
314 | return len; | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * beiscsi_conn_get_stats - get the iscsi stats | ||
319 | * @cls_conn: pointer to iscsi cls conn | ||
320 | * @stats: pointer to iscsi_stats structure | ||
321 | * | ||
322 | * returns iscsi stats | ||
323 | */ | ||
324 | void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, | ||
325 | struct iscsi_stats *stats) | ||
326 | { | ||
327 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
328 | |||
329 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_stats\n"); | ||
330 | stats->txdata_octets = conn->txdata_octets; | ||
331 | stats->rxdata_octets = conn->rxdata_octets; | ||
332 | stats->dataout_pdus = conn->dataout_pdus_cnt; | ||
333 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; | ||
334 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; | ||
335 | stats->datain_pdus = conn->datain_pdus_cnt; | ||
336 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; | ||
337 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; | ||
338 | stats->r2t_pdus = conn->r2t_pdus_cnt; | ||
339 | stats->digest_err = 0; | ||
340 | stats->timeout_err = 0; | ||
341 | stats->custom_length = 0; | ||
342 | strcpy(stats->custom[0].desc, "eh_abort_cnt"); | ||
343 | stats->custom[0].value = conn->eh_abort_cnt; | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * beiscsi_set_params_for_offld - get the parameters for offload | ||
348 | * @beiscsi_conn: pointer to beiscsi_conn | ||
349 | * @params: pointer to offload_params structure | ||
350 | */ | ||
351 | static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn, | ||
352 | struct beiscsi_offload_params *params) | ||
353 | { | ||
354 | struct iscsi_conn *conn = beiscsi_conn->conn; | ||
355 | struct iscsi_session *session = conn->session; | ||
356 | |||
357 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length, | ||
358 | params, session->max_burst); | ||
359 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, | ||
360 | max_send_data_segment_length, params, | ||
361 | conn->max_xmit_dlength); | ||
362 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length, | ||
363 | params, session->first_burst); | ||
364 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params, | ||
365 | session->erl); | ||
366 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params, | ||
367 | conn->datadgst_en); | ||
368 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params, | ||
369 | conn->hdrdgst_en); | ||
370 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params, | ||
371 | session->initial_r2t_en); | ||
372 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params, | ||
373 | session->imm_data_en); | ||
374 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params, | ||
375 | (conn->exp_statsn - 1)); | ||
376 | } | ||
377 | |||
378 | /** | ||
379 | * beiscsi_conn_start - offload of session to chip | ||
380 | * @cls_conn: pointer to beiscsi_conn | ||
381 | */ | ||
382 | int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn) | ||
383 | { | ||
384 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
385 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | ||
386 | struct beiscsi_endpoint *beiscsi_ep; | ||
387 | struct beiscsi_offload_params params; | ||
388 | struct iscsi_session *session = conn->session; | ||
389 | struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); | ||
390 | struct beiscsi_hba *phba = iscsi_host_priv(shost); | ||
391 | |||
392 | memset(¶ms, 0, sizeof(struct beiscsi_offload_params)); | ||
393 | beiscsi_ep = beiscsi_conn->ep; | ||
394 | if (!beiscsi_ep) | ||
395 | SE_DEBUG(DBG_LVL_1, "In beiscsi_conn_start , no beiscsi_ep\n"); | ||
396 | |||
397 | free_mgmt_sgl_handle(phba, beiscsi_conn->plogin_sgl_handle); | ||
398 | beiscsi_conn->login_in_progress = 0; | ||
399 | beiscsi_set_params_for_offld(beiscsi_conn, ¶ms); | ||
400 | beiscsi_offload_connection(beiscsi_conn, ¶ms); | ||
401 | iscsi_conn_start(cls_conn); | ||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | /** | ||
406 | * beiscsi_get_cid - Allocate a cid | ||
407 | * @phba: The phba instance | ||
408 | */ | ||
409 | static int beiscsi_get_cid(struct beiscsi_hba *phba) | ||
410 | { | ||
411 | unsigned short cid = 0xFFFF; | ||
412 | |||
413 | if (!phba->avlbl_cids) | ||
414 | return cid; | ||
415 | |||
416 | cid = phba->cid_array[phba->cid_alloc++]; | ||
417 | if (phba->cid_alloc == phba->params.cxns_per_ctrl) | ||
418 | phba->cid_alloc = 0; | ||
419 | phba->avlbl_cids--; | ||
420 | return cid; | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * beiscsi_open_conn - Ask FW to open a TCP connection | ||
425 | * @ep: endpoint to be used | ||
426 | * @src_addr: The source IP address | ||
427 | * @dst_addr: The Destination IP address | ||
428 | * | ||
429 | * Asks the FW to open a TCP connection | ||
430 | */ | ||
431 | static int beiscsi_open_conn(struct iscsi_endpoint *ep, | ||
432 | struct sockaddr *src_addr, | ||
433 | struct sockaddr *dst_addr, int non_blocking) | ||
434 | { | ||
435 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | ||
436 | struct beiscsi_hba *phba = beiscsi_ep->phba; | ||
437 | int ret = -1; | ||
438 | |||
439 | beiscsi_ep->ep_cid = beiscsi_get_cid(phba); | ||
440 | if (beiscsi_ep->ep_cid == 0xFFFF) { | ||
441 | SE_DEBUG(DBG_LVL_1, "No free cid available\n"); | ||
442 | return ret; | ||
443 | } | ||
444 | SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d ", | ||
445 | beiscsi_ep->ep_cid); | ||
446 | phba->ep_array[beiscsi_ep->ep_cid] = ep; | ||
447 | if (beiscsi_ep->ep_cid > | ||
448 | (phba->fw_config.iscsi_cid_start + phba->params.cxns_per_ctrl)) { | ||
449 | SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n"); | ||
450 | return ret; | ||
451 | } | ||
452 | |||
453 | beiscsi_ep->cid_vld = 0; | ||
454 | return mgmt_open_connection(phba, dst_addr, beiscsi_ep); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * beiscsi_put_cid - Free the cid | ||
459 | * @phba: The phba for which the cid is being freed | ||
460 | * @cid: The cid to free | ||
461 | */ | ||
462 | static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid) | ||
463 | { | ||
464 | phba->avlbl_cids++; | ||
465 | phba->cid_array[phba->cid_free++] = cid; | ||
466 | if (phba->cid_free == phba->params.cxns_per_ctrl) | ||
467 | phba->cid_free = 0; | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * beiscsi_free_ep - free endpoint | ||
472 | * @ep: pointer to iscsi endpoint structure | ||
473 | */ | ||
474 | static void beiscsi_free_ep(struct iscsi_endpoint *ep) | ||
475 | { | ||
476 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | ||
477 | struct beiscsi_hba *phba = beiscsi_ep->phba; | ||
478 | |||
479 | beiscsi_put_cid(phba, beiscsi_ep->ep_cid); | ||
480 | beiscsi_ep->phba = NULL; | ||
481 | iscsi_destroy_endpoint(ep); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * beiscsi_ep_connect - Ask chip to create TCP Conn | ||
486 | * @scsi_host: Pointer to scsi_host structure | ||
487 | * @dst_addr: The IP address of Target | ||
488 | * @non_blocking: blocking or non-blocking call | ||
489 | * | ||
490 | * This routines first asks chip to create a connection and then allocates an EP | ||
491 | */ | ||
492 | struct iscsi_endpoint * | ||
493 | beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, | ||
494 | int non_blocking) | ||
495 | { | ||
496 | struct beiscsi_hba *phba; | ||
497 | struct beiscsi_endpoint *beiscsi_ep; | ||
498 | struct iscsi_endpoint *ep; | ||
499 | int ret; | ||
500 | |||
501 | SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect \n"); | ||
502 | if (shost) | ||
503 | phba = iscsi_host_priv(shost); | ||
504 | else { | ||
505 | ret = -ENXIO; | ||
506 | SE_DEBUG(DBG_LVL_1, "shost is NULL \n"); | ||
507 | return ERR_PTR(ret); | ||
508 | } | ||
509 | ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint)); | ||
510 | if (!ep) { | ||
511 | ret = -ENOMEM; | ||
512 | return ERR_PTR(ret); | ||
513 | } | ||
514 | |||
515 | beiscsi_ep = ep->dd_data; | ||
516 | beiscsi_ep->phba = phba; | ||
517 | |||
518 | if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) { | ||
519 | SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n"); | ||
520 | ret = -ENOMEM; | ||
521 | goto free_ep; | ||
522 | } | ||
523 | |||
524 | return ep; | ||
525 | |||
526 | free_ep: | ||
527 | beiscsi_free_ep(ep); | ||
528 | return ERR_PTR(ret); | ||
529 | } | ||
530 | |||
531 | /** | ||
532 | * beiscsi_ep_poll - Poll to see if connection is established | ||
533 | * @ep: endpoint to be used | ||
534 | * @timeout_ms: timeout specified in millisecs | ||
535 | * | ||
536 | * Poll to see if TCP connection established | ||
537 | */ | ||
538 | int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) | ||
539 | { | ||
540 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | ||
541 | |||
542 | SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n"); | ||
543 | if (beiscsi_ep->cid_vld == 1) | ||
544 | return 1; | ||
545 | else | ||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | /** | ||
550 | * beiscsi_close_conn - Upload the connection | ||
551 | * @ep: The iscsi endpoint | ||
552 | * @flag: The type of connection closure | ||
553 | */ | ||
554 | static int beiscsi_close_conn(struct iscsi_endpoint *ep, int flag) | ||
555 | { | ||
556 | int ret = 0; | ||
557 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | ||
558 | struct beiscsi_hba *phba = beiscsi_ep->phba; | ||
559 | |||
560 | if (MGMT_STATUS_SUCCESS != | ||
561 | mgmt_upload_connection(phba, beiscsi_ep->ep_cid, | ||
562 | CONNECTION_UPLOAD_GRACEFUL)) { | ||
563 | SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x", | ||
564 | beiscsi_ep->ep_cid); | ||
565 | ret = -1; | ||
566 | } | ||
567 | |||
568 | return ret; | ||
569 | } | ||
570 | |||
571 | /** | ||
572 | * beiscsi_ep_disconnect - Tears down the TCP connection | ||
573 | * @ep: endpoint to be used | ||
574 | * | ||
575 | * Tears down the TCP connection | ||
576 | */ | ||
577 | void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) | ||
578 | { | ||
579 | struct beiscsi_conn *beiscsi_conn; | ||
580 | struct beiscsi_endpoint *beiscsi_ep; | ||
581 | struct beiscsi_hba *phba; | ||
582 | int flag = 0; | ||
583 | |||
584 | beiscsi_ep = ep->dd_data; | ||
585 | phba = beiscsi_ep->phba; | ||
586 | SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect\n"); | ||
587 | |||
588 | if (beiscsi_ep->conn) { | ||
589 | beiscsi_conn = beiscsi_ep->conn; | ||
590 | iscsi_suspend_queue(beiscsi_conn->conn); | ||
591 | beiscsi_close_conn(ep, flag); | ||
592 | } | ||
593 | |||
594 | beiscsi_free_ep(ep); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table | ||
599 | * @phba: The phba instance | ||
600 | * @cid: The cid to free | ||
601 | */ | ||
602 | static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba, | ||
603 | unsigned int cid) | ||
604 | { | ||
605 | if (phba->conn_table[cid]) | ||
606 | phba->conn_table[cid] = NULL; | ||
607 | else { | ||
608 | SE_DEBUG(DBG_LVL_8, "Connection table Not occupied. \n"); | ||
609 | return -EINVAL; | ||
610 | } | ||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | /** | ||
615 | * beiscsi_conn_stop - Invalidate and stop the connection | ||
616 | * @cls_conn: pointer to get iscsi_conn | ||
617 | * @flag: The type of connection closure | ||
618 | */ | ||
619 | void beiscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) | ||
620 | { | ||
621 | struct iscsi_conn *conn = cls_conn->dd_data; | ||
622 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | ||
623 | struct beiscsi_endpoint *beiscsi_ep; | ||
624 | struct iscsi_session *session = conn->session; | ||
625 | struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); | ||
626 | struct beiscsi_hba *phba = iscsi_host_priv(shost); | ||
627 | unsigned int status; | ||
628 | unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH; | ||
629 | |||
630 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop\n"); | ||
631 | beiscsi_ep = beiscsi_conn->ep; | ||
632 | if (!beiscsi_ep) { | ||
633 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop , no beiscsi_ep\n"); | ||
634 | return; | ||
635 | } | ||
636 | status = mgmt_invalidate_connection(phba, beiscsi_ep, | ||
637 | beiscsi_ep->ep_cid, 1, | ||
638 | savecfg_flag); | ||
639 | if (status != MGMT_STATUS_SUCCESS) { | ||
640 | SE_DEBUG(DBG_LVL_1, | ||
641 | "mgmt_invalidate_connection Failed for cid=%d \n", | ||
642 | beiscsi_ep->ep_cid); | ||
643 | } | ||
644 | beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid); | ||
645 | iscsi_conn_stop(cls_conn, flag); | ||
646 | } | ||