1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * QLogic iSCSI HBA Driver
4 * Copyright (c) 2003-2013 QLogic Corporation
5 */
6 #include <linux/moduleparam.h>
7 #include <linux/slab.h>
8 #include <linux/blkdev.h>
9 #include <linux/iscsi_boot_sysfs.h>
10 #include <linux/inet.h>
11
12 #include <scsi/scsi_tcq.h>
13 #include <scsi/scsicam.h>
14
15 #include "ql4_def.h"
16 #include "ql4_version.h"
17 #include "ql4_glbl.h"
18 #include "ql4_dbg.h"
19 #include "ql4_inline.h"
20 #include "ql4_83xx.h"
21
22 /*
23 * Driver version
24 */
25 static char qla4xxx_version_str[40];
26
27 /*
28 * SRB allocation cache
29 */
30 static struct kmem_cache *srb_cachep;
31
32 /*
33 * Module parameter information and variables
34 */
35 static int ql4xdisablesysfsboot = 1;
36 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
37 MODULE_PARM_DESC(ql4xdisablesysfsboot,
38 " Set to disable exporting boot targets to sysfs.\n"
39 "\t\t 0 - Export boot targets\n"
40 "\t\t 1 - Do not export boot targets (Default)");
41
42 int ql4xdontresethba;
43 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
44 MODULE_PARM_DESC(ql4xdontresethba,
45 " Don't reset the HBA for driver recovery.\n"
46 "\t\t 0 - It will reset HBA (Default)\n"
47 "\t\t 1 - It will NOT reset HBA");
48
49 int ql4xextended_error_logging;
50 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
51 MODULE_PARM_DESC(ql4xextended_error_logging,
52 " Option to enable extended error logging.\n"
53 "\t\t 0 - no logging (Default)\n"
54 "\t\t 2 - debug logging");
55
56 int ql4xenablemsix = 1;
57 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql4xenablemsix,
59 " Set to enable MSI or MSI-X interrupt mechanism.\n"
60 "\t\t 0 = enable INTx interrupt mechanism.\n"
61 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
62 "\t\t 2 = enable MSI interrupt mechanism.");
63
64 #define QL4_DEF_QDEPTH 32
65 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
66 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
67 MODULE_PARM_DESC(ql4xmaxqdepth,
68 " Maximum queue depth to report for target devices.\n"
69 "\t\t Default: 32.");
70
71 static int ql4xqfulltracking = 1;
72 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
73 MODULE_PARM_DESC(ql4xqfulltracking,
74 " Enable or disable dynamic tracking and adjustment of\n"
75 "\t\t scsi device queue depth.\n"
76 "\t\t 0 - Disable.\n"
77 "\t\t 1 - Enable. (Default)");
78
79 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
80 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
81 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
82 " Target Session Recovery Timeout.\n"
83 "\t\t Default: 120 sec.");
84
85 int ql4xmdcapmask = 0;
86 module_param(ql4xmdcapmask, int, S_IRUGO);
87 MODULE_PARM_DESC(ql4xmdcapmask,
88 " Set the Minidump driver capture mask level.\n"
89 "\t\t Default is 0 (firmware default capture mask)\n"
90 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
91
92 int ql4xenablemd = 1;
93 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
94 MODULE_PARM_DESC(ql4xenablemd,
95 " Set to enable minidump.\n"
96 "\t\t 0 - disable minidump\n"
97 "\t\t 1 - enable minidump (Default)");
98
99 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
100 /*
101 * SCSI host template entry points
102 */
103 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
104
105 /*
106 * iSCSI template entry points
107 */
108 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
109 enum iscsi_param param, char *buf);
110 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
111 enum iscsi_param param, char *buf);
112 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
113 enum iscsi_host_param param, char *buf);
114 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
115 uint32_t len);
116 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
117 enum iscsi_param_type param_type,
118 int param, char *buf);
119 static enum scsi_timeout_action qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
120 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
121 struct sockaddr *dst_addr,
122 int non_blocking);
123 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
124 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
125 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
126 enum iscsi_param param, char *buf);
127 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
128 static struct iscsi_cls_conn *
129 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
130 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
131 struct iscsi_cls_conn *cls_conn,
132 uint64_t transport_fd, int is_leading);
133 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
134 static struct iscsi_cls_session *
135 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
136 uint16_t qdepth, uint32_t initial_cmdsn);
137 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
138 static void qla4xxx_task_work(struct work_struct *wdata);
139 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
140 static int qla4xxx_task_xmit(struct iscsi_task *);
141 static void qla4xxx_task_cleanup(struct iscsi_task *);
142 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
143 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
144 struct iscsi_stats *stats);
145 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
146 uint32_t iface_type, uint32_t payload_size,
147 uint32_t pid, struct sockaddr *dst_addr);
148 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
149 uint32_t *num_entries, char *buf);
150 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
151 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
152 int len);
153 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
154
155 /*
156 * SCSI host template entry points
157 */
158 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
159 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
161 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
162 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
163 static int qla4xxx_slave_alloc(struct scsi_device *device);
164 static umode_t qla4_attr_is_visible(int param_type, int param);
165 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
166
167 /*
168 * iSCSI Flash DDB sysfs entry points
169 */
170 static int
171 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
172 struct iscsi_bus_flash_conn *fnode_conn,
173 void *data, int len);
174 static int
175 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
176 int param, char *buf);
177 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
178 int len);
179 static int
180 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
181 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
182 struct iscsi_bus_flash_conn *fnode_conn);
183 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
184 struct iscsi_bus_flash_conn *fnode_conn);
185 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
186
187 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
188 QLA82XX_LEGACY_INTR_CONFIG;
189
190 static const uint32_t qla4_82xx_reg_tbl[] = {
191 QLA82XX_PEG_HALT_STATUS1,
192 QLA82XX_PEG_HALT_STATUS2,
193 QLA82XX_PEG_ALIVE_COUNTER,
194 QLA82XX_CRB_DRV_ACTIVE,
195 QLA82XX_CRB_DEV_STATE,
196 QLA82XX_CRB_DRV_STATE,
197 QLA82XX_CRB_DRV_SCRATCH,
198 QLA82XX_CRB_DEV_PART_INFO,
199 QLA82XX_CRB_DRV_IDC_VERSION,
200 QLA82XX_FW_VERSION_MAJOR,
201 QLA82XX_FW_VERSION_MINOR,
202 QLA82XX_FW_VERSION_SUB,
203 CRB_CMDPEG_STATE,
204 CRB_TEMP_STATE,
205 };
206
207 static const uint32_t qla4_83xx_reg_tbl[] = {
208 QLA83XX_PEG_HALT_STATUS1,
209 QLA83XX_PEG_HALT_STATUS2,
210 QLA83XX_PEG_ALIVE_COUNTER,
211 QLA83XX_CRB_DRV_ACTIVE,
212 QLA83XX_CRB_DEV_STATE,
213 QLA83XX_CRB_DRV_STATE,
214 QLA83XX_CRB_DRV_SCRATCH,
215 QLA83XX_CRB_DEV_PART_INFO1,
216 QLA83XX_CRB_IDC_VER_MAJOR,
217 QLA83XX_FW_VER_MAJOR,
218 QLA83XX_FW_VER_MINOR,
219 QLA83XX_FW_VER_SUB,
220 QLA83XX_CMDPEG_STATE,
221 QLA83XX_ASIC_TEMP,
222 };
223
224 static struct scsi_host_template qla4xxx_driver_template = {
225 .module = THIS_MODULE,
226 .name = DRIVER_NAME,
227 .proc_name = DRIVER_NAME,
228 .queuecommand = qla4xxx_queuecommand,
229 .cmd_size = sizeof(struct qla4xxx_cmd_priv),
230
231 .eh_abort_handler = qla4xxx_eh_abort,
232 .eh_device_reset_handler = qla4xxx_eh_device_reset,
233 .eh_target_reset_handler = qla4xxx_eh_target_reset,
234 .eh_host_reset_handler = qla4xxx_eh_host_reset,
235 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
236
237 .slave_alloc = qla4xxx_slave_alloc,
238 .change_queue_depth = scsi_change_queue_depth,
239
240 .this_id = -1,
241 .cmd_per_lun = 3,
242 .sg_tablesize = SG_ALL,
243
244 .max_sectors = 0xFFFF,
245 .shost_groups = qla4xxx_host_groups,
246 .host_reset = qla4xxx_host_reset,
247 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
248 };
249
250 static struct iscsi_transport qla4xxx_iscsi_transport = {
251 .owner = THIS_MODULE,
252 .name = DRIVER_NAME,
253 .caps = CAP_TEXT_NEGO |
254 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
255 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
256 CAP_MULTI_R2T,
257 .attr_is_visible = qla4_attr_is_visible,
258 .create_session = qla4xxx_session_create,
259 .destroy_session = qla4xxx_session_destroy,
260 .start_conn = qla4xxx_conn_start,
261 .create_conn = qla4xxx_conn_create,
262 .bind_conn = qla4xxx_conn_bind,
263 .unbind_conn = iscsi_conn_unbind,
264 .stop_conn = iscsi_conn_stop,
265 .destroy_conn = qla4xxx_conn_destroy,
266 .set_param = iscsi_set_param,
267 .get_conn_param = qla4xxx_conn_get_param,
268 .get_session_param = qla4xxx_session_get_param,
269 .get_ep_param = qla4xxx_get_ep_param,
270 .ep_connect = qla4xxx_ep_connect,
271 .ep_poll = qla4xxx_ep_poll,
272 .ep_disconnect = qla4xxx_ep_disconnect,
273 .get_stats = qla4xxx_conn_get_stats,
274 .send_pdu = iscsi_conn_send_pdu,
275 .xmit_task = qla4xxx_task_xmit,
276 .cleanup_task = qla4xxx_task_cleanup,
277 .alloc_pdu = qla4xxx_alloc_pdu,
278
279 .get_host_param = qla4xxx_host_get_param,
280 .set_iface_param = qla4xxx_iface_set_param,
281 .get_iface_param = qla4xxx_get_iface_param,
282 .bsg_request = qla4xxx_bsg_request,
283 .send_ping = qla4xxx_send_ping,
284 .get_chap = qla4xxx_get_chap_list,
285 .delete_chap = qla4xxx_delete_chap,
286 .set_chap = qla4xxx_set_chap_entry,
287 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
288 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
289 .new_flashnode = qla4xxx_sysfs_ddb_add,
290 .del_flashnode = qla4xxx_sysfs_ddb_delete,
291 .login_flashnode = qla4xxx_sysfs_ddb_login,
292 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
293 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
294 .get_host_stats = qla4xxx_get_host_stats,
295 };
296
297 static struct scsi_transport_template *qla4xxx_scsi_transport;
298
qla4xxx_isp_check_reg(struct scsi_qla_host * ha)299 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
300 {
301 u32 reg_val = 0;
302 int rval = QLA_SUCCESS;
303
304 if (is_qla8022(ha))
305 reg_val = readl(&ha->qla4_82xx_reg->host_status);
306 else if (is_qla8032(ha) || is_qla8042(ha))
307 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
308 else
309 reg_val = readw(&ha->reg->ctrl_status);
310
311 if (reg_val == QL4_ISP_REG_DISCONNECT)
312 rval = QLA_ERROR;
313
314 return rval;
315 }
316
qla4xxx_send_ping(struct Scsi_Host * shost,uint32_t iface_num,uint32_t iface_type,uint32_t payload_size,uint32_t pid,struct sockaddr * dst_addr)317 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
318 uint32_t iface_type, uint32_t payload_size,
319 uint32_t pid, struct sockaddr *dst_addr)
320 {
321 struct scsi_qla_host *ha = to_qla_host(shost);
322 struct sockaddr_in *addr;
323 struct sockaddr_in6 *addr6;
324 uint32_t options = 0;
325 uint8_t ipaddr[IPv6_ADDR_LEN];
326 int rval;
327
328 memset(ipaddr, 0, IPv6_ADDR_LEN);
329 /* IPv4 to IPv4 */
330 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
331 (dst_addr->sa_family == AF_INET)) {
332 addr = (struct sockaddr_in *)dst_addr;
333 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
334 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
335 "dest: %pI4\n", __func__,
336 &ha->ip_config.ip_address, ipaddr));
337 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
338 ipaddr);
339 if (rval)
340 rval = -EINVAL;
341 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
342 (dst_addr->sa_family == AF_INET6)) {
343 /* IPv6 to IPv6 */
344 addr6 = (struct sockaddr_in6 *)dst_addr;
345 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
346
347 options |= PING_IPV6_PROTOCOL_ENABLE;
348
349 /* Ping using LinkLocal address */
350 if ((iface_num == 0) || (iface_num == 1)) {
351 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
352 "src: %pI6 dest: %pI6\n", __func__,
353 &ha->ip_config.ipv6_link_local_addr,
354 ipaddr));
355 options |= PING_IPV6_LINKLOCAL_ADDR;
356 rval = qla4xxx_ping_iocb(ha, options, payload_size,
357 pid, ipaddr);
358 } else {
359 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
360 "not supported\n", __func__, iface_num);
361 rval = -ENOSYS;
362 goto exit_send_ping;
363 }
364
365 /*
366 * If ping using LinkLocal address fails, try ping using
367 * IPv6 address
368 */
369 if (rval != QLA_SUCCESS) {
370 options &= ~PING_IPV6_LINKLOCAL_ADDR;
371 if (iface_num == 0) {
372 options |= PING_IPV6_ADDR0;
373 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
374 "Ping src: %pI6 "
375 "dest: %pI6\n", __func__,
376 &ha->ip_config.ipv6_addr0,
377 ipaddr));
378 } else if (iface_num == 1) {
379 options |= PING_IPV6_ADDR1;
380 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
381 "Ping src: %pI6 "
382 "dest: %pI6\n", __func__,
383 &ha->ip_config.ipv6_addr1,
384 ipaddr));
385 }
386 rval = qla4xxx_ping_iocb(ha, options, payload_size,
387 pid, ipaddr);
388 if (rval)
389 rval = -EINVAL;
390 }
391 } else
392 rval = -ENOSYS;
393 exit_send_ping:
394 return rval;
395 }
396
qla4_attr_is_visible(int param_type,int param)397 static umode_t qla4_attr_is_visible(int param_type, int param)
398 {
399 switch (param_type) {
400 case ISCSI_HOST_PARAM:
401 switch (param) {
402 case ISCSI_HOST_PARAM_HWADDRESS:
403 case ISCSI_HOST_PARAM_IPADDRESS:
404 case ISCSI_HOST_PARAM_INITIATOR_NAME:
405 case ISCSI_HOST_PARAM_PORT_STATE:
406 case ISCSI_HOST_PARAM_PORT_SPEED:
407 return S_IRUGO;
408 default:
409 return 0;
410 }
411 case ISCSI_PARAM:
412 switch (param) {
413 case ISCSI_PARAM_PERSISTENT_ADDRESS:
414 case ISCSI_PARAM_PERSISTENT_PORT:
415 case ISCSI_PARAM_CONN_ADDRESS:
416 case ISCSI_PARAM_CONN_PORT:
417 case ISCSI_PARAM_TARGET_NAME:
418 case ISCSI_PARAM_TPGT:
419 case ISCSI_PARAM_TARGET_ALIAS:
420 case ISCSI_PARAM_MAX_BURST:
421 case ISCSI_PARAM_MAX_R2T:
422 case ISCSI_PARAM_FIRST_BURST:
423 case ISCSI_PARAM_MAX_RECV_DLENGTH:
424 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
425 case ISCSI_PARAM_IFACE_NAME:
426 case ISCSI_PARAM_CHAP_OUT_IDX:
427 case ISCSI_PARAM_CHAP_IN_IDX:
428 case ISCSI_PARAM_USERNAME:
429 case ISCSI_PARAM_PASSWORD:
430 case ISCSI_PARAM_USERNAME_IN:
431 case ISCSI_PARAM_PASSWORD_IN:
432 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
433 case ISCSI_PARAM_DISCOVERY_SESS:
434 case ISCSI_PARAM_PORTAL_TYPE:
435 case ISCSI_PARAM_CHAP_AUTH_EN:
436 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
437 case ISCSI_PARAM_BIDI_CHAP_EN:
438 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
439 case ISCSI_PARAM_DEF_TIME2WAIT:
440 case ISCSI_PARAM_DEF_TIME2RETAIN:
441 case ISCSI_PARAM_HDRDGST_EN:
442 case ISCSI_PARAM_DATADGST_EN:
443 case ISCSI_PARAM_INITIAL_R2T_EN:
444 case ISCSI_PARAM_IMM_DATA_EN:
445 case ISCSI_PARAM_PDU_INORDER_EN:
446 case ISCSI_PARAM_DATASEQ_INORDER_EN:
447 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
448 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
449 case ISCSI_PARAM_TCP_WSF_DISABLE:
450 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
451 case ISCSI_PARAM_TCP_TIMER_SCALE:
452 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
453 case ISCSI_PARAM_TCP_XMIT_WSF:
454 case ISCSI_PARAM_TCP_RECV_WSF:
455 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
456 case ISCSI_PARAM_IPV4_TOS:
457 case ISCSI_PARAM_IPV6_TC:
458 case ISCSI_PARAM_IPV6_FLOW_LABEL:
459 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
460 case ISCSI_PARAM_KEEPALIVE_TMO:
461 case ISCSI_PARAM_LOCAL_PORT:
462 case ISCSI_PARAM_ISID:
463 case ISCSI_PARAM_TSID:
464 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
465 case ISCSI_PARAM_ERL:
466 case ISCSI_PARAM_STATSN:
467 case ISCSI_PARAM_EXP_STATSN:
468 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
469 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
470 case ISCSI_PARAM_LOCAL_IPADDR:
471 return S_IRUGO;
472 default:
473 return 0;
474 }
475 case ISCSI_NET_PARAM:
476 switch (param) {
477 case ISCSI_NET_PARAM_IPV4_ADDR:
478 case ISCSI_NET_PARAM_IPV4_SUBNET:
479 case ISCSI_NET_PARAM_IPV4_GW:
480 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
481 case ISCSI_NET_PARAM_IFACE_ENABLE:
482 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
483 case ISCSI_NET_PARAM_IPV6_ADDR:
484 case ISCSI_NET_PARAM_IPV6_ROUTER:
485 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
486 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
487 case ISCSI_NET_PARAM_VLAN_ID:
488 case ISCSI_NET_PARAM_VLAN_PRIORITY:
489 case ISCSI_NET_PARAM_VLAN_ENABLED:
490 case ISCSI_NET_PARAM_MTU:
491 case ISCSI_NET_PARAM_PORT:
492 case ISCSI_NET_PARAM_IPADDR_STATE:
493 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
494 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
495 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
496 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
497 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
498 case ISCSI_NET_PARAM_TCP_WSF:
499 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
500 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
501 case ISCSI_NET_PARAM_CACHE_ID:
502 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
503 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
504 case ISCSI_NET_PARAM_IPV4_TOS_EN:
505 case ISCSI_NET_PARAM_IPV4_TOS:
506 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
507 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
508 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
509 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
510 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
511 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
512 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
513 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
514 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
515 case ISCSI_NET_PARAM_REDIRECT_EN:
516 case ISCSI_NET_PARAM_IPV4_TTL:
517 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
518 case ISCSI_NET_PARAM_IPV6_MLD_EN:
519 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
520 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
521 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
522 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
523 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
524 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
525 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
526 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
527 return S_IRUGO;
528 default:
529 return 0;
530 }
531 case ISCSI_IFACE_PARAM:
532 switch (param) {
533 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
534 case ISCSI_IFACE_PARAM_HDRDGST_EN:
535 case ISCSI_IFACE_PARAM_DATADGST_EN:
536 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
537 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
538 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
539 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
540 case ISCSI_IFACE_PARAM_ERL:
541 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
542 case ISCSI_IFACE_PARAM_FIRST_BURST:
543 case ISCSI_IFACE_PARAM_MAX_R2T:
544 case ISCSI_IFACE_PARAM_MAX_BURST:
545 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
546 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
547 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
548 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
549 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
550 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
551 return S_IRUGO;
552 default:
553 return 0;
554 }
555 case ISCSI_FLASHNODE_PARAM:
556 switch (param) {
557 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
558 case ISCSI_FLASHNODE_PORTAL_TYPE:
559 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
560 case ISCSI_FLASHNODE_DISCOVERY_SESS:
561 case ISCSI_FLASHNODE_ENTRY_EN:
562 case ISCSI_FLASHNODE_HDR_DGST_EN:
563 case ISCSI_FLASHNODE_DATA_DGST_EN:
564 case ISCSI_FLASHNODE_IMM_DATA_EN:
565 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
566 case ISCSI_FLASHNODE_DATASEQ_INORDER:
567 case ISCSI_FLASHNODE_PDU_INORDER:
568 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
569 case ISCSI_FLASHNODE_SNACK_REQ_EN:
570 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
571 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
572 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
573 case ISCSI_FLASHNODE_ERL:
574 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
575 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
576 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
577 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
578 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
579 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
580 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
581 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
582 case ISCSI_FLASHNODE_FIRST_BURST:
583 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
584 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
585 case ISCSI_FLASHNODE_MAX_R2T:
586 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
587 case ISCSI_FLASHNODE_ISID:
588 case ISCSI_FLASHNODE_TSID:
589 case ISCSI_FLASHNODE_PORT:
590 case ISCSI_FLASHNODE_MAX_BURST:
591 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
592 case ISCSI_FLASHNODE_IPADDR:
593 case ISCSI_FLASHNODE_ALIAS:
594 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
595 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
596 case ISCSI_FLASHNODE_LOCAL_PORT:
597 case ISCSI_FLASHNODE_IPV4_TOS:
598 case ISCSI_FLASHNODE_IPV6_TC:
599 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
600 case ISCSI_FLASHNODE_NAME:
601 case ISCSI_FLASHNODE_TPGT:
602 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
603 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
604 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
605 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
606 case ISCSI_FLASHNODE_TCP_RECV_WSF:
607 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
608 case ISCSI_FLASHNODE_USERNAME:
609 case ISCSI_FLASHNODE_PASSWORD:
610 case ISCSI_FLASHNODE_STATSN:
611 case ISCSI_FLASHNODE_EXP_STATSN:
612 case ISCSI_FLASHNODE_IS_BOOT_TGT:
613 return S_IRUGO;
614 default:
615 return 0;
616 }
617 }
618
619 return 0;
620 }
621
622 /**
623 * qla4xxx_create_chap_list - Create CHAP list from FLASH
624 * @ha: pointer to adapter structure
625 *
626 * Read flash and make a list of CHAP entries, during login when a CHAP entry
627 * is received, it will be checked in this list. If entry exist then the CHAP
628 * entry index is set in the DDB. If CHAP entry does not exist in this list
629 * then a new entry is added in FLASH in CHAP table and the index obtained is
630 * used in the DDB.
631 **/
qla4xxx_create_chap_list(struct scsi_qla_host * ha)632 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
633 {
634 int rval = 0;
635 uint8_t *chap_flash_data = NULL;
636 uint32_t offset;
637 dma_addr_t chap_dma;
638 uint32_t chap_size = 0;
639
640 if (is_qla40XX(ha))
641 chap_size = MAX_CHAP_ENTRIES_40XX *
642 sizeof(struct ql4_chap_table);
643 else /* Single region contains CHAP info for both
644 * ports which is divided into half for each port.
645 */
646 chap_size = ha->hw.flt_chap_size / 2;
647
648 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
649 &chap_dma, GFP_KERNEL);
650 if (!chap_flash_data) {
651 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
652 return;
653 }
654
655 if (is_qla40XX(ha)) {
656 offset = FLASH_CHAP_OFFSET;
657 } else {
658 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
659 if (ha->port_num == 1)
660 offset += chap_size;
661 }
662
663 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
664 if (rval != QLA_SUCCESS)
665 goto exit_chap_list;
666
667 if (ha->chap_list == NULL)
668 ha->chap_list = vmalloc(chap_size);
669 if (ha->chap_list == NULL) {
670 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
671 goto exit_chap_list;
672 }
673
674 memcpy(ha->chap_list, chap_flash_data, chap_size);
675
676 exit_chap_list:
677 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
678 }
679
qla4xxx_get_chap_by_index(struct scsi_qla_host * ha,int16_t chap_index,struct ql4_chap_table ** chap_entry)680 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
681 int16_t chap_index,
682 struct ql4_chap_table **chap_entry)
683 {
684 int rval = QLA_ERROR;
685 int max_chap_entries;
686
687 if (!ha->chap_list) {
688 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
689 goto exit_get_chap;
690 }
691
692 if (is_qla80XX(ha))
693 max_chap_entries = (ha->hw.flt_chap_size / 2) /
694 sizeof(struct ql4_chap_table);
695 else
696 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
697
698 if (chap_index > max_chap_entries) {
699 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
700 goto exit_get_chap;
701 }
702
703 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
704 if ((*chap_entry)->cookie !=
705 cpu_to_le16(CHAP_VALID_COOKIE)) {
706 *chap_entry = NULL;
707 } else {
708 rval = QLA_SUCCESS;
709 }
710
711 exit_get_chap:
712 return rval;
713 }
714
715 /**
716 * qla4xxx_find_free_chap_index - Find the first free chap index
717 * @ha: pointer to adapter structure
718 * @chap_index: CHAP index to be returned
719 *
720 * Find the first free chap index available in the chap table
721 *
722 * Note: Caller should acquire the chap lock before getting here.
723 **/
qla4xxx_find_free_chap_index(struct scsi_qla_host * ha,uint16_t * chap_index)724 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
725 uint16_t *chap_index)
726 {
727 int i, rval;
728 int free_index = -1;
729 int max_chap_entries = 0;
730 struct ql4_chap_table *chap_table;
731
732 if (is_qla80XX(ha))
733 max_chap_entries = (ha->hw.flt_chap_size / 2) /
734 sizeof(struct ql4_chap_table);
735 else
736 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
737
738 if (!ha->chap_list) {
739 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
740 rval = QLA_ERROR;
741 goto exit_find_chap;
742 }
743
744 for (i = 0; i < max_chap_entries; i++) {
745 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
746
747 if ((chap_table->cookie !=
748 cpu_to_le16(CHAP_VALID_COOKIE)) &&
749 (i > MAX_RESRV_CHAP_IDX)) {
750 free_index = i;
751 break;
752 }
753 }
754
755 if (free_index != -1) {
756 *chap_index = free_index;
757 rval = QLA_SUCCESS;
758 } else {
759 rval = QLA_ERROR;
760 }
761
762 exit_find_chap:
763 return rval;
764 }
765
qla4xxx_get_chap_list(struct Scsi_Host * shost,uint16_t chap_tbl_idx,uint32_t * num_entries,char * buf)766 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
767 uint32_t *num_entries, char *buf)
768 {
769 struct scsi_qla_host *ha = to_qla_host(shost);
770 struct ql4_chap_table *chap_table;
771 struct iscsi_chap_rec *chap_rec;
772 int max_chap_entries = 0;
773 int valid_chap_entries = 0;
774 int ret = 0, i;
775
776 if (is_qla80XX(ha))
777 max_chap_entries = (ha->hw.flt_chap_size / 2) /
778 sizeof(struct ql4_chap_table);
779 else
780 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
781
782 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
783 __func__, *num_entries, chap_tbl_idx);
784
785 if (!buf) {
786 ret = -ENOMEM;
787 goto exit_get_chap_list;
788 }
789
790 qla4xxx_create_chap_list(ha);
791
792 chap_rec = (struct iscsi_chap_rec *) buf;
793 mutex_lock(&ha->chap_sem);
794 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
795 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
796 if (chap_table->cookie !=
797 cpu_to_le16(CHAP_VALID_COOKIE))
798 continue;
799
800 chap_rec->chap_tbl_idx = i;
801 strscpy(chap_rec->username, chap_table->name,
802 sizeof(chap_rec->username));
803 chap_rec->password_length = strscpy(chap_rec->password,
804 chap_table->secret,
805 sizeof(chap_rec->password));
806
807 if (chap_table->flags & BIT_7) /* local */
808 chap_rec->chap_type = CHAP_TYPE_OUT;
809
810 if (chap_table->flags & BIT_6) /* peer */
811 chap_rec->chap_type = CHAP_TYPE_IN;
812
813 chap_rec++;
814
815 valid_chap_entries++;
816 if (valid_chap_entries == *num_entries)
817 break;
818 }
819 mutex_unlock(&ha->chap_sem);
820
821 exit_get_chap_list:
822 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
823 __func__, valid_chap_entries);
824 *num_entries = valid_chap_entries;
825 return ret;
826 }
827
__qla4xxx_is_chap_active(struct device * dev,void * data)828 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
829 {
830 int ret = 0;
831 uint16_t *chap_tbl_idx = (uint16_t *) data;
832 struct iscsi_cls_session *cls_session;
833 struct iscsi_session *sess;
834 struct ddb_entry *ddb_entry;
835
836 if (!iscsi_is_session_dev(dev))
837 goto exit_is_chap_active;
838
839 cls_session = iscsi_dev_to_session(dev);
840 sess = cls_session->dd_data;
841 ddb_entry = sess->dd_data;
842
843 if (iscsi_is_session_online(cls_session))
844 goto exit_is_chap_active;
845
846 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
847 ret = 1;
848
849 exit_is_chap_active:
850 return ret;
851 }
852
qla4xxx_is_chap_active(struct Scsi_Host * shost,uint16_t chap_tbl_idx)853 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
854 uint16_t chap_tbl_idx)
855 {
856 int ret = 0;
857
858 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
859 __qla4xxx_is_chap_active);
860
861 return ret;
862 }
863
qla4xxx_delete_chap(struct Scsi_Host * shost,uint16_t chap_tbl_idx)864 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
865 {
866 struct scsi_qla_host *ha = to_qla_host(shost);
867 struct ql4_chap_table *chap_table;
868 dma_addr_t chap_dma;
869 int max_chap_entries = 0;
870 uint32_t offset = 0;
871 uint32_t chap_size;
872 int ret = 0;
873
874 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
875 if (chap_table == NULL)
876 return -ENOMEM;
877
878 if (is_qla80XX(ha))
879 max_chap_entries = (ha->hw.flt_chap_size / 2) /
880 sizeof(struct ql4_chap_table);
881 else
882 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
883
884 if (chap_tbl_idx > max_chap_entries) {
885 ret = -EINVAL;
886 goto exit_delete_chap;
887 }
888
889 /* Check if chap index is in use.
890 * If chap is in use don't delet chap entry */
891 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
892 if (ret) {
893 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
894 "delete from flash\n", chap_tbl_idx);
895 ret = -EBUSY;
896 goto exit_delete_chap;
897 }
898
899 chap_size = sizeof(struct ql4_chap_table);
900 if (is_qla40XX(ha))
901 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
902 else {
903 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
904 /* flt_chap_size is CHAP table size for both ports
905 * so divide it by 2 to calculate the offset for second port
906 */
907 if (ha->port_num == 1)
908 offset += (ha->hw.flt_chap_size / 2);
909 offset += (chap_tbl_idx * chap_size);
910 }
911
912 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
913 if (ret != QLA_SUCCESS) {
914 ret = -EINVAL;
915 goto exit_delete_chap;
916 }
917
918 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
919 __le16_to_cpu(chap_table->cookie)));
920
921 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
922 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
923 goto exit_delete_chap;
924 }
925
926 chap_table->cookie = cpu_to_le16(0xFFFF);
927
928 offset = FLASH_CHAP_OFFSET |
929 (chap_tbl_idx * sizeof(struct ql4_chap_table));
930 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
931 FLASH_OPT_RMW_COMMIT);
932 if (ret == QLA_SUCCESS && ha->chap_list) {
933 mutex_lock(&ha->chap_sem);
934 /* Update ha chap_list cache */
935 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
936 chap_table, sizeof(struct ql4_chap_table));
937 mutex_unlock(&ha->chap_sem);
938 }
939 if (ret != QLA_SUCCESS)
940 ret = -EINVAL;
941
942 exit_delete_chap:
943 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
944 return ret;
945 }
946
947 /**
948 * qla4xxx_set_chap_entry - Make chap entry with given information
949 * @shost: pointer to host
950 * @data: chap info - credentials, index and type to make chap entry
951 * @len: length of data
952 *
953 * Add or update chap entry with the given information
954 **/
qla4xxx_set_chap_entry(struct Scsi_Host * shost,void * data,int len)955 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
956 {
957 struct scsi_qla_host *ha = to_qla_host(shost);
958 struct iscsi_chap_rec chap_rec;
959 struct ql4_chap_table *chap_entry = NULL;
960 struct iscsi_param_info *param_info;
961 struct nlattr *attr;
962 int max_chap_entries = 0;
963 int type;
964 int rem = len;
965 int rc = 0;
966 int size;
967
968 memset(&chap_rec, 0, sizeof(chap_rec));
969
970 nla_for_each_attr(attr, data, len, rem) {
971 if (nla_len(attr) < sizeof(*param_info)) {
972 rc = -EINVAL;
973 goto exit_set_chap;
974 }
975
976 param_info = nla_data(attr);
977
978 switch (param_info->param) {
979 case ISCSI_CHAP_PARAM_INDEX:
980 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
981 break;
982 case ISCSI_CHAP_PARAM_CHAP_TYPE:
983 chap_rec.chap_type = param_info->value[0];
984 break;
985 case ISCSI_CHAP_PARAM_USERNAME:
986 size = min_t(size_t, sizeof(chap_rec.username),
987 param_info->len);
988 memcpy(chap_rec.username, param_info->value, size);
989 break;
990 case ISCSI_CHAP_PARAM_PASSWORD:
991 size = min_t(size_t, sizeof(chap_rec.password),
992 param_info->len);
993 memcpy(chap_rec.password, param_info->value, size);
994 break;
995 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
996 chap_rec.password_length = param_info->value[0];
997 break;
998 default:
999 ql4_printk(KERN_ERR, ha,
1000 "%s: No such sysfs attribute\n", __func__);
1001 rc = -ENOSYS;
1002 goto exit_set_chap;
1003 }
1004 }
1005
1006 if (chap_rec.chap_type == CHAP_TYPE_IN)
1007 type = BIDI_CHAP;
1008 else
1009 type = LOCAL_CHAP;
1010
1011 if (is_qla80XX(ha))
1012 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1013 sizeof(struct ql4_chap_table);
1014 else
1015 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1016
1017 mutex_lock(&ha->chap_sem);
1018 if (chap_rec.chap_tbl_idx < max_chap_entries) {
1019 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
1020 &chap_entry);
1021 if (!rc) {
1022 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
1023 ql4_printk(KERN_INFO, ha,
1024 "Type mismatch for CHAP entry %d\n",
1025 chap_rec.chap_tbl_idx);
1026 rc = -EINVAL;
1027 goto exit_unlock_chap;
1028 }
1029
1030 /* If chap index is in use then don't modify it */
1031 rc = qla4xxx_is_chap_active(shost,
1032 chap_rec.chap_tbl_idx);
1033 if (rc) {
1034 ql4_printk(KERN_INFO, ha,
1035 "CHAP entry %d is in use\n",
1036 chap_rec.chap_tbl_idx);
1037 rc = -EBUSY;
1038 goto exit_unlock_chap;
1039 }
1040 }
1041 } else {
1042 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1043 if (rc) {
1044 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1045 rc = -EBUSY;
1046 goto exit_unlock_chap;
1047 }
1048 }
1049
1050 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1051 chap_rec.chap_tbl_idx, type);
1052
1053 exit_unlock_chap:
1054 mutex_unlock(&ha->chap_sem);
1055
1056 exit_set_chap:
1057 return rc;
1058 }
1059
1060
qla4xxx_get_host_stats(struct Scsi_Host * shost,char * buf,int len)1061 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1062 {
1063 struct scsi_qla_host *ha = to_qla_host(shost);
1064 struct iscsi_offload_host_stats *host_stats = NULL;
1065 int host_stats_size;
1066 int ret = 0;
1067 int ddb_idx = 0;
1068 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1069 int stats_size;
1070 dma_addr_t iscsi_stats_dma;
1071
1072 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1073
1074 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1075
1076 if (host_stats_size != len) {
1077 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1078 __func__, len, host_stats_size);
1079 ret = -EINVAL;
1080 goto exit_host_stats;
1081 }
1082 host_stats = (struct iscsi_offload_host_stats *)buf;
1083
1084 if (!buf) {
1085 ret = -ENOMEM;
1086 goto exit_host_stats;
1087 }
1088
1089 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1090
1091 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1092 &iscsi_stats_dma, GFP_KERNEL);
1093 if (!ql_iscsi_stats) {
1094 ql4_printk(KERN_ERR, ha,
1095 "Unable to allocate memory for iscsi stats\n");
1096 ret = -ENOMEM;
1097 goto exit_host_stats;
1098 }
1099
1100 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1101 iscsi_stats_dma);
1102 if (ret != QLA_SUCCESS) {
1103 ql4_printk(KERN_ERR, ha,
1104 "Unable to retrieve iscsi stats\n");
1105 ret = -EIO;
1106 goto exit_host_stats;
1107 }
1108 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1109 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1110 host_stats->mactx_multicast_frames =
1111 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1112 host_stats->mactx_broadcast_frames =
1113 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1114 host_stats->mactx_pause_frames =
1115 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1116 host_stats->mactx_control_frames =
1117 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1118 host_stats->mactx_deferral =
1119 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1120 host_stats->mactx_excess_deferral =
1121 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1122 host_stats->mactx_late_collision =
1123 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1124 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1125 host_stats->mactx_single_collision =
1126 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1127 host_stats->mactx_multiple_collision =
1128 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1129 host_stats->mactx_collision =
1130 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1131 host_stats->mactx_frames_dropped =
1132 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1133 host_stats->mactx_jumbo_frames =
1134 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1135 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1136 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1137 host_stats->macrx_unknown_control_frames =
1138 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1139 host_stats->macrx_pause_frames =
1140 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1141 host_stats->macrx_control_frames =
1142 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1143 host_stats->macrx_dribble =
1144 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1145 host_stats->macrx_frame_length_error =
1146 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1147 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1148 host_stats->macrx_carrier_sense_error =
1149 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1150 host_stats->macrx_frame_discarded =
1151 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1152 host_stats->macrx_frames_dropped =
1153 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1154 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1155 host_stats->mac_encoding_error =
1156 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1157 host_stats->macrx_length_error_large =
1158 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1159 host_stats->macrx_length_error_small =
1160 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1161 host_stats->macrx_multicast_frames =
1162 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1163 host_stats->macrx_broadcast_frames =
1164 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1165 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1166 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1167 host_stats->iptx_fragments =
1168 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1169 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1170 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1171 host_stats->iprx_fragments =
1172 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1173 host_stats->ip_datagram_reassembly =
1174 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1175 host_stats->ip_invalid_address_error =
1176 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1177 host_stats->ip_error_packets =
1178 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1179 host_stats->ip_fragrx_overlap =
1180 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1181 host_stats->ip_fragrx_outoforder =
1182 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1183 host_stats->ip_datagram_reassembly_timeout =
1184 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1185 host_stats->ipv6tx_packets =
1186 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1187 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1188 host_stats->ipv6tx_fragments =
1189 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1190 host_stats->ipv6rx_packets =
1191 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1192 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1193 host_stats->ipv6rx_fragments =
1194 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1195 host_stats->ipv6_datagram_reassembly =
1196 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1197 host_stats->ipv6_invalid_address_error =
1198 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1199 host_stats->ipv6_error_packets =
1200 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1201 host_stats->ipv6_fragrx_overlap =
1202 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1203 host_stats->ipv6_fragrx_outoforder =
1204 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1205 host_stats->ipv6_datagram_reassembly_timeout =
1206 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1207 host_stats->tcptx_segments =
1208 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1209 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1210 host_stats->tcprx_segments =
1211 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1212 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1213 host_stats->tcp_duplicate_ack_retx =
1214 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1215 host_stats->tcp_retx_timer_expired =
1216 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1217 host_stats->tcprx_duplicate_ack =
1218 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1219 host_stats->tcprx_pure_ackr =
1220 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1221 host_stats->tcptx_delayed_ack =
1222 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1223 host_stats->tcptx_pure_ack =
1224 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1225 host_stats->tcprx_segment_error =
1226 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1227 host_stats->tcprx_segment_outoforder =
1228 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1229 host_stats->tcprx_window_probe =
1230 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1231 host_stats->tcprx_window_update =
1232 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1233 host_stats->tcptx_window_probe_persist =
1234 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1235 host_stats->ecc_error_correction =
1236 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1237 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1238 host_stats->iscsi_data_bytes_tx =
1239 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1240 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1241 host_stats->iscsi_data_bytes_rx =
1242 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1243 host_stats->iscsi_io_completed =
1244 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1245 host_stats->iscsi_unexpected_io_rx =
1246 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1247 host_stats->iscsi_format_error =
1248 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1249 host_stats->iscsi_hdr_digest_error =
1250 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1251 host_stats->iscsi_data_digest_error =
1252 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1253 host_stats->iscsi_sequence_error =
1254 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1255 exit_host_stats:
1256 if (ql_iscsi_stats)
1257 dma_free_coherent(&ha->pdev->dev, stats_size,
1258 ql_iscsi_stats, iscsi_stats_dma);
1259
1260 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1261 __func__);
1262 return ret;
1263 }
1264
qla4xxx_get_iface_param(struct iscsi_iface * iface,enum iscsi_param_type param_type,int param,char * buf)1265 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1266 enum iscsi_param_type param_type,
1267 int param, char *buf)
1268 {
1269 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1270 struct scsi_qla_host *ha = to_qla_host(shost);
1271 int ival;
1272 char *pval = NULL;
1273 int len = -ENOSYS;
1274
1275 if (param_type == ISCSI_NET_PARAM) {
1276 switch (param) {
1277 case ISCSI_NET_PARAM_IPV4_ADDR:
1278 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1279 break;
1280 case ISCSI_NET_PARAM_IPV4_SUBNET:
1281 len = sprintf(buf, "%pI4\n",
1282 &ha->ip_config.subnet_mask);
1283 break;
1284 case ISCSI_NET_PARAM_IPV4_GW:
1285 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1286 break;
1287 case ISCSI_NET_PARAM_IFACE_ENABLE:
1288 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1289 OP_STATE(ha->ip_config.ipv4_options,
1290 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1291 } else {
1292 OP_STATE(ha->ip_config.ipv6_options,
1293 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1294 }
1295
1296 len = sprintf(buf, "%s\n", pval);
1297 break;
1298 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1299 len = sprintf(buf, "%s\n",
1300 (ha->ip_config.tcp_options &
1301 TCPOPT_DHCP_ENABLE) ?
1302 "dhcp" : "static");
1303 break;
1304 case ISCSI_NET_PARAM_IPV6_ADDR:
1305 if (iface->iface_num == 0)
1306 len = sprintf(buf, "%pI6\n",
1307 &ha->ip_config.ipv6_addr0);
1308 if (iface->iface_num == 1)
1309 len = sprintf(buf, "%pI6\n",
1310 &ha->ip_config.ipv6_addr1);
1311 break;
1312 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1313 len = sprintf(buf, "%pI6\n",
1314 &ha->ip_config.ipv6_link_local_addr);
1315 break;
1316 case ISCSI_NET_PARAM_IPV6_ROUTER:
1317 len = sprintf(buf, "%pI6\n",
1318 &ha->ip_config.ipv6_default_router_addr);
1319 break;
1320 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1321 pval = (ha->ip_config.ipv6_addl_options &
1322 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1323 "nd" : "static";
1324
1325 len = sprintf(buf, "%s\n", pval);
1326 break;
1327 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1328 pval = (ha->ip_config.ipv6_addl_options &
1329 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1330 "auto" : "static";
1331
1332 len = sprintf(buf, "%s\n", pval);
1333 break;
1334 case ISCSI_NET_PARAM_VLAN_ID:
1335 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1336 ival = ha->ip_config.ipv4_vlan_tag &
1337 ISCSI_MAX_VLAN_ID;
1338 else
1339 ival = ha->ip_config.ipv6_vlan_tag &
1340 ISCSI_MAX_VLAN_ID;
1341
1342 len = sprintf(buf, "%d\n", ival);
1343 break;
1344 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1345 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1346 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1347 ISCSI_MAX_VLAN_PRIORITY;
1348 else
1349 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1350 ISCSI_MAX_VLAN_PRIORITY;
1351
1352 len = sprintf(buf, "%d\n", ival);
1353 break;
1354 case ISCSI_NET_PARAM_VLAN_ENABLED:
1355 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1356 OP_STATE(ha->ip_config.ipv4_options,
1357 IPOPT_VLAN_TAGGING_ENABLE, pval);
1358 } else {
1359 OP_STATE(ha->ip_config.ipv6_options,
1360 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1361 }
1362 len = sprintf(buf, "%s\n", pval);
1363 break;
1364 case ISCSI_NET_PARAM_MTU:
1365 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1366 break;
1367 case ISCSI_NET_PARAM_PORT:
1368 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1369 len = sprintf(buf, "%d\n",
1370 ha->ip_config.ipv4_port);
1371 else
1372 len = sprintf(buf, "%d\n",
1373 ha->ip_config.ipv6_port);
1374 break;
1375 case ISCSI_NET_PARAM_IPADDR_STATE:
1376 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1377 pval = iscsi_get_ipaddress_state_name(
1378 ha->ip_config.ipv4_addr_state);
1379 } else {
1380 if (iface->iface_num == 0)
1381 pval = iscsi_get_ipaddress_state_name(
1382 ha->ip_config.ipv6_addr0_state);
1383 else if (iface->iface_num == 1)
1384 pval = iscsi_get_ipaddress_state_name(
1385 ha->ip_config.ipv6_addr1_state);
1386 }
1387
1388 len = sprintf(buf, "%s\n", pval);
1389 break;
1390 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1391 pval = iscsi_get_ipaddress_state_name(
1392 ha->ip_config.ipv6_link_local_state);
1393 len = sprintf(buf, "%s\n", pval);
1394 break;
1395 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1396 pval = iscsi_get_router_state_name(
1397 ha->ip_config.ipv6_default_router_state);
1398 len = sprintf(buf, "%s\n", pval);
1399 break;
1400 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1401 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1402 OP_STATE(~ha->ip_config.tcp_options,
1403 TCPOPT_DELAYED_ACK_DISABLE, pval);
1404 } else {
1405 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1406 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1407 }
1408 len = sprintf(buf, "%s\n", pval);
1409 break;
1410 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1411 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1412 OP_STATE(~ha->ip_config.tcp_options,
1413 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1414 } else {
1415 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1416 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1417 }
1418 len = sprintf(buf, "%s\n", pval);
1419 break;
1420 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1421 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1422 OP_STATE(~ha->ip_config.tcp_options,
1423 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1424 } else {
1425 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1426 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1427 pval);
1428 }
1429 len = sprintf(buf, "%s\n", pval);
1430 break;
1431 case ISCSI_NET_PARAM_TCP_WSF:
1432 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1433 len = sprintf(buf, "%d\n",
1434 ha->ip_config.tcp_wsf);
1435 else
1436 len = sprintf(buf, "%d\n",
1437 ha->ip_config.ipv6_tcp_wsf);
1438 break;
1439 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1440 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1441 ival = (ha->ip_config.tcp_options &
1442 TCPOPT_TIMER_SCALE) >> 1;
1443 else
1444 ival = (ha->ip_config.ipv6_tcp_options &
1445 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1446
1447 len = sprintf(buf, "%d\n", ival);
1448 break;
1449 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1450 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1451 OP_STATE(ha->ip_config.tcp_options,
1452 TCPOPT_TIMESTAMP_ENABLE, pval);
1453 } else {
1454 OP_STATE(ha->ip_config.ipv6_tcp_options,
1455 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1456 }
1457 len = sprintf(buf, "%s\n", pval);
1458 break;
1459 case ISCSI_NET_PARAM_CACHE_ID:
1460 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1461 len = sprintf(buf, "%d\n",
1462 ha->ip_config.ipv4_cache_id);
1463 else
1464 len = sprintf(buf, "%d\n",
1465 ha->ip_config.ipv6_cache_id);
1466 break;
1467 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1468 OP_STATE(ha->ip_config.tcp_options,
1469 TCPOPT_DNS_SERVER_IP_EN, pval);
1470
1471 len = sprintf(buf, "%s\n", pval);
1472 break;
1473 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1474 OP_STATE(ha->ip_config.tcp_options,
1475 TCPOPT_SLP_DA_INFO_EN, pval);
1476
1477 len = sprintf(buf, "%s\n", pval);
1478 break;
1479 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1480 OP_STATE(ha->ip_config.ipv4_options,
1481 IPOPT_IPV4_TOS_EN, pval);
1482
1483 len = sprintf(buf, "%s\n", pval);
1484 break;
1485 case ISCSI_NET_PARAM_IPV4_TOS:
1486 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1487 break;
1488 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1489 OP_STATE(ha->ip_config.ipv4_options,
1490 IPOPT_GRAT_ARP_EN, pval);
1491
1492 len = sprintf(buf, "%s\n", pval);
1493 break;
1494 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1495 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1496 pval);
1497
1498 len = sprintf(buf, "%s\n", pval);
1499 break;
1500 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1501 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1502 (char *)ha->ip_config.ipv4_alt_cid : "";
1503
1504 len = sprintf(buf, "%s\n", pval);
1505 break;
1506 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1507 OP_STATE(ha->ip_config.ipv4_options,
1508 IPOPT_REQ_VID_EN, pval);
1509
1510 len = sprintf(buf, "%s\n", pval);
1511 break;
1512 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1513 OP_STATE(ha->ip_config.ipv4_options,
1514 IPOPT_USE_VID_EN, pval);
1515
1516 len = sprintf(buf, "%s\n", pval);
1517 break;
1518 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1519 pval = (ha->ip_config.ipv4_vid_len) ?
1520 (char *)ha->ip_config.ipv4_vid : "";
1521
1522 len = sprintf(buf, "%s\n", pval);
1523 break;
1524 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1525 OP_STATE(ha->ip_config.ipv4_options,
1526 IPOPT_LEARN_IQN_EN, pval);
1527
1528 len = sprintf(buf, "%s\n", pval);
1529 break;
1530 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1531 OP_STATE(~ha->ip_config.ipv4_options,
1532 IPOPT_FRAGMENTATION_DISABLE, pval);
1533
1534 len = sprintf(buf, "%s\n", pval);
1535 break;
1536 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1537 OP_STATE(ha->ip_config.ipv4_options,
1538 IPOPT_IN_FORWARD_EN, pval);
1539
1540 len = sprintf(buf, "%s\n", pval);
1541 break;
1542 case ISCSI_NET_PARAM_REDIRECT_EN:
1543 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1544 OP_STATE(ha->ip_config.ipv4_options,
1545 IPOPT_ARP_REDIRECT_EN, pval);
1546 } else {
1547 OP_STATE(ha->ip_config.ipv6_options,
1548 IPV6_OPT_REDIRECT_EN, pval);
1549 }
1550 len = sprintf(buf, "%s\n", pval);
1551 break;
1552 case ISCSI_NET_PARAM_IPV4_TTL:
1553 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1554 break;
1555 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1556 OP_STATE(ha->ip_config.ipv6_options,
1557 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1558
1559 len = sprintf(buf, "%s\n", pval);
1560 break;
1561 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1562 OP_STATE(ha->ip_config.ipv6_addl_options,
1563 IPV6_ADDOPT_MLD_EN, pval);
1564
1565 len = sprintf(buf, "%s\n", pval);
1566 break;
1567 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1568 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1569 break;
1570 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1571 len = sprintf(buf, "%d\n",
1572 ha->ip_config.ipv6_traffic_class);
1573 break;
1574 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1575 len = sprintf(buf, "%d\n",
1576 ha->ip_config.ipv6_hop_limit);
1577 break;
1578 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1579 len = sprintf(buf, "%d\n",
1580 ha->ip_config.ipv6_nd_reach_time);
1581 break;
1582 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1583 len = sprintf(buf, "%d\n",
1584 ha->ip_config.ipv6_nd_rexmit_timer);
1585 break;
1586 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1587 len = sprintf(buf, "%d\n",
1588 ha->ip_config.ipv6_nd_stale_timeout);
1589 break;
1590 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1591 len = sprintf(buf, "%d\n",
1592 ha->ip_config.ipv6_dup_addr_detect_count);
1593 break;
1594 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1595 len = sprintf(buf, "%d\n",
1596 ha->ip_config.ipv6_gw_advrt_mtu);
1597 break;
1598 default:
1599 len = -ENOSYS;
1600 }
1601 } else if (param_type == ISCSI_IFACE_PARAM) {
1602 switch (param) {
1603 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1604 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1605 break;
1606 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1607 OP_STATE(ha->ip_config.iscsi_options,
1608 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1609
1610 len = sprintf(buf, "%s\n", pval);
1611 break;
1612 case ISCSI_IFACE_PARAM_DATADGST_EN:
1613 OP_STATE(ha->ip_config.iscsi_options,
1614 ISCSIOPTS_DATA_DIGEST_EN, pval);
1615
1616 len = sprintf(buf, "%s\n", pval);
1617 break;
1618 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1619 OP_STATE(ha->ip_config.iscsi_options,
1620 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1621
1622 len = sprintf(buf, "%s\n", pval);
1623 break;
1624 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1625 OP_STATE(ha->ip_config.iscsi_options,
1626 ISCSIOPTS_INITIAL_R2T_EN, pval);
1627
1628 len = sprintf(buf, "%s\n", pval);
1629 break;
1630 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1631 OP_STATE(ha->ip_config.iscsi_options,
1632 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1633
1634 len = sprintf(buf, "%s\n", pval);
1635 break;
1636 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1637 OP_STATE(ha->ip_config.iscsi_options,
1638 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1639
1640 len = sprintf(buf, "%s\n", pval);
1641 break;
1642 case ISCSI_IFACE_PARAM_ERL:
1643 len = sprintf(buf, "%d\n",
1644 (ha->ip_config.iscsi_options &
1645 ISCSIOPTS_ERL));
1646 break;
1647 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1648 len = sprintf(buf, "%u\n",
1649 ha->ip_config.iscsi_max_pdu_size *
1650 BYTE_UNITS);
1651 break;
1652 case ISCSI_IFACE_PARAM_FIRST_BURST:
1653 len = sprintf(buf, "%u\n",
1654 ha->ip_config.iscsi_first_burst_len *
1655 BYTE_UNITS);
1656 break;
1657 case ISCSI_IFACE_PARAM_MAX_R2T:
1658 len = sprintf(buf, "%d\n",
1659 ha->ip_config.iscsi_max_outstnd_r2t);
1660 break;
1661 case ISCSI_IFACE_PARAM_MAX_BURST:
1662 len = sprintf(buf, "%u\n",
1663 ha->ip_config.iscsi_max_burst_len *
1664 BYTE_UNITS);
1665 break;
1666 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1667 OP_STATE(ha->ip_config.iscsi_options,
1668 ISCSIOPTS_CHAP_AUTH_EN, pval);
1669
1670 len = sprintf(buf, "%s\n", pval);
1671 break;
1672 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1673 OP_STATE(ha->ip_config.iscsi_options,
1674 ISCSIOPTS_BIDI_CHAP_EN, pval);
1675
1676 len = sprintf(buf, "%s\n", pval);
1677 break;
1678 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1679 OP_STATE(ha->ip_config.iscsi_options,
1680 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1681
1682 len = sprintf(buf, "%s\n", pval);
1683 break;
1684 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1685 OP_STATE(ha->ip_config.iscsi_options,
1686 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1687
1688 len = sprintf(buf, "%s\n", pval);
1689 break;
1690 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1691 OP_STATE(ha->ip_config.iscsi_options,
1692 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1693
1694 len = sprintf(buf, "%s\n", pval);
1695 break;
1696 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1697 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1698 break;
1699 default:
1700 len = -ENOSYS;
1701 }
1702 }
1703
1704 return len;
1705 }
1706
1707 static struct iscsi_endpoint *
qla4xxx_ep_connect(struct Scsi_Host * shost,struct sockaddr * dst_addr,int non_blocking)1708 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1709 int non_blocking)
1710 {
1711 int ret;
1712 struct iscsi_endpoint *ep;
1713 struct qla_endpoint *qla_ep;
1714 struct scsi_qla_host *ha;
1715 struct sockaddr_in *addr;
1716 struct sockaddr_in6 *addr6;
1717
1718 if (!shost) {
1719 ret = -ENXIO;
1720 pr_err("%s: shost is NULL\n", __func__);
1721 return ERR_PTR(ret);
1722 }
1723
1724 ha = iscsi_host_priv(shost);
1725 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1726 if (!ep) {
1727 ret = -ENOMEM;
1728 return ERR_PTR(ret);
1729 }
1730
1731 qla_ep = ep->dd_data;
1732 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1733 if (dst_addr->sa_family == AF_INET) {
1734 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1735 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1736 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1737 (char *)&addr->sin_addr));
1738 } else if (dst_addr->sa_family == AF_INET6) {
1739 memcpy(&qla_ep->dst_addr, dst_addr,
1740 sizeof(struct sockaddr_in6));
1741 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1742 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1743 (char *)&addr6->sin6_addr));
1744 } else {
1745 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1746 __func__);
1747 }
1748
1749 qla_ep->host = shost;
1750
1751 return ep;
1752 }
1753
qla4xxx_ep_poll(struct iscsi_endpoint * ep,int timeout_ms)1754 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1755 {
1756 struct qla_endpoint *qla_ep;
1757 struct scsi_qla_host *ha;
1758 int ret = 0;
1759
1760 qla_ep = ep->dd_data;
1761 ha = to_qla_host(qla_ep->host);
1762 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1763
1764 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1765 ret = 1;
1766
1767 return ret;
1768 }
1769
qla4xxx_ep_disconnect(struct iscsi_endpoint * ep)1770 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1771 {
1772 struct qla_endpoint *qla_ep;
1773 struct scsi_qla_host *ha;
1774
1775 qla_ep = ep->dd_data;
1776 ha = to_qla_host(qla_ep->host);
1777 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1778 ha->host_no));
1779 iscsi_destroy_endpoint(ep);
1780 }
1781
qla4xxx_get_ep_param(struct iscsi_endpoint * ep,enum iscsi_param param,char * buf)1782 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1783 enum iscsi_param param,
1784 char *buf)
1785 {
1786 struct qla_endpoint *qla_ep = ep->dd_data;
1787 struct sockaddr *dst_addr;
1788 struct scsi_qla_host *ha;
1789
1790 if (!qla_ep)
1791 return -ENOTCONN;
1792
1793 ha = to_qla_host(qla_ep->host);
1794 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1795 ha->host_no));
1796
1797 switch (param) {
1798 case ISCSI_PARAM_CONN_PORT:
1799 case ISCSI_PARAM_CONN_ADDRESS:
1800 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1801 if (!dst_addr)
1802 return -ENOTCONN;
1803
1804 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1805 &qla_ep->dst_addr, param, buf);
1806 default:
1807 return -ENOSYS;
1808 }
1809 }
1810
qla4xxx_conn_get_stats(struct iscsi_cls_conn * cls_conn,struct iscsi_stats * stats)1811 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1812 struct iscsi_stats *stats)
1813 {
1814 struct iscsi_session *sess;
1815 struct iscsi_cls_session *cls_sess;
1816 struct ddb_entry *ddb_entry;
1817 struct scsi_qla_host *ha;
1818 struct ql_iscsi_stats *ql_iscsi_stats;
1819 int stats_size;
1820 int ret;
1821 dma_addr_t iscsi_stats_dma;
1822
1823 cls_sess = iscsi_conn_to_session(cls_conn);
1824 sess = cls_sess->dd_data;
1825 ddb_entry = sess->dd_data;
1826 ha = ddb_entry->ha;
1827
1828 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1829 ha->host_no));
1830 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1831 /* Allocate memory */
1832 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1833 &iscsi_stats_dma, GFP_KERNEL);
1834 if (!ql_iscsi_stats) {
1835 ql4_printk(KERN_ERR, ha,
1836 "Unable to allocate memory for iscsi stats\n");
1837 goto exit_get_stats;
1838 }
1839
1840 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1841 iscsi_stats_dma);
1842 if (ret != QLA_SUCCESS) {
1843 ql4_printk(KERN_ERR, ha,
1844 "Unable to retrieve iscsi stats\n");
1845 goto free_stats;
1846 }
1847
1848 /* octets */
1849 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1850 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1851 /* xmit pdus */
1852 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1853 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1854 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1855 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1856 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1857 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1858 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1859 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1860 /* recv pdus */
1861 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1862 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1863 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1864 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1865 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1866 stats->logoutrsp_pdus =
1867 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1868 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1869 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1870 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1871
1872 free_stats:
1873 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1874 iscsi_stats_dma);
1875 exit_get_stats:
1876 return;
1877 }
1878
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd * sc)1879 static enum scsi_timeout_action qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1880 {
1881 struct iscsi_cls_session *session;
1882 unsigned long flags;
1883 enum scsi_timeout_action ret = SCSI_EH_NOT_HANDLED;
1884
1885 session = starget_to_session(scsi_target(sc->device));
1886
1887 spin_lock_irqsave(&session->lock, flags);
1888 if (session->state == ISCSI_SESSION_FAILED)
1889 ret = SCSI_EH_RESET_TIMER;
1890 spin_unlock_irqrestore(&session->lock, flags);
1891
1892 return ret;
1893 }
1894
qla4xxx_set_port_speed(struct Scsi_Host * shost)1895 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1896 {
1897 struct scsi_qla_host *ha = to_qla_host(shost);
1898 struct iscsi_cls_host *ihost = shost->shost_data;
1899 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1900
1901 qla4xxx_get_firmware_state(ha);
1902
1903 switch (ha->addl_fw_state & 0x0F00) {
1904 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1905 speed = ISCSI_PORT_SPEED_10MBPS;
1906 break;
1907 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1908 speed = ISCSI_PORT_SPEED_100MBPS;
1909 break;
1910 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1911 speed = ISCSI_PORT_SPEED_1GBPS;
1912 break;
1913 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1914 speed = ISCSI_PORT_SPEED_10GBPS;
1915 break;
1916 }
1917 ihost->port_speed = speed;
1918 }
1919
qla4xxx_set_port_state(struct Scsi_Host * shost)1920 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1921 {
1922 struct scsi_qla_host *ha = to_qla_host(shost);
1923 struct iscsi_cls_host *ihost = shost->shost_data;
1924 uint32_t state = ISCSI_PORT_STATE_DOWN;
1925
1926 if (test_bit(AF_LINK_UP, &ha->flags))
1927 state = ISCSI_PORT_STATE_UP;
1928
1929 ihost->port_state = state;
1930 }
1931
qla4xxx_host_get_param(struct Scsi_Host * shost,enum iscsi_host_param param,char * buf)1932 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1933 enum iscsi_host_param param, char *buf)
1934 {
1935 struct scsi_qla_host *ha = to_qla_host(shost);
1936 int len;
1937
1938 switch (param) {
1939 case ISCSI_HOST_PARAM_HWADDRESS:
1940 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1941 break;
1942 case ISCSI_HOST_PARAM_IPADDRESS:
1943 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1944 break;
1945 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1946 len = sprintf(buf, "%s\n", ha->name_string);
1947 break;
1948 case ISCSI_HOST_PARAM_PORT_STATE:
1949 qla4xxx_set_port_state(shost);
1950 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1951 break;
1952 case ISCSI_HOST_PARAM_PORT_SPEED:
1953 qla4xxx_set_port_speed(shost);
1954 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1955 break;
1956 default:
1957 return -ENOSYS;
1958 }
1959
1960 return len;
1961 }
1962
qla4xxx_create_ipv4_iface(struct scsi_qla_host * ha)1963 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1964 {
1965 if (ha->iface_ipv4)
1966 return;
1967
1968 /* IPv4 */
1969 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1970 &qla4xxx_iscsi_transport,
1971 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1972 if (!ha->iface_ipv4)
1973 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1974 "iface0.\n");
1975 }
1976
qla4xxx_create_ipv6_iface(struct scsi_qla_host * ha)1977 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1978 {
1979 if (!ha->iface_ipv6_0)
1980 /* IPv6 iface-0 */
1981 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1982 &qla4xxx_iscsi_transport,
1983 ISCSI_IFACE_TYPE_IPV6, 0,
1984 0);
1985 if (!ha->iface_ipv6_0)
1986 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1987 "iface0.\n");
1988
1989 if (!ha->iface_ipv6_1)
1990 /* IPv6 iface-1 */
1991 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1992 &qla4xxx_iscsi_transport,
1993 ISCSI_IFACE_TYPE_IPV6, 1,
1994 0);
1995 if (!ha->iface_ipv6_1)
1996 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1997 "iface1.\n");
1998 }
1999
qla4xxx_create_ifaces(struct scsi_qla_host * ha)2000 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
2001 {
2002 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
2003 qla4xxx_create_ipv4_iface(ha);
2004
2005 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
2006 qla4xxx_create_ipv6_iface(ha);
2007 }
2008
qla4xxx_destroy_ipv4_iface(struct scsi_qla_host * ha)2009 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
2010 {
2011 if (ha->iface_ipv4) {
2012 iscsi_destroy_iface(ha->iface_ipv4);
2013 ha->iface_ipv4 = NULL;
2014 }
2015 }
2016
qla4xxx_destroy_ipv6_iface(struct scsi_qla_host * ha)2017 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
2018 {
2019 if (ha->iface_ipv6_0) {
2020 iscsi_destroy_iface(ha->iface_ipv6_0);
2021 ha->iface_ipv6_0 = NULL;
2022 }
2023 if (ha->iface_ipv6_1) {
2024 iscsi_destroy_iface(ha->iface_ipv6_1);
2025 ha->iface_ipv6_1 = NULL;
2026 }
2027 }
2028
qla4xxx_destroy_ifaces(struct scsi_qla_host * ha)2029 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2030 {
2031 qla4xxx_destroy_ipv4_iface(ha);
2032 qla4xxx_destroy_ipv6_iface(ha);
2033 }
2034
qla4xxx_set_ipv6(struct scsi_qla_host * ha,struct iscsi_iface_param_info * iface_param,struct addr_ctrl_blk * init_fw_cb)2035 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2036 struct iscsi_iface_param_info *iface_param,
2037 struct addr_ctrl_blk *init_fw_cb)
2038 {
2039 /*
2040 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2041 * iface_num 1 is valid only for IPv6 Addr.
2042 */
2043 switch (iface_param->param) {
2044 case ISCSI_NET_PARAM_IPV6_ADDR:
2045 if (iface_param->iface_num & 0x1)
2046 /* IPv6 Addr 1 */
2047 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2048 sizeof(init_fw_cb->ipv6_addr1));
2049 else
2050 /* IPv6 Addr 0 */
2051 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2052 sizeof(init_fw_cb->ipv6_addr0));
2053 break;
2054 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2055 if (iface_param->iface_num & 0x1)
2056 break;
2057 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2058 sizeof(init_fw_cb->ipv6_if_id));
2059 break;
2060 case ISCSI_NET_PARAM_IPV6_ROUTER:
2061 if (iface_param->iface_num & 0x1)
2062 break;
2063 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2064 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2065 break;
2066 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2067 /* Autocfg applies to even interface */
2068 if (iface_param->iface_num & 0x1)
2069 break;
2070
2071 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2072 init_fw_cb->ipv6_addtl_opts &=
2073 cpu_to_le16(
2074 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2075 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2076 init_fw_cb->ipv6_addtl_opts |=
2077 cpu_to_le16(
2078 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2079 else
2080 ql4_printk(KERN_ERR, ha,
2081 "Invalid autocfg setting for IPv6 addr\n");
2082 break;
2083 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2084 /* Autocfg applies to even interface */
2085 if (iface_param->iface_num & 0x1)
2086 break;
2087
2088 if (iface_param->value[0] ==
2089 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2090 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2091 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2092 else if (iface_param->value[0] ==
2093 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2094 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2095 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2096 else
2097 ql4_printk(KERN_ERR, ha,
2098 "Invalid autocfg setting for IPv6 linklocal addr\n");
2099 break;
2100 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2101 /* Autocfg applies to even interface */
2102 if (iface_param->iface_num & 0x1)
2103 break;
2104
2105 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2106 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2107 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2108 break;
2109 case ISCSI_NET_PARAM_IFACE_ENABLE:
2110 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2111 init_fw_cb->ipv6_opts |=
2112 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2113 qla4xxx_create_ipv6_iface(ha);
2114 } else {
2115 init_fw_cb->ipv6_opts &=
2116 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2117 0xFFFF);
2118 qla4xxx_destroy_ipv6_iface(ha);
2119 }
2120 break;
2121 case ISCSI_NET_PARAM_VLAN_TAG:
2122 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2123 break;
2124 init_fw_cb->ipv6_vlan_tag =
2125 cpu_to_be16(*(uint16_t *)iface_param->value);
2126 break;
2127 case ISCSI_NET_PARAM_VLAN_ENABLED:
2128 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2129 init_fw_cb->ipv6_opts |=
2130 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2131 else
2132 init_fw_cb->ipv6_opts &=
2133 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2134 break;
2135 case ISCSI_NET_PARAM_MTU:
2136 init_fw_cb->eth_mtu_size =
2137 cpu_to_le16(*(uint16_t *)iface_param->value);
2138 break;
2139 case ISCSI_NET_PARAM_PORT:
2140 /* Autocfg applies to even interface */
2141 if (iface_param->iface_num & 0x1)
2142 break;
2143
2144 init_fw_cb->ipv6_port =
2145 cpu_to_le16(*(uint16_t *)iface_param->value);
2146 break;
2147 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2148 if (iface_param->iface_num & 0x1)
2149 break;
2150 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2151 init_fw_cb->ipv6_tcp_opts |=
2152 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2153 else
2154 init_fw_cb->ipv6_tcp_opts &=
2155 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2156 0xFFFF);
2157 break;
2158 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2159 if (iface_param->iface_num & 0x1)
2160 break;
2161 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2162 init_fw_cb->ipv6_tcp_opts |=
2163 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2164 else
2165 init_fw_cb->ipv6_tcp_opts &=
2166 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2167 break;
2168 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2169 if (iface_param->iface_num & 0x1)
2170 break;
2171 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2172 init_fw_cb->ipv6_tcp_opts |=
2173 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2174 else
2175 init_fw_cb->ipv6_tcp_opts &=
2176 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2177 break;
2178 case ISCSI_NET_PARAM_TCP_WSF:
2179 if (iface_param->iface_num & 0x1)
2180 break;
2181 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2182 break;
2183 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2184 if (iface_param->iface_num & 0x1)
2185 break;
2186 init_fw_cb->ipv6_tcp_opts &=
2187 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2188 init_fw_cb->ipv6_tcp_opts |=
2189 cpu_to_le16((iface_param->value[0] << 1) &
2190 IPV6_TCPOPT_TIMER_SCALE);
2191 break;
2192 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2193 if (iface_param->iface_num & 0x1)
2194 break;
2195 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2196 init_fw_cb->ipv6_tcp_opts |=
2197 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2198 else
2199 init_fw_cb->ipv6_tcp_opts &=
2200 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2201 break;
2202 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2203 if (iface_param->iface_num & 0x1)
2204 break;
2205 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2206 init_fw_cb->ipv6_opts |=
2207 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2208 else
2209 init_fw_cb->ipv6_opts &=
2210 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2211 break;
2212 case ISCSI_NET_PARAM_REDIRECT_EN:
2213 if (iface_param->iface_num & 0x1)
2214 break;
2215 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2216 init_fw_cb->ipv6_opts |=
2217 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2218 else
2219 init_fw_cb->ipv6_opts &=
2220 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2221 break;
2222 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2223 if (iface_param->iface_num & 0x1)
2224 break;
2225 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2226 init_fw_cb->ipv6_addtl_opts |=
2227 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2228 else
2229 init_fw_cb->ipv6_addtl_opts &=
2230 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2231 break;
2232 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2233 if (iface_param->iface_num & 0x1)
2234 break;
2235 init_fw_cb->ipv6_flow_lbl =
2236 cpu_to_le16(*(uint16_t *)iface_param->value);
2237 break;
2238 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2239 if (iface_param->iface_num & 0x1)
2240 break;
2241 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2242 break;
2243 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2244 if (iface_param->iface_num & 0x1)
2245 break;
2246 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2247 break;
2248 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2249 if (iface_param->iface_num & 0x1)
2250 break;
2251 init_fw_cb->ipv6_nd_reach_time =
2252 cpu_to_le32(*(uint32_t *)iface_param->value);
2253 break;
2254 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2255 if (iface_param->iface_num & 0x1)
2256 break;
2257 init_fw_cb->ipv6_nd_rexmit_timer =
2258 cpu_to_le32(*(uint32_t *)iface_param->value);
2259 break;
2260 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2261 if (iface_param->iface_num & 0x1)
2262 break;
2263 init_fw_cb->ipv6_nd_stale_timeout =
2264 cpu_to_le32(*(uint32_t *)iface_param->value);
2265 break;
2266 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2267 if (iface_param->iface_num & 0x1)
2268 break;
2269 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2270 break;
2271 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2272 if (iface_param->iface_num & 0x1)
2273 break;
2274 init_fw_cb->ipv6_gw_advrt_mtu =
2275 cpu_to_le32(*(uint32_t *)iface_param->value);
2276 break;
2277 default:
2278 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2279 iface_param->param);
2280 break;
2281 }
2282 }
2283
qla4xxx_set_ipv4(struct scsi_qla_host * ha,struct iscsi_iface_param_info * iface_param,struct addr_ctrl_blk * init_fw_cb)2284 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2285 struct iscsi_iface_param_info *iface_param,
2286 struct addr_ctrl_blk *init_fw_cb)
2287 {
2288 switch (iface_param->param) {
2289 case ISCSI_NET_PARAM_IPV4_ADDR:
2290 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2291 sizeof(init_fw_cb->ipv4_addr));
2292 break;
2293 case ISCSI_NET_PARAM_IPV4_SUBNET:
2294 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2295 sizeof(init_fw_cb->ipv4_subnet));
2296 break;
2297 case ISCSI_NET_PARAM_IPV4_GW:
2298 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2299 sizeof(init_fw_cb->ipv4_gw_addr));
2300 break;
2301 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2302 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2303 init_fw_cb->ipv4_tcp_opts |=
2304 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2305 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2306 init_fw_cb->ipv4_tcp_opts &=
2307 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2308 else
2309 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2310 break;
2311 case ISCSI_NET_PARAM_IFACE_ENABLE:
2312 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2313 init_fw_cb->ipv4_ip_opts |=
2314 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2315 qla4xxx_create_ipv4_iface(ha);
2316 } else {
2317 init_fw_cb->ipv4_ip_opts &=
2318 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2319 0xFFFF);
2320 qla4xxx_destroy_ipv4_iface(ha);
2321 }
2322 break;
2323 case ISCSI_NET_PARAM_VLAN_TAG:
2324 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2325 break;
2326 init_fw_cb->ipv4_vlan_tag =
2327 cpu_to_be16(*(uint16_t *)iface_param->value);
2328 break;
2329 case ISCSI_NET_PARAM_VLAN_ENABLED:
2330 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2331 init_fw_cb->ipv4_ip_opts |=
2332 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2333 else
2334 init_fw_cb->ipv4_ip_opts &=
2335 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2336 break;
2337 case ISCSI_NET_PARAM_MTU:
2338 init_fw_cb->eth_mtu_size =
2339 cpu_to_le16(*(uint16_t *)iface_param->value);
2340 break;
2341 case ISCSI_NET_PARAM_PORT:
2342 init_fw_cb->ipv4_port =
2343 cpu_to_le16(*(uint16_t *)iface_param->value);
2344 break;
2345 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2346 if (iface_param->iface_num & 0x1)
2347 break;
2348 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2349 init_fw_cb->ipv4_tcp_opts |=
2350 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2351 else
2352 init_fw_cb->ipv4_tcp_opts &=
2353 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2354 0xFFFF);
2355 break;
2356 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2357 if (iface_param->iface_num & 0x1)
2358 break;
2359 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2360 init_fw_cb->ipv4_tcp_opts |=
2361 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2362 else
2363 init_fw_cb->ipv4_tcp_opts &=
2364 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2365 break;
2366 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2367 if (iface_param->iface_num & 0x1)
2368 break;
2369 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2370 init_fw_cb->ipv4_tcp_opts |=
2371 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2372 else
2373 init_fw_cb->ipv4_tcp_opts &=
2374 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2375 break;
2376 case ISCSI_NET_PARAM_TCP_WSF:
2377 if (iface_param->iface_num & 0x1)
2378 break;
2379 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2380 break;
2381 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2382 if (iface_param->iface_num & 0x1)
2383 break;
2384 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2385 init_fw_cb->ipv4_tcp_opts |=
2386 cpu_to_le16((iface_param->value[0] << 1) &
2387 TCPOPT_TIMER_SCALE);
2388 break;
2389 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2390 if (iface_param->iface_num & 0x1)
2391 break;
2392 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2393 init_fw_cb->ipv4_tcp_opts |=
2394 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2395 else
2396 init_fw_cb->ipv4_tcp_opts &=
2397 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2398 break;
2399 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2400 if (iface_param->iface_num & 0x1)
2401 break;
2402 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2403 init_fw_cb->ipv4_tcp_opts |=
2404 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2405 else
2406 init_fw_cb->ipv4_tcp_opts &=
2407 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2408 break;
2409 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2410 if (iface_param->iface_num & 0x1)
2411 break;
2412 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2413 init_fw_cb->ipv4_tcp_opts |=
2414 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2415 else
2416 init_fw_cb->ipv4_tcp_opts &=
2417 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2418 break;
2419 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2420 if (iface_param->iface_num & 0x1)
2421 break;
2422 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2423 init_fw_cb->ipv4_ip_opts |=
2424 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2425 else
2426 init_fw_cb->ipv4_ip_opts &=
2427 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2428 break;
2429 case ISCSI_NET_PARAM_IPV4_TOS:
2430 if (iface_param->iface_num & 0x1)
2431 break;
2432 init_fw_cb->ipv4_tos = iface_param->value[0];
2433 break;
2434 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2435 if (iface_param->iface_num & 0x1)
2436 break;
2437 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2438 init_fw_cb->ipv4_ip_opts |=
2439 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2440 else
2441 init_fw_cb->ipv4_ip_opts &=
2442 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2443 break;
2444 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2445 if (iface_param->iface_num & 0x1)
2446 break;
2447 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2448 init_fw_cb->ipv4_ip_opts |=
2449 cpu_to_le16(IPOPT_ALT_CID_EN);
2450 else
2451 init_fw_cb->ipv4_ip_opts &=
2452 cpu_to_le16(~IPOPT_ALT_CID_EN);
2453 break;
2454 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2455 if (iface_param->iface_num & 0x1)
2456 break;
2457 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2458 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2459 init_fw_cb->ipv4_dhcp_alt_cid_len =
2460 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2461 break;
2462 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2463 if (iface_param->iface_num & 0x1)
2464 break;
2465 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2466 init_fw_cb->ipv4_ip_opts |=
2467 cpu_to_le16(IPOPT_REQ_VID_EN);
2468 else
2469 init_fw_cb->ipv4_ip_opts &=
2470 cpu_to_le16(~IPOPT_REQ_VID_EN);
2471 break;
2472 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2473 if (iface_param->iface_num & 0x1)
2474 break;
2475 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2476 init_fw_cb->ipv4_ip_opts |=
2477 cpu_to_le16(IPOPT_USE_VID_EN);
2478 else
2479 init_fw_cb->ipv4_ip_opts &=
2480 cpu_to_le16(~IPOPT_USE_VID_EN);
2481 break;
2482 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2483 if (iface_param->iface_num & 0x1)
2484 break;
2485 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2486 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2487 init_fw_cb->ipv4_dhcp_vid_len =
2488 strlen(init_fw_cb->ipv4_dhcp_vid);
2489 break;
2490 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2491 if (iface_param->iface_num & 0x1)
2492 break;
2493 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2494 init_fw_cb->ipv4_ip_opts |=
2495 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2496 else
2497 init_fw_cb->ipv4_ip_opts &=
2498 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2499 break;
2500 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2501 if (iface_param->iface_num & 0x1)
2502 break;
2503 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2504 init_fw_cb->ipv4_ip_opts |=
2505 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2506 else
2507 init_fw_cb->ipv4_ip_opts &=
2508 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2509 break;
2510 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2511 if (iface_param->iface_num & 0x1)
2512 break;
2513 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2514 init_fw_cb->ipv4_ip_opts |=
2515 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2516 else
2517 init_fw_cb->ipv4_ip_opts &=
2518 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2519 break;
2520 case ISCSI_NET_PARAM_REDIRECT_EN:
2521 if (iface_param->iface_num & 0x1)
2522 break;
2523 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2524 init_fw_cb->ipv4_ip_opts |=
2525 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2526 else
2527 init_fw_cb->ipv4_ip_opts &=
2528 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2529 break;
2530 case ISCSI_NET_PARAM_IPV4_TTL:
2531 if (iface_param->iface_num & 0x1)
2532 break;
2533 init_fw_cb->ipv4_ttl = iface_param->value[0];
2534 break;
2535 default:
2536 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2537 iface_param->param);
2538 break;
2539 }
2540 }
2541
qla4xxx_set_iscsi_param(struct scsi_qla_host * ha,struct iscsi_iface_param_info * iface_param,struct addr_ctrl_blk * init_fw_cb)2542 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2543 struct iscsi_iface_param_info *iface_param,
2544 struct addr_ctrl_blk *init_fw_cb)
2545 {
2546 switch (iface_param->param) {
2547 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2548 if (iface_param->iface_num & 0x1)
2549 break;
2550 init_fw_cb->def_timeout =
2551 cpu_to_le16(*(uint16_t *)iface_param->value);
2552 break;
2553 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2554 if (iface_param->iface_num & 0x1)
2555 break;
2556 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2557 init_fw_cb->iscsi_opts |=
2558 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2559 else
2560 init_fw_cb->iscsi_opts &=
2561 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2562 break;
2563 case ISCSI_IFACE_PARAM_DATADGST_EN:
2564 if (iface_param->iface_num & 0x1)
2565 break;
2566 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2567 init_fw_cb->iscsi_opts |=
2568 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2569 else
2570 init_fw_cb->iscsi_opts &=
2571 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2572 break;
2573 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2574 if (iface_param->iface_num & 0x1)
2575 break;
2576 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2577 init_fw_cb->iscsi_opts |=
2578 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2579 else
2580 init_fw_cb->iscsi_opts &=
2581 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2582 break;
2583 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2584 if (iface_param->iface_num & 0x1)
2585 break;
2586 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2587 init_fw_cb->iscsi_opts |=
2588 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2589 else
2590 init_fw_cb->iscsi_opts &=
2591 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2592 break;
2593 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2594 if (iface_param->iface_num & 0x1)
2595 break;
2596 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2597 init_fw_cb->iscsi_opts |=
2598 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2599 else
2600 init_fw_cb->iscsi_opts &=
2601 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2602 break;
2603 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2604 if (iface_param->iface_num & 0x1)
2605 break;
2606 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2607 init_fw_cb->iscsi_opts |=
2608 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2609 else
2610 init_fw_cb->iscsi_opts &=
2611 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2612 break;
2613 case ISCSI_IFACE_PARAM_ERL:
2614 if (iface_param->iface_num & 0x1)
2615 break;
2616 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2617 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2618 ISCSIOPTS_ERL);
2619 break;
2620 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2621 if (iface_param->iface_num & 0x1)
2622 break;
2623 init_fw_cb->iscsi_max_pdu_size =
2624 cpu_to_le32(*(uint32_t *)iface_param->value) /
2625 BYTE_UNITS;
2626 break;
2627 case ISCSI_IFACE_PARAM_FIRST_BURST:
2628 if (iface_param->iface_num & 0x1)
2629 break;
2630 init_fw_cb->iscsi_fburst_len =
2631 cpu_to_le32(*(uint32_t *)iface_param->value) /
2632 BYTE_UNITS;
2633 break;
2634 case ISCSI_IFACE_PARAM_MAX_R2T:
2635 if (iface_param->iface_num & 0x1)
2636 break;
2637 init_fw_cb->iscsi_max_outstnd_r2t =
2638 cpu_to_le16(*(uint16_t *)iface_param->value);
2639 break;
2640 case ISCSI_IFACE_PARAM_MAX_BURST:
2641 if (iface_param->iface_num & 0x1)
2642 break;
2643 init_fw_cb->iscsi_max_burst_len =
2644 cpu_to_le32(*(uint32_t *)iface_param->value) /
2645 BYTE_UNITS;
2646 break;
2647 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2648 if (iface_param->iface_num & 0x1)
2649 break;
2650 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2651 init_fw_cb->iscsi_opts |=
2652 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2653 else
2654 init_fw_cb->iscsi_opts &=
2655 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2656 break;
2657 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2658 if (iface_param->iface_num & 0x1)
2659 break;
2660 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2661 init_fw_cb->iscsi_opts |=
2662 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2663 else
2664 init_fw_cb->iscsi_opts &=
2665 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2666 break;
2667 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2668 if (iface_param->iface_num & 0x1)
2669 break;
2670 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2671 init_fw_cb->iscsi_opts |=
2672 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2673 else
2674 init_fw_cb->iscsi_opts &=
2675 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2676 break;
2677 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2678 if (iface_param->iface_num & 0x1)
2679 break;
2680 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2681 init_fw_cb->iscsi_opts |=
2682 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2683 else
2684 init_fw_cb->iscsi_opts &=
2685 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2686 break;
2687 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2688 if (iface_param->iface_num & 0x1)
2689 break;
2690 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2691 init_fw_cb->iscsi_opts |=
2692 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2693 else
2694 init_fw_cb->iscsi_opts &=
2695 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2696 break;
2697 default:
2698 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2699 iface_param->param);
2700 break;
2701 }
2702 }
2703
2704 static void
qla4xxx_initcb_to_acb(struct addr_ctrl_blk * init_fw_cb)2705 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2706 {
2707 struct addr_ctrl_blk_def *acb;
2708 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2709 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2710 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2711 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2712 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2713 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2714 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2715 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2716 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2717 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2718 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2719 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2720 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2721 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2722 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2723 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2724 }
2725
2726 static int
qla4xxx_iface_set_param(struct Scsi_Host * shost,void * data,uint32_t len)2727 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2728 {
2729 struct scsi_qla_host *ha = to_qla_host(shost);
2730 int rval = 0;
2731 struct iscsi_iface_param_info *iface_param = NULL;
2732 struct addr_ctrl_blk *init_fw_cb = NULL;
2733 dma_addr_t init_fw_cb_dma;
2734 uint32_t mbox_cmd[MBOX_REG_COUNT];
2735 uint32_t mbox_sts[MBOX_REG_COUNT];
2736 uint32_t rem = len;
2737 struct nlattr *attr;
2738
2739 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2740 sizeof(struct addr_ctrl_blk),
2741 &init_fw_cb_dma, GFP_KERNEL);
2742 if (!init_fw_cb) {
2743 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2744 __func__);
2745 return -ENOMEM;
2746 }
2747
2748 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2749 memset(&mbox_sts, 0, sizeof(mbox_sts));
2750
2751 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2752 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2753 rval = -EIO;
2754 goto exit_init_fw_cb;
2755 }
2756
2757 nla_for_each_attr(attr, data, len, rem) {
2758 if (nla_len(attr) < sizeof(*iface_param)) {
2759 rval = -EINVAL;
2760 goto exit_init_fw_cb;
2761 }
2762
2763 iface_param = nla_data(attr);
2764
2765 if (iface_param->param_type == ISCSI_NET_PARAM) {
2766 switch (iface_param->iface_type) {
2767 case ISCSI_IFACE_TYPE_IPV4:
2768 switch (iface_param->iface_num) {
2769 case 0:
2770 qla4xxx_set_ipv4(ha, iface_param,
2771 init_fw_cb);
2772 break;
2773 default:
2774 /* Cannot have more than one IPv4 interface */
2775 ql4_printk(KERN_ERR, ha,
2776 "Invalid IPv4 iface number = %d\n",
2777 iface_param->iface_num);
2778 break;
2779 }
2780 break;
2781 case ISCSI_IFACE_TYPE_IPV6:
2782 switch (iface_param->iface_num) {
2783 case 0:
2784 case 1:
2785 qla4xxx_set_ipv6(ha, iface_param,
2786 init_fw_cb);
2787 break;
2788 default:
2789 /* Cannot have more than two IPv6 interface */
2790 ql4_printk(KERN_ERR, ha,
2791 "Invalid IPv6 iface number = %d\n",
2792 iface_param->iface_num);
2793 break;
2794 }
2795 break;
2796 default:
2797 ql4_printk(KERN_ERR, ha,
2798 "Invalid iface type\n");
2799 break;
2800 }
2801 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2802 qla4xxx_set_iscsi_param(ha, iface_param,
2803 init_fw_cb);
2804 } else {
2805 continue;
2806 }
2807 }
2808
2809 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2810
2811 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2812 sizeof(struct addr_ctrl_blk),
2813 FLASH_OPT_RMW_COMMIT);
2814 if (rval != QLA_SUCCESS) {
2815 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2816 __func__);
2817 rval = -EIO;
2818 goto exit_init_fw_cb;
2819 }
2820
2821 rval = qla4xxx_disable_acb(ha);
2822 if (rval != QLA_SUCCESS) {
2823 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2824 __func__);
2825 rval = -EIO;
2826 goto exit_init_fw_cb;
2827 }
2828
2829 wait_for_completion_timeout(&ha->disable_acb_comp,
2830 DISABLE_ACB_TOV * HZ);
2831
2832 qla4xxx_initcb_to_acb(init_fw_cb);
2833
2834 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2835 if (rval != QLA_SUCCESS) {
2836 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2837 __func__);
2838 rval = -EIO;
2839 goto exit_init_fw_cb;
2840 }
2841
2842 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2843 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2844 init_fw_cb_dma);
2845
2846 exit_init_fw_cb:
2847 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2848 init_fw_cb, init_fw_cb_dma);
2849
2850 return rval;
2851 }
2852
qla4xxx_session_get_param(struct iscsi_cls_session * cls_sess,enum iscsi_param param,char * buf)2853 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2854 enum iscsi_param param, char *buf)
2855 {
2856 struct iscsi_session *sess = cls_sess->dd_data;
2857 struct ddb_entry *ddb_entry = sess->dd_data;
2858 struct scsi_qla_host *ha = ddb_entry->ha;
2859 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2860 struct ql4_chap_table chap_tbl;
2861 int rval, len;
2862 uint16_t idx;
2863
2864 memset(&chap_tbl, 0, sizeof(chap_tbl));
2865 switch (param) {
2866 case ISCSI_PARAM_CHAP_IN_IDX:
2867 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2868 sess->password_in, BIDI_CHAP,
2869 &idx);
2870 if (rval)
2871 len = sprintf(buf, "\n");
2872 else
2873 len = sprintf(buf, "%hu\n", idx);
2874 break;
2875 case ISCSI_PARAM_CHAP_OUT_IDX:
2876 if (ddb_entry->ddb_type == FLASH_DDB) {
2877 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2878 idx = ddb_entry->chap_tbl_idx;
2879 rval = QLA_SUCCESS;
2880 } else {
2881 rval = QLA_ERROR;
2882 }
2883 } else {
2884 rval = qla4xxx_get_chap_index(ha, sess->username,
2885 sess->password,
2886 LOCAL_CHAP, &idx);
2887 }
2888 if (rval)
2889 len = sprintf(buf, "\n");
2890 else
2891 len = sprintf(buf, "%hu\n", idx);
2892 break;
2893 case ISCSI_PARAM_USERNAME:
2894 case ISCSI_PARAM_PASSWORD:
2895 /* First, populate session username and password for FLASH DDB,
2896 * if not already done. This happens when session login fails
2897 * for a FLASH DDB.
2898 */
2899 if (ddb_entry->ddb_type == FLASH_DDB &&
2900 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2901 !sess->username && !sess->password) {
2902 idx = ddb_entry->chap_tbl_idx;
2903 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2904 chap_tbl.secret,
2905 idx);
2906 if (!rval) {
2907 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2908 (char *)chap_tbl.name,
2909 strlen((char *)chap_tbl.name));
2910 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2911 (char *)chap_tbl.secret,
2912 chap_tbl.secret_len);
2913 }
2914 }
2915 fallthrough;
2916 default:
2917 return iscsi_session_get_param(cls_sess, param, buf);
2918 }
2919
2920 return len;
2921 }
2922
qla4xxx_conn_get_param(struct iscsi_cls_conn * cls_conn,enum iscsi_param param,char * buf)2923 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2924 enum iscsi_param param, char *buf)
2925 {
2926 struct iscsi_conn *conn;
2927 struct qla_conn *qla_conn;
2928 struct sockaddr *dst_addr;
2929
2930 conn = cls_conn->dd_data;
2931 qla_conn = conn->dd_data;
2932 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2933
2934 switch (param) {
2935 case ISCSI_PARAM_CONN_PORT:
2936 case ISCSI_PARAM_CONN_ADDRESS:
2937 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2938 dst_addr, param, buf);
2939 default:
2940 return iscsi_conn_get_param(cls_conn, param, buf);
2941 }
2942 }
2943
qla4xxx_get_ddb_index(struct scsi_qla_host * ha,uint16_t * ddb_index)2944 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2945 {
2946 uint32_t mbx_sts = 0;
2947 uint16_t tmp_ddb_index;
2948 int ret;
2949
2950 get_ddb_index:
2951 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2952
2953 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2954 DEBUG2(ql4_printk(KERN_INFO, ha,
2955 "Free DDB index not available\n"));
2956 ret = QLA_ERROR;
2957 goto exit_get_ddb_index;
2958 }
2959
2960 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2961 goto get_ddb_index;
2962
2963 DEBUG2(ql4_printk(KERN_INFO, ha,
2964 "Found a free DDB index at %d\n", tmp_ddb_index));
2965 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2966 if (ret == QLA_ERROR) {
2967 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2968 ql4_printk(KERN_INFO, ha,
2969 "DDB index = %d not available trying next\n",
2970 tmp_ddb_index);
2971 goto get_ddb_index;
2972 }
2973 DEBUG2(ql4_printk(KERN_INFO, ha,
2974 "Free FW DDB not available\n"));
2975 }
2976
2977 *ddb_index = tmp_ddb_index;
2978
2979 exit_get_ddb_index:
2980 return ret;
2981 }
2982
qla4xxx_match_ipaddress(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry,char * existing_ipaddr,char * user_ipaddr)2983 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2984 struct ddb_entry *ddb_entry,
2985 char *existing_ipaddr,
2986 char *user_ipaddr)
2987 {
2988 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2989 char formatted_ipaddr[DDB_IPADDR_LEN];
2990 int status = QLA_SUCCESS, ret = 0;
2991
2992 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2993 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2994 '\0', NULL);
2995 if (ret == 0) {
2996 status = QLA_ERROR;
2997 goto out_match;
2998 }
2999 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
3000 } else {
3001 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
3002 '\0', NULL);
3003 if (ret == 0) {
3004 status = QLA_ERROR;
3005 goto out_match;
3006 }
3007 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
3008 }
3009
3010 if (strcmp(existing_ipaddr, formatted_ipaddr))
3011 status = QLA_ERROR;
3012
3013 out_match:
3014 return status;
3015 }
3016
qla4xxx_match_fwdb_session(struct scsi_qla_host * ha,struct iscsi_cls_conn * cls_conn)3017 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
3018 struct iscsi_cls_conn *cls_conn)
3019 {
3020 int idx = 0, max_ddbs, rval;
3021 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3022 struct iscsi_session *sess, *existing_sess;
3023 struct iscsi_conn *conn, *existing_conn;
3024 struct ddb_entry *ddb_entry;
3025
3026 sess = cls_sess->dd_data;
3027 conn = cls_conn->dd_data;
3028
3029 if (sess->targetname == NULL ||
3030 conn->persistent_address == NULL ||
3031 conn->persistent_port == 0)
3032 return QLA_ERROR;
3033
3034 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3035 MAX_DEV_DB_ENTRIES;
3036
3037 for (idx = 0; idx < max_ddbs; idx++) {
3038 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3039 if (ddb_entry == NULL)
3040 continue;
3041
3042 if (ddb_entry->ddb_type != FLASH_DDB)
3043 continue;
3044
3045 existing_sess = ddb_entry->sess->dd_data;
3046 existing_conn = ddb_entry->conn->dd_data;
3047
3048 if (existing_sess->targetname == NULL ||
3049 existing_conn->persistent_address == NULL ||
3050 existing_conn->persistent_port == 0)
3051 continue;
3052
3053 DEBUG2(ql4_printk(KERN_INFO, ha,
3054 "IQN = %s User IQN = %s\n",
3055 existing_sess->targetname,
3056 sess->targetname));
3057
3058 DEBUG2(ql4_printk(KERN_INFO, ha,
3059 "IP = %s User IP = %s\n",
3060 existing_conn->persistent_address,
3061 conn->persistent_address));
3062
3063 DEBUG2(ql4_printk(KERN_INFO, ha,
3064 "Port = %d User Port = %d\n",
3065 existing_conn->persistent_port,
3066 conn->persistent_port));
3067
3068 if (strcmp(existing_sess->targetname, sess->targetname))
3069 continue;
3070 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3071 existing_conn->persistent_address,
3072 conn->persistent_address);
3073 if (rval == QLA_ERROR)
3074 continue;
3075 if (existing_conn->persistent_port != conn->persistent_port)
3076 continue;
3077 break;
3078 }
3079
3080 if (idx == max_ddbs)
3081 return QLA_ERROR;
3082
3083 DEBUG2(ql4_printk(KERN_INFO, ha,
3084 "Match found in fwdb sessions\n"));
3085 return QLA_SUCCESS;
3086 }
3087
3088 static struct iscsi_cls_session *
qla4xxx_session_create(struct iscsi_endpoint * ep,uint16_t cmds_max,uint16_t qdepth,uint32_t initial_cmdsn)3089 qla4xxx_session_create(struct iscsi_endpoint *ep,
3090 uint16_t cmds_max, uint16_t qdepth,
3091 uint32_t initial_cmdsn)
3092 {
3093 struct iscsi_cls_session *cls_sess;
3094 struct scsi_qla_host *ha;
3095 struct qla_endpoint *qla_ep;
3096 struct ddb_entry *ddb_entry;
3097 uint16_t ddb_index;
3098 struct iscsi_session *sess;
3099 int ret;
3100
3101 if (!ep) {
3102 printk(KERN_ERR "qla4xxx: missing ep.\n");
3103 return NULL;
3104 }
3105
3106 qla_ep = ep->dd_data;
3107 ha = to_qla_host(qla_ep->host);
3108 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3109 ha->host_no));
3110
3111 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3112 if (ret == QLA_ERROR)
3113 return NULL;
3114
3115 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3116 cmds_max, sizeof(struct ddb_entry),
3117 sizeof(struct ql4_task_data),
3118 initial_cmdsn, ddb_index);
3119 if (!cls_sess)
3120 return NULL;
3121
3122 sess = cls_sess->dd_data;
3123 ddb_entry = sess->dd_data;
3124 ddb_entry->fw_ddb_index = ddb_index;
3125 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3126 ddb_entry->ha = ha;
3127 ddb_entry->sess = cls_sess;
3128 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3129 ddb_entry->ddb_change = qla4xxx_ddb_change;
3130 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3131 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3132 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3133 ha->tot_ddbs++;
3134
3135 return cls_sess;
3136 }
3137
qla4xxx_session_destroy(struct iscsi_cls_session * cls_sess)3138 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3139 {
3140 struct iscsi_session *sess;
3141 struct ddb_entry *ddb_entry;
3142 struct scsi_qla_host *ha;
3143 unsigned long flags, wtime;
3144 struct dev_db_entry *fw_ddb_entry = NULL;
3145 dma_addr_t fw_ddb_entry_dma;
3146 uint32_t ddb_state;
3147 int ret;
3148
3149 sess = cls_sess->dd_data;
3150 ddb_entry = sess->dd_data;
3151 ha = ddb_entry->ha;
3152 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3153 ha->host_no));
3154
3155 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3156 &fw_ddb_entry_dma, GFP_KERNEL);
3157 if (!fw_ddb_entry) {
3158 ql4_printk(KERN_ERR, ha,
3159 "%s: Unable to allocate dma buffer\n", __func__);
3160 goto destroy_session;
3161 }
3162
3163 wtime = jiffies + (HZ * LOGOUT_TOV);
3164 do {
3165 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3166 fw_ddb_entry, fw_ddb_entry_dma,
3167 NULL, NULL, &ddb_state, NULL,
3168 NULL, NULL);
3169 if (ret == QLA_ERROR)
3170 goto destroy_session;
3171
3172 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3173 (ddb_state == DDB_DS_SESSION_FAILED))
3174 goto destroy_session;
3175
3176 schedule_timeout_uninterruptible(HZ);
3177 } while ((time_after(wtime, jiffies)));
3178
3179 destroy_session:
3180 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3181 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3182 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3183 spin_lock_irqsave(&ha->hardware_lock, flags);
3184 qla4xxx_free_ddb(ha, ddb_entry);
3185 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3186
3187 iscsi_session_teardown(cls_sess);
3188
3189 if (fw_ddb_entry)
3190 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3191 fw_ddb_entry, fw_ddb_entry_dma);
3192 }
3193
3194 static struct iscsi_cls_conn *
qla4xxx_conn_create(struct iscsi_cls_session * cls_sess,uint32_t conn_idx)3195 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3196 {
3197 struct iscsi_cls_conn *cls_conn;
3198 struct iscsi_session *sess;
3199 struct ddb_entry *ddb_entry;
3200 struct scsi_qla_host *ha;
3201
3202 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3203 conn_idx);
3204 if (!cls_conn) {
3205 pr_info("%s: Can not create connection for conn_idx = %u\n",
3206 __func__, conn_idx);
3207 return NULL;
3208 }
3209
3210 sess = cls_sess->dd_data;
3211 ddb_entry = sess->dd_data;
3212 ddb_entry->conn = cls_conn;
3213
3214 ha = ddb_entry->ha;
3215 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3216 conn_idx));
3217 return cls_conn;
3218 }
3219
qla4xxx_conn_bind(struct iscsi_cls_session * cls_session,struct iscsi_cls_conn * cls_conn,uint64_t transport_fd,int is_leading)3220 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3221 struct iscsi_cls_conn *cls_conn,
3222 uint64_t transport_fd, int is_leading)
3223 {
3224 struct iscsi_conn *conn;
3225 struct qla_conn *qla_conn;
3226 struct iscsi_endpoint *ep;
3227 struct ddb_entry *ddb_entry;
3228 struct scsi_qla_host *ha;
3229 struct iscsi_session *sess;
3230
3231 sess = cls_session->dd_data;
3232 ddb_entry = sess->dd_data;
3233 ha = ddb_entry->ha;
3234
3235 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3236 cls_session->sid, cls_conn->cid));
3237
3238 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3239 return -EINVAL;
3240 ep = iscsi_lookup_endpoint(transport_fd);
3241 if (!ep)
3242 return -EINVAL;
3243 conn = cls_conn->dd_data;
3244 qla_conn = conn->dd_data;
3245 qla_conn->qla_ep = ep->dd_data;
3246 iscsi_put_endpoint(ep);
3247 return 0;
3248 }
3249
qla4xxx_conn_start(struct iscsi_cls_conn * cls_conn)3250 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3251 {
3252 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3253 struct iscsi_session *sess;
3254 struct ddb_entry *ddb_entry;
3255 struct scsi_qla_host *ha;
3256 struct dev_db_entry *fw_ddb_entry = NULL;
3257 dma_addr_t fw_ddb_entry_dma;
3258 uint32_t mbx_sts = 0;
3259 int ret = 0;
3260 int status = QLA_SUCCESS;
3261
3262 sess = cls_sess->dd_data;
3263 ddb_entry = sess->dd_data;
3264 ha = ddb_entry->ha;
3265 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3266 cls_sess->sid, cls_conn->cid));
3267
3268 /* Check if we have matching FW DDB, if yes then do not
3269 * login to this target. This could cause target to logout previous
3270 * connection
3271 */
3272 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3273 if (ret == QLA_SUCCESS) {
3274 ql4_printk(KERN_INFO, ha,
3275 "Session already exist in FW.\n");
3276 ret = -EEXIST;
3277 goto exit_conn_start;
3278 }
3279
3280 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3281 &fw_ddb_entry_dma, GFP_KERNEL);
3282 if (!fw_ddb_entry) {
3283 ql4_printk(KERN_ERR, ha,
3284 "%s: Unable to allocate dma buffer\n", __func__);
3285 ret = -ENOMEM;
3286 goto exit_conn_start;
3287 }
3288
3289 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3290 if (ret) {
3291 /* If iscsid is stopped and started then no need to do
3292 * set param again since ddb state will be already
3293 * active and FW does not allow set ddb to an
3294 * active session.
3295 */
3296 if (mbx_sts)
3297 if (ddb_entry->fw_ddb_device_state ==
3298 DDB_DS_SESSION_ACTIVE) {
3299 ddb_entry->unblock_sess(ddb_entry->sess);
3300 goto exit_set_param;
3301 }
3302
3303 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3304 __func__, ddb_entry->fw_ddb_index);
3305 goto exit_conn_start;
3306 }
3307
3308 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3309 if (status == QLA_ERROR) {
3310 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3311 sess->targetname);
3312 ret = -EINVAL;
3313 goto exit_conn_start;
3314 }
3315
3316 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3317 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3318
3319 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3320 ddb_entry->fw_ddb_device_state));
3321
3322 exit_set_param:
3323 ret = 0;
3324
3325 exit_conn_start:
3326 if (fw_ddb_entry)
3327 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3328 fw_ddb_entry, fw_ddb_entry_dma);
3329 return ret;
3330 }
3331
qla4xxx_conn_destroy(struct iscsi_cls_conn * cls_conn)3332 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3333 {
3334 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3335 struct iscsi_session *sess;
3336 struct scsi_qla_host *ha;
3337 struct ddb_entry *ddb_entry;
3338 int options;
3339
3340 sess = cls_sess->dd_data;
3341 ddb_entry = sess->dd_data;
3342 ha = ddb_entry->ha;
3343 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3344 cls_conn->cid));
3345
3346 options = LOGOUT_OPTION_CLOSE_SESSION;
3347 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3348 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3349 }
3350
qla4xxx_task_work(struct work_struct * wdata)3351 static void qla4xxx_task_work(struct work_struct *wdata)
3352 {
3353 struct ql4_task_data *task_data;
3354 struct scsi_qla_host *ha;
3355 struct passthru_status *sts;
3356 struct iscsi_task *task;
3357 struct iscsi_hdr *hdr;
3358 uint8_t *data;
3359 uint32_t data_len;
3360 struct iscsi_conn *conn;
3361 int hdr_len;
3362 itt_t itt;
3363
3364 task_data = container_of(wdata, struct ql4_task_data, task_work);
3365 ha = task_data->ha;
3366 task = task_data->task;
3367 sts = &task_data->sts;
3368 hdr_len = sizeof(struct iscsi_hdr);
3369
3370 DEBUG3(printk(KERN_INFO "Status returned\n"));
3371 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3372 DEBUG3(printk(KERN_INFO "Response buffer"));
3373 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3374
3375 conn = task->conn;
3376
3377 switch (sts->completionStatus) {
3378 case PASSTHRU_STATUS_COMPLETE:
3379 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3380 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3381 itt = sts->handle;
3382 hdr->itt = itt;
3383 data = task_data->resp_buffer + hdr_len;
3384 data_len = task_data->resp_len - hdr_len;
3385 iscsi_complete_pdu(conn, hdr, data, data_len);
3386 break;
3387 default:
3388 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3389 sts->completionStatus);
3390 break;
3391 }
3392 return;
3393 }
3394
qla4xxx_alloc_pdu(struct iscsi_task * task,uint8_t opcode)3395 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3396 {
3397 struct ql4_task_data *task_data;
3398 struct iscsi_session *sess;
3399 struct ddb_entry *ddb_entry;
3400 struct scsi_qla_host *ha;
3401 int hdr_len;
3402
3403 sess = task->conn->session;
3404 ddb_entry = sess->dd_data;
3405 ha = ddb_entry->ha;
3406 task_data = task->dd_data;
3407 memset(task_data, 0, sizeof(struct ql4_task_data));
3408
3409 if (task->sc) {
3410 ql4_printk(KERN_INFO, ha,
3411 "%s: SCSI Commands not implemented\n", __func__);
3412 return -EINVAL;
3413 }
3414
3415 hdr_len = sizeof(struct iscsi_hdr);
3416 task_data->ha = ha;
3417 task_data->task = task;
3418
3419 if (task->data_count) {
3420 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3421 task->data_count,
3422 DMA_TO_DEVICE);
3423 if (dma_mapping_error(&ha->pdev->dev, task_data->data_dma))
3424 return -ENOMEM;
3425 }
3426
3427 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3428 __func__, task->conn->max_recv_dlength, hdr_len));
3429
3430 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3431 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3432 task_data->resp_len,
3433 &task_data->resp_dma,
3434 GFP_ATOMIC);
3435 if (!task_data->resp_buffer)
3436 goto exit_alloc_pdu;
3437
3438 task_data->req_len = task->data_count + hdr_len;
3439 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3440 task_data->req_len,
3441 &task_data->req_dma,
3442 GFP_ATOMIC);
3443 if (!task_data->req_buffer)
3444 goto exit_alloc_pdu;
3445
3446 task->hdr = task_data->req_buffer;
3447
3448 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3449
3450 return 0;
3451
3452 exit_alloc_pdu:
3453 if (task_data->resp_buffer)
3454 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3455 task_data->resp_buffer, task_data->resp_dma);
3456
3457 if (task_data->req_buffer)
3458 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3459 task_data->req_buffer, task_data->req_dma);
3460 return -ENOMEM;
3461 }
3462
qla4xxx_task_cleanup(struct iscsi_task * task)3463 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3464 {
3465 struct ql4_task_data *task_data;
3466 struct iscsi_session *sess;
3467 struct ddb_entry *ddb_entry;
3468 struct scsi_qla_host *ha;
3469 int hdr_len;
3470
3471 hdr_len = sizeof(struct iscsi_hdr);
3472 sess = task->conn->session;
3473 ddb_entry = sess->dd_data;
3474 ha = ddb_entry->ha;
3475 task_data = task->dd_data;
3476
3477 if (task->data_count) {
3478 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3479 task->data_count, DMA_TO_DEVICE);
3480 }
3481
3482 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3483 __func__, task->conn->max_recv_dlength, hdr_len));
3484
3485 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3486 task_data->resp_buffer, task_data->resp_dma);
3487 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3488 task_data->req_buffer, task_data->req_dma);
3489 return;
3490 }
3491
qla4xxx_task_xmit(struct iscsi_task * task)3492 static int qla4xxx_task_xmit(struct iscsi_task *task)
3493 {
3494 struct scsi_cmnd *sc = task->sc;
3495 struct iscsi_session *sess = task->conn->session;
3496 struct ddb_entry *ddb_entry = sess->dd_data;
3497 struct scsi_qla_host *ha = ddb_entry->ha;
3498
3499 if (!sc)
3500 return qla4xxx_send_passthru0(task);
3501
3502 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3503 __func__);
3504 return -ENOSYS;
3505 }
3506
qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session * sess,struct iscsi_bus_flash_conn * conn,struct dev_db_entry * fw_ddb_entry)3507 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3508 struct iscsi_bus_flash_conn *conn,
3509 struct dev_db_entry *fw_ddb_entry)
3510 {
3511 unsigned long options = 0;
3512 int rc = 0;
3513
3514 options = le16_to_cpu(fw_ddb_entry->options);
3515 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3516 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3517 rc = iscsi_switch_str_param(&sess->portal_type,
3518 PORTAL_TYPE_IPV6);
3519 if (rc)
3520 goto exit_copy;
3521 } else {
3522 rc = iscsi_switch_str_param(&sess->portal_type,
3523 PORTAL_TYPE_IPV4);
3524 if (rc)
3525 goto exit_copy;
3526 }
3527
3528 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3529 &options);
3530 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3531 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3532
3533 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3534 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3535 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3536 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3537 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3538 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3539 &options);
3540 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3541 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3542 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3543 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3544 &options);
3545 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3546 sess->discovery_auth_optional =
3547 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3548 if (test_bit(ISCSIOPT_ERL1, &options))
3549 sess->erl |= BIT_1;
3550 if (test_bit(ISCSIOPT_ERL0, &options))
3551 sess->erl |= BIT_0;
3552
3553 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3554 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3555 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3556 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3557 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3558 conn->tcp_timer_scale |= BIT_3;
3559 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3560 conn->tcp_timer_scale |= BIT_2;
3561 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3562 conn->tcp_timer_scale |= BIT_1;
3563
3564 conn->tcp_timer_scale >>= 1;
3565 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3566
3567 options = le16_to_cpu(fw_ddb_entry->ip_options);
3568 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3569
3570 conn->max_recv_dlength = BYTE_UNITS *
3571 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3572 conn->max_xmit_dlength = BYTE_UNITS *
3573 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3574 sess->first_burst = BYTE_UNITS *
3575 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3576 sess->max_burst = BYTE_UNITS *
3577 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3578 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3579 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3580 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3581 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3582 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3583 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3584 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3585 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3586 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3587 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3588 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3589 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3590 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3591 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3592 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3593 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3594
3595 sess->default_taskmgmt_timeout =
3596 le16_to_cpu(fw_ddb_entry->def_timeout);
3597 conn->port = le16_to_cpu(fw_ddb_entry->port);
3598
3599 options = le16_to_cpu(fw_ddb_entry->options);
3600 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3601 if (!conn->ipaddress) {
3602 rc = -ENOMEM;
3603 goto exit_copy;
3604 }
3605
3606 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3607 if (!conn->redirect_ipaddr) {
3608 rc = -ENOMEM;
3609 goto exit_copy;
3610 }
3611
3612 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3613 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3614
3615 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3616 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3617
3618 conn->link_local_ipv6_addr = kmemdup(
3619 fw_ddb_entry->link_local_ipv6_addr,
3620 IPv6_ADDR_LEN, GFP_KERNEL);
3621 if (!conn->link_local_ipv6_addr) {
3622 rc = -ENOMEM;
3623 goto exit_copy;
3624 }
3625 } else {
3626 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3627 }
3628
3629 if (fw_ddb_entry->iscsi_name[0]) {
3630 rc = iscsi_switch_str_param(&sess->targetname,
3631 (char *)fw_ddb_entry->iscsi_name);
3632 if (rc)
3633 goto exit_copy;
3634 }
3635
3636 if (fw_ddb_entry->iscsi_alias[0]) {
3637 rc = iscsi_switch_str_param(&sess->targetalias,
3638 (char *)fw_ddb_entry->iscsi_alias);
3639 if (rc)
3640 goto exit_copy;
3641 }
3642
3643 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3644
3645 exit_copy:
3646 return rc;
3647 }
3648
qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session * sess,struct iscsi_bus_flash_conn * conn,struct dev_db_entry * fw_ddb_entry)3649 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3650 struct iscsi_bus_flash_conn *conn,
3651 struct dev_db_entry *fw_ddb_entry)
3652 {
3653 uint16_t options;
3654
3655 options = le16_to_cpu(fw_ddb_entry->options);
3656 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3657 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3658 options |= BIT_8;
3659 else
3660 options &= ~BIT_8;
3661
3662 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3663 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3664 SET_BITVAL(sess->entry_state, options, BIT_3);
3665 fw_ddb_entry->options = cpu_to_le16(options);
3666
3667 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3668 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3669 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3670 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3671 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3672 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3673 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3674 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3675 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3676 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3677 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3678 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3679 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3680 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3681 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3682
3683 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3684 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3685 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3686 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3687 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3688 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3689 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3690 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3691 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3692
3693 options = le16_to_cpu(fw_ddb_entry->ip_options);
3694 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3695 fw_ddb_entry->ip_options = cpu_to_le16(options);
3696
3697 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3698 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3699 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3700 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3701 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3702 fw_ddb_entry->iscsi_first_burst_len =
3703 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3704 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3705 BYTE_UNITS);
3706 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3707 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3708 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3709 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3710 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3711 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3712 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3713 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3714 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3715 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3716 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3717 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3718 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3719 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3720 fw_ddb_entry->port = cpu_to_le16(conn->port);
3721 fw_ddb_entry->def_timeout =
3722 cpu_to_le16(sess->default_taskmgmt_timeout);
3723
3724 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3725 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3726 else
3727 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3728
3729 if (conn->ipaddress)
3730 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3731 sizeof(fw_ddb_entry->ip_addr));
3732
3733 if (conn->redirect_ipaddr)
3734 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3735 sizeof(fw_ddb_entry->tgt_addr));
3736
3737 if (conn->link_local_ipv6_addr)
3738 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3739 conn->link_local_ipv6_addr,
3740 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3741
3742 if (sess->targetname)
3743 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3744 sizeof(fw_ddb_entry->iscsi_name));
3745
3746 if (sess->targetalias)
3747 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3748 sizeof(fw_ddb_entry->iscsi_alias));
3749
3750 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3751
3752 return 0;
3753 }
3754
qla4xxx_copy_to_sess_conn_params(struct iscsi_conn * conn,struct iscsi_session * sess,struct dev_db_entry * fw_ddb_entry)3755 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3756 struct iscsi_session *sess,
3757 struct dev_db_entry *fw_ddb_entry)
3758 {
3759 unsigned long options = 0;
3760 uint16_t ddb_link;
3761 uint16_t disc_parent;
3762 char ip_addr[DDB_IPADDR_LEN];
3763
3764 options = le16_to_cpu(fw_ddb_entry->options);
3765 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3766 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3767 &options);
3768 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3769
3770 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3771 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3772 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3773 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3774 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3775 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3776 &options);
3777 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3778 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3779 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3780 &options);
3781 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3782 sess->discovery_auth_optional =
3783 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3784 if (test_bit(ISCSIOPT_ERL1, &options))
3785 sess->erl |= BIT_1;
3786 if (test_bit(ISCSIOPT_ERL0, &options))
3787 sess->erl |= BIT_0;
3788
3789 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3790 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3791 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3792 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3793 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3794 conn->tcp_timer_scale |= BIT_3;
3795 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3796 conn->tcp_timer_scale |= BIT_2;
3797 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3798 conn->tcp_timer_scale |= BIT_1;
3799
3800 conn->tcp_timer_scale >>= 1;
3801 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3802
3803 options = le16_to_cpu(fw_ddb_entry->ip_options);
3804 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3805
3806 conn->max_recv_dlength = BYTE_UNITS *
3807 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3808 conn->max_xmit_dlength = BYTE_UNITS *
3809 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3810 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3811 sess->first_burst = BYTE_UNITS *
3812 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3813 sess->max_burst = BYTE_UNITS *
3814 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3815 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3816 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3817 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3818 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3819 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3820 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3821 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3822 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3823 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3824 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3825 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3826 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3827 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3828
3829 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3830 if (ddb_link == DDB_ISNS)
3831 disc_parent = ISCSI_DISC_PARENT_ISNS;
3832 else if (ddb_link == DDB_NO_LINK)
3833 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3834 else if (ddb_link < MAX_DDB_ENTRIES)
3835 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3836 else
3837 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3838
3839 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3840 iscsi_get_discovery_parent_name(disc_parent), 0);
3841
3842 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3843 (char *)fw_ddb_entry->iscsi_alias, 0);
3844
3845 options = le16_to_cpu(fw_ddb_entry->options);
3846 if (options & DDB_OPT_IPV6_DEVICE) {
3847 memset(ip_addr, 0, sizeof(ip_addr));
3848 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3849 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3850 (char *)ip_addr, 0);
3851 }
3852 }
3853
qla4xxx_copy_fwddb_param(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,struct iscsi_cls_session * cls_sess,struct iscsi_cls_conn * cls_conn)3854 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3855 struct dev_db_entry *fw_ddb_entry,
3856 struct iscsi_cls_session *cls_sess,
3857 struct iscsi_cls_conn *cls_conn)
3858 {
3859 int buflen = 0;
3860 struct iscsi_session *sess;
3861 struct ddb_entry *ddb_entry;
3862 struct ql4_chap_table chap_tbl;
3863 struct iscsi_conn *conn;
3864 char ip_addr[DDB_IPADDR_LEN];
3865 uint16_t options = 0;
3866
3867 sess = cls_sess->dd_data;
3868 ddb_entry = sess->dd_data;
3869 conn = cls_conn->dd_data;
3870 memset(&chap_tbl, 0, sizeof(chap_tbl));
3871
3872 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3873
3874 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3875
3876 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3877 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3878
3879 memset(ip_addr, 0, sizeof(ip_addr));
3880 options = le16_to_cpu(fw_ddb_entry->options);
3881 if (options & DDB_OPT_IPV6_DEVICE) {
3882 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3883
3884 memset(ip_addr, 0, sizeof(ip_addr));
3885 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3886 } else {
3887 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3888 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3889 }
3890
3891 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3892 (char *)ip_addr, buflen);
3893 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3894 (char *)fw_ddb_entry->iscsi_name, buflen);
3895 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3896 (char *)ha->name_string, buflen);
3897
3898 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3899 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3900 chap_tbl.secret,
3901 ddb_entry->chap_tbl_idx)) {
3902 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3903 (char *)chap_tbl.name,
3904 strlen((char *)chap_tbl.name));
3905 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3906 (char *)chap_tbl.secret,
3907 chap_tbl.secret_len);
3908 }
3909 }
3910 }
3911
qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry)3912 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3913 struct ddb_entry *ddb_entry)
3914 {
3915 struct iscsi_cls_session *cls_sess;
3916 struct iscsi_cls_conn *cls_conn;
3917 uint32_t ddb_state;
3918 dma_addr_t fw_ddb_entry_dma;
3919 struct dev_db_entry *fw_ddb_entry;
3920
3921 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3922 &fw_ddb_entry_dma, GFP_KERNEL);
3923 if (!fw_ddb_entry) {
3924 ql4_printk(KERN_ERR, ha,
3925 "%s: Unable to allocate dma buffer\n", __func__);
3926 goto exit_session_conn_fwddb_param;
3927 }
3928
3929 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3930 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3931 NULL, NULL, NULL) == QLA_ERROR) {
3932 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3933 "get_ddb_entry for fw_ddb_index %d\n",
3934 ha->host_no, __func__,
3935 ddb_entry->fw_ddb_index));
3936 goto exit_session_conn_fwddb_param;
3937 }
3938
3939 cls_sess = ddb_entry->sess;
3940
3941 cls_conn = ddb_entry->conn;
3942
3943 /* Update params */
3944 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3945
3946 exit_session_conn_fwddb_param:
3947 if (fw_ddb_entry)
3948 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3949 fw_ddb_entry, fw_ddb_entry_dma);
3950 }
3951
qla4xxx_update_session_conn_param(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry)3952 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3953 struct ddb_entry *ddb_entry)
3954 {
3955 struct iscsi_cls_session *cls_sess;
3956 struct iscsi_cls_conn *cls_conn;
3957 struct iscsi_session *sess;
3958 struct iscsi_conn *conn;
3959 uint32_t ddb_state;
3960 dma_addr_t fw_ddb_entry_dma;
3961 struct dev_db_entry *fw_ddb_entry;
3962
3963 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3964 &fw_ddb_entry_dma, GFP_KERNEL);
3965 if (!fw_ddb_entry) {
3966 ql4_printk(KERN_ERR, ha,
3967 "%s: Unable to allocate dma buffer\n", __func__);
3968 goto exit_session_conn_param;
3969 }
3970
3971 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3972 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3973 NULL, NULL, NULL) == QLA_ERROR) {
3974 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3975 "get_ddb_entry for fw_ddb_index %d\n",
3976 ha->host_no, __func__,
3977 ddb_entry->fw_ddb_index));
3978 goto exit_session_conn_param;
3979 }
3980
3981 cls_sess = ddb_entry->sess;
3982 sess = cls_sess->dd_data;
3983
3984 cls_conn = ddb_entry->conn;
3985 conn = cls_conn->dd_data;
3986
3987 /* Update timers after login */
3988 ddb_entry->default_relogin_timeout =
3989 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3990 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3991 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3992 ddb_entry->default_time2wait =
3993 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3994
3995 /* Update params */
3996 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3997 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3998
3999 memcpy(sess->initiatorname, ha->name_string,
4000 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
4001
4002 exit_session_conn_param:
4003 if (fw_ddb_entry)
4004 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4005 fw_ddb_entry, fw_ddb_entry_dma);
4006 }
4007
4008 /*
4009 * Timer routines
4010 */
4011 static void qla4xxx_timer(struct timer_list *t);
4012
qla4xxx_start_timer(struct scsi_qla_host * ha,unsigned long interval)4013 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
4014 unsigned long interval)
4015 {
4016 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
4017 __func__, ha->host->host_no));
4018 timer_setup(&ha->timer, qla4xxx_timer, 0);
4019 ha->timer.expires = jiffies + interval * HZ;
4020 add_timer(&ha->timer);
4021 ha->timer_active = 1;
4022 }
4023
qla4xxx_stop_timer(struct scsi_qla_host * ha)4024 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4025 {
4026 del_timer_sync(&ha->timer);
4027 ha->timer_active = 0;
4028 }
4029
4030 /***
4031 * qla4xxx_mark_device_missing - blocks the session
4032 * @cls_session: Pointer to the session to be blocked
4033 * @ddb_entry: Pointer to device database entry
4034 *
4035 * This routine marks a device missing and close connection.
4036 **/
qla4xxx_mark_device_missing(struct iscsi_cls_session * cls_session)4037 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4038 {
4039 iscsi_block_session(cls_session);
4040 }
4041
4042 /**
4043 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4044 * @ha: Pointer to host adapter structure.
4045 *
4046 * This routine marks a device missing and resets the relogin retry count.
4047 **/
qla4xxx_mark_all_devices_missing(struct scsi_qla_host * ha)4048 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4049 {
4050 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4051 }
4052
qla4xxx_get_new_srb(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry,struct scsi_cmnd * cmd)4053 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4054 struct ddb_entry *ddb_entry,
4055 struct scsi_cmnd *cmd)
4056 {
4057 struct srb *srb;
4058
4059 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4060 if (!srb)
4061 return srb;
4062
4063 kref_init(&srb->srb_ref);
4064 srb->ha = ha;
4065 srb->ddb = ddb_entry;
4066 srb->cmd = cmd;
4067 srb->flags = 0;
4068 qla4xxx_cmd_priv(cmd)->srb = srb;
4069
4070 return srb;
4071 }
4072
qla4xxx_srb_free_dma(struct scsi_qla_host * ha,struct srb * srb)4073 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4074 {
4075 struct scsi_cmnd *cmd = srb->cmd;
4076
4077 if (srb->flags & SRB_DMA_VALID) {
4078 scsi_dma_unmap(cmd);
4079 srb->flags &= ~SRB_DMA_VALID;
4080 }
4081 qla4xxx_cmd_priv(cmd)->srb = NULL;
4082 }
4083
qla4xxx_srb_compl(struct kref * ref)4084 void qla4xxx_srb_compl(struct kref *ref)
4085 {
4086 struct srb *srb = container_of(ref, struct srb, srb_ref);
4087 struct scsi_cmnd *cmd = srb->cmd;
4088 struct scsi_qla_host *ha = srb->ha;
4089
4090 qla4xxx_srb_free_dma(ha, srb);
4091
4092 mempool_free(srb, ha->srb_mempool);
4093
4094 scsi_done(cmd);
4095 }
4096
4097 /**
4098 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4099 * @host: scsi host
4100 * @cmd: Pointer to Linux's SCSI command structure
4101 *
4102 * Remarks:
4103 * This routine is invoked by Linux to send a SCSI command to the driver.
4104 * The mid-level driver tries to ensure that queuecommand never gets
4105 * invoked concurrently with itself or the interrupt handler (although
4106 * the interrupt handler may call this routine as part of request-
4107 * completion handling). Unfortunely, it sometimes calls the scheduler
4108 * in interrupt context which is a big NO! NO!.
4109 **/
qla4xxx_queuecommand(struct Scsi_Host * host,struct scsi_cmnd * cmd)4110 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4111 {
4112 struct scsi_qla_host *ha = to_qla_host(host);
4113 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4114 struct iscsi_cls_session *sess = ddb_entry->sess;
4115 struct srb *srb;
4116 int rval;
4117
4118 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4119 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4120 cmd->result = DID_NO_CONNECT << 16;
4121 else
4122 cmd->result = DID_REQUEUE << 16;
4123 goto qc_fail_command;
4124 }
4125
4126 if (!sess) {
4127 cmd->result = DID_IMM_RETRY << 16;
4128 goto qc_fail_command;
4129 }
4130
4131 rval = iscsi_session_chkready(sess);
4132 if (rval) {
4133 cmd->result = rval;
4134 goto qc_fail_command;
4135 }
4136
4137 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4138 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4139 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4140 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4141 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4142 !test_bit(AF_ONLINE, &ha->flags) ||
4143 !test_bit(AF_LINK_UP, &ha->flags) ||
4144 test_bit(AF_LOOPBACK, &ha->flags) ||
4145 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4146 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4147 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4148 goto qc_host_busy;
4149
4150 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4151 if (!srb)
4152 goto qc_host_busy;
4153
4154 rval = qla4xxx_send_command_to_isp(ha, srb);
4155 if (rval != QLA_SUCCESS)
4156 goto qc_host_busy_free_sp;
4157
4158 return 0;
4159
4160 qc_host_busy_free_sp:
4161 qla4xxx_srb_free_dma(ha, srb);
4162 mempool_free(srb, ha->srb_mempool);
4163
4164 qc_host_busy:
4165 return SCSI_MLQUEUE_HOST_BUSY;
4166
4167 qc_fail_command:
4168 scsi_done(cmd);
4169
4170 return 0;
4171 }
4172
4173 /**
4174 * qla4xxx_mem_free - frees memory allocated to adapter
4175 * @ha: Pointer to host adapter structure.
4176 *
4177 * Frees memory previously allocated by qla4xxx_mem_alloc
4178 **/
qla4xxx_mem_free(struct scsi_qla_host * ha)4179 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4180 {
4181 if (ha->queues)
4182 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4183 ha->queues_dma);
4184
4185 vfree(ha->fw_dump);
4186
4187 ha->queues_len = 0;
4188 ha->queues = NULL;
4189 ha->queues_dma = 0;
4190 ha->request_ring = NULL;
4191 ha->request_dma = 0;
4192 ha->response_ring = NULL;
4193 ha->response_dma = 0;
4194 ha->shadow_regs = NULL;
4195 ha->shadow_regs_dma = 0;
4196 ha->fw_dump = NULL;
4197 ha->fw_dump_size = 0;
4198
4199 /* Free srb pool. */
4200 mempool_destroy(ha->srb_mempool);
4201 ha->srb_mempool = NULL;
4202
4203 dma_pool_destroy(ha->chap_dma_pool);
4204
4205 vfree(ha->chap_list);
4206 ha->chap_list = NULL;
4207
4208 dma_pool_destroy(ha->fw_ddb_dma_pool);
4209
4210 /* release io space registers */
4211 if (is_qla8022(ha)) {
4212 if (ha->nx_pcibase)
4213 iounmap(
4214 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4215 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4216 if (ha->nx_pcibase)
4217 iounmap(
4218 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4219 } else if (ha->reg) {
4220 iounmap(ha->reg);
4221 }
4222
4223 vfree(ha->reset_tmplt.buff);
4224
4225 pci_release_regions(ha->pdev);
4226 }
4227
4228 /**
4229 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4230 * @ha: Pointer to host adapter structure
4231 *
4232 * Allocates DMA memory for request and response queues. Also allocates memory
4233 * for srbs.
4234 **/
qla4xxx_mem_alloc(struct scsi_qla_host * ha)4235 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4236 {
4237 unsigned long align;
4238
4239 /* Allocate contiguous block of DMA memory for queues. */
4240 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4241 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4242 sizeof(struct shadow_regs) +
4243 MEM_ALIGN_VALUE +
4244 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4245 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4246 &ha->queues_dma, GFP_KERNEL);
4247 if (ha->queues == NULL) {
4248 ql4_printk(KERN_WARNING, ha,
4249 "Memory Allocation failed - queues.\n");
4250
4251 goto mem_alloc_error_exit;
4252 }
4253
4254 /*
4255 * As per RISC alignment requirements -- the bus-address must be a
4256 * multiple of the request-ring size (in bytes).
4257 */
4258 align = 0;
4259 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4260 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4261 (MEM_ALIGN_VALUE - 1));
4262
4263 /* Update request and response queue pointers. */
4264 ha->request_dma = ha->queues_dma + align;
4265 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4266 ha->response_dma = ha->queues_dma + align +
4267 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4268 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4269 (REQUEST_QUEUE_DEPTH *
4270 QUEUE_SIZE));
4271 ha->shadow_regs_dma = ha->queues_dma + align +
4272 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4273 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4274 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4275 (REQUEST_QUEUE_DEPTH *
4276 QUEUE_SIZE) +
4277 (RESPONSE_QUEUE_DEPTH *
4278 QUEUE_SIZE));
4279
4280 /* Allocate memory for srb pool. */
4281 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4282 mempool_free_slab, srb_cachep);
4283 if (ha->srb_mempool == NULL) {
4284 ql4_printk(KERN_WARNING, ha,
4285 "Memory Allocation failed - SRB Pool.\n");
4286
4287 goto mem_alloc_error_exit;
4288 }
4289
4290 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4291 CHAP_DMA_BLOCK_SIZE, 8, 0);
4292
4293 if (ha->chap_dma_pool == NULL) {
4294 ql4_printk(KERN_WARNING, ha,
4295 "%s: chap_dma_pool allocation failed..\n", __func__);
4296 goto mem_alloc_error_exit;
4297 }
4298
4299 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4300 DDB_DMA_BLOCK_SIZE, 8, 0);
4301
4302 if (ha->fw_ddb_dma_pool == NULL) {
4303 ql4_printk(KERN_WARNING, ha,
4304 "%s: fw_ddb_dma_pool allocation failed..\n",
4305 __func__);
4306 goto mem_alloc_error_exit;
4307 }
4308
4309 return QLA_SUCCESS;
4310
4311 mem_alloc_error_exit:
4312 return QLA_ERROR;
4313 }
4314
4315 /**
4316 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4317 * @ha: adapter block pointer.
4318 *
4319 * Note: The caller should not hold the idc lock.
4320 **/
qla4_8xxx_check_temp(struct scsi_qla_host * ha)4321 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4322 {
4323 uint32_t temp, temp_state, temp_val;
4324 int status = QLA_SUCCESS;
4325
4326 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4327
4328 temp_state = qla82xx_get_temp_state(temp);
4329 temp_val = qla82xx_get_temp_val(temp);
4330
4331 if (temp_state == QLA82XX_TEMP_PANIC) {
4332 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4333 " exceeds maximum allowed. Hardware has been shut"
4334 " down.\n", temp_val);
4335 status = QLA_ERROR;
4336 } else if (temp_state == QLA82XX_TEMP_WARN) {
4337 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4338 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4339 " degrees C exceeds operating range."
4340 " Immediate action needed.\n", temp_val);
4341 } else {
4342 if (ha->temperature == QLA82XX_TEMP_WARN)
4343 ql4_printk(KERN_INFO, ha, "Device temperature is"
4344 " now %d degrees C in normal range.\n",
4345 temp_val);
4346 }
4347 ha->temperature = temp_state;
4348 return status;
4349 }
4350
4351 /**
4352 * qla4_8xxx_check_fw_alive - Check firmware health
4353 * @ha: Pointer to host adapter structure.
4354 *
4355 * Context: Interrupt
4356 **/
qla4_8xxx_check_fw_alive(struct scsi_qla_host * ha)4357 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4358 {
4359 uint32_t fw_heartbeat_counter;
4360 int status = QLA_SUCCESS;
4361
4362 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4363 QLA8XXX_PEG_ALIVE_COUNTER);
4364 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4365 if (fw_heartbeat_counter == 0xffffffff) {
4366 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4367 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4368 ha->host_no, __func__));
4369 return status;
4370 }
4371
4372 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4373 ha->seconds_since_last_heartbeat++;
4374 /* FW not alive after 2 seconds */
4375 if (ha->seconds_since_last_heartbeat == 2) {
4376 ha->seconds_since_last_heartbeat = 0;
4377 qla4_8xxx_dump_peg_reg(ha);
4378 status = QLA_ERROR;
4379 }
4380 } else
4381 ha->seconds_since_last_heartbeat = 0;
4382
4383 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4384 return status;
4385 }
4386
qla4_8xxx_process_fw_error(struct scsi_qla_host * ha)4387 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4388 {
4389 uint32_t halt_status;
4390 int halt_status_unrecoverable = 0;
4391
4392 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4393
4394 if (is_qla8022(ha)) {
4395 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4396 __func__);
4397 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4398 CRB_NIU_XG_PAUSE_CTL_P0 |
4399 CRB_NIU_XG_PAUSE_CTL_P1);
4400
4401 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4402 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4403 __func__);
4404 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4405 halt_status_unrecoverable = 1;
4406 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4407 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4408 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4409 __func__);
4410 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4411 halt_status_unrecoverable = 1;
4412 }
4413
4414 /*
4415 * Since we cannot change dev_state in interrupt context,
4416 * set appropriate DPC flag then wakeup DPC
4417 */
4418 if (halt_status_unrecoverable) {
4419 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4420 } else {
4421 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4422 __func__);
4423 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4424 }
4425 qla4xxx_mailbox_premature_completion(ha);
4426 qla4xxx_wake_dpc(ha);
4427 }
4428
4429 /**
4430 * qla4_8xxx_watchdog - Poll dev state
4431 * @ha: Pointer to host adapter structure.
4432 *
4433 * Context: Interrupt
4434 **/
qla4_8xxx_watchdog(struct scsi_qla_host * ha)4435 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4436 {
4437 uint32_t dev_state;
4438 uint32_t idc_ctrl;
4439
4440 if (is_qla8032(ha) &&
4441 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4442 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4443 __func__, ha->func_num);
4444
4445 /* don't poll if reset is going on */
4446 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4447 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4448 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4449 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4450
4451 if (qla4_8xxx_check_temp(ha)) {
4452 if (is_qla8022(ha)) {
4453 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4454 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4455 CRB_NIU_XG_PAUSE_CTL_P0 |
4456 CRB_NIU_XG_PAUSE_CTL_P1);
4457 }
4458 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4459 qla4xxx_wake_dpc(ha);
4460 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4461 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4462
4463 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4464 __func__);
4465
4466 if (is_qla8032(ha) || is_qla8042(ha)) {
4467 idc_ctrl = qla4_83xx_rd_reg(ha,
4468 QLA83XX_IDC_DRV_CTRL);
4469 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4470 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4471 __func__);
4472 qla4xxx_mailbox_premature_completion(
4473 ha);
4474 }
4475 }
4476
4477 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4478 (is_qla8022(ha) && !ql4xdontresethba)) {
4479 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4480 qla4xxx_wake_dpc(ha);
4481 }
4482 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4483 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4484 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4485 __func__);
4486 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4487 qla4xxx_wake_dpc(ha);
4488 } else {
4489 /* Check firmware health */
4490 if (qla4_8xxx_check_fw_alive(ha))
4491 qla4_8xxx_process_fw_error(ha);
4492 }
4493 }
4494 }
4495
qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session * cls_sess)4496 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4497 {
4498 struct iscsi_session *sess;
4499 struct ddb_entry *ddb_entry;
4500 struct scsi_qla_host *ha;
4501
4502 sess = cls_sess->dd_data;
4503 ddb_entry = sess->dd_data;
4504 ha = ddb_entry->ha;
4505
4506 if (!(ddb_entry->ddb_type == FLASH_DDB))
4507 return;
4508
4509 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4510 !iscsi_is_session_online(cls_sess)) {
4511 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4512 INVALID_ENTRY) {
4513 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4514 0) {
4515 atomic_set(&ddb_entry->retry_relogin_timer,
4516 INVALID_ENTRY);
4517 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4518 set_bit(DF_RELOGIN, &ddb_entry->flags);
4519 DEBUG2(ql4_printk(KERN_INFO, ha,
4520 "%s: index [%d] login device\n",
4521 __func__, ddb_entry->fw_ddb_index));
4522 } else
4523 atomic_dec(&ddb_entry->retry_relogin_timer);
4524 }
4525 }
4526
4527 /* Wait for relogin to timeout */
4528 if (atomic_read(&ddb_entry->relogin_timer) &&
4529 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4530 /*
4531 * If the relogin times out and the device is
4532 * still NOT ONLINE then try and relogin again.
4533 */
4534 if (!iscsi_is_session_online(cls_sess)) {
4535 /* Reset retry relogin timer */
4536 atomic_inc(&ddb_entry->relogin_retry_count);
4537 DEBUG2(ql4_printk(KERN_INFO, ha,
4538 "%s: index[%d] relogin timed out-retrying"
4539 " relogin (%d), retry (%d)\n", __func__,
4540 ddb_entry->fw_ddb_index,
4541 atomic_read(&ddb_entry->relogin_retry_count),
4542 ddb_entry->default_time2wait + 4));
4543 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4544 atomic_set(&ddb_entry->retry_relogin_timer,
4545 ddb_entry->default_time2wait + 4);
4546 }
4547 }
4548 }
4549
4550 /**
4551 * qla4xxx_timer - checks every second for work to do.
4552 * @t: Context to obtain pointer to host adapter structure.
4553 **/
qla4xxx_timer(struct timer_list * t)4554 static void qla4xxx_timer(struct timer_list *t)
4555 {
4556 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4557 int start_dpc = 0;
4558 uint16_t w;
4559
4560 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4561
4562 /* If we are in the middle of AER/EEH processing
4563 * skip any processing and reschedule the timer
4564 */
4565 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4566 mod_timer(&ha->timer, jiffies + HZ);
4567 return;
4568 }
4569
4570 /* Hardware read to trigger an EEH error during mailbox waits. */
4571 if (!pci_channel_offline(ha->pdev))
4572 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4573
4574 if (is_qla80XX(ha))
4575 qla4_8xxx_watchdog(ha);
4576
4577 if (is_qla40XX(ha)) {
4578 /* Check for heartbeat interval. */
4579 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4580 ha->heartbeat_interval != 0) {
4581 ha->seconds_since_last_heartbeat++;
4582 if (ha->seconds_since_last_heartbeat >
4583 ha->heartbeat_interval + 2)
4584 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4585 }
4586 }
4587
4588 /* Process any deferred work. */
4589 if (!list_empty(&ha->work_list))
4590 start_dpc++;
4591
4592 /* Wakeup the dpc routine for this adapter, if needed. */
4593 if (start_dpc ||
4594 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4595 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4596 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4597 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4598 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4599 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4600 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4601 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4602 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4603 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4604 test_bit(DPC_AEN, &ha->dpc_flags)) {
4605 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4606 " - dpc flags = 0x%lx\n",
4607 ha->host_no, __func__, ha->dpc_flags));
4608 qla4xxx_wake_dpc(ha);
4609 }
4610
4611 /* Reschedule timer thread to call us back in one second */
4612 mod_timer(&ha->timer, jiffies + HZ);
4613
4614 DEBUG2(ha->seconds_since_last_intr++);
4615 }
4616
4617 /**
4618 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4619 * @ha: Pointer to host adapter structure.
4620 *
4621 * This routine stalls the driver until all outstanding commands are returned.
4622 * Caller must release the Hardware Lock prior to calling this routine.
4623 **/
qla4xxx_cmd_wait(struct scsi_qla_host * ha)4624 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4625 {
4626 uint32_t index = 0;
4627 unsigned long flags;
4628 struct scsi_cmnd *cmd;
4629 unsigned long wtime;
4630 uint32_t wtmo;
4631
4632 if (is_qla40XX(ha))
4633 wtmo = WAIT_CMD_TOV;
4634 else
4635 wtmo = ha->nx_reset_timeout / 2;
4636
4637 wtime = jiffies + (wtmo * HZ);
4638
4639 DEBUG2(ql4_printk(KERN_INFO, ha,
4640 "Wait up to %u seconds for cmds to complete\n",
4641 wtmo));
4642
4643 while (!time_after_eq(jiffies, wtime)) {
4644 spin_lock_irqsave(&ha->hardware_lock, flags);
4645 /* Find a command that hasn't completed. */
4646 for (index = 0; index < ha->host->can_queue; index++) {
4647 cmd = scsi_host_find_tag(ha->host, index);
4648 /*
4649 * We cannot just check if the index is valid,
4650 * becase if we are run from the scsi eh, then
4651 * the scsi/block layer is going to prevent
4652 * the tag from being released.
4653 */
4654 if (cmd != NULL && qla4xxx_cmd_priv(cmd)->srb)
4655 break;
4656 }
4657 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4658
4659 /* If No Commands are pending, wait is complete */
4660 if (index == ha->host->can_queue)
4661 return QLA_SUCCESS;
4662
4663 msleep(1000);
4664 }
4665 /* If we timed out on waiting for commands to come back
4666 * return ERROR. */
4667 return QLA_ERROR;
4668 }
4669
qla4xxx_hw_reset(struct scsi_qla_host * ha)4670 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4671 {
4672 uint32_t ctrl_status;
4673 unsigned long flags = 0;
4674
4675 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4676
4677 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4678 return QLA_ERROR;
4679
4680 spin_lock_irqsave(&ha->hardware_lock, flags);
4681
4682 /*
4683 * If the SCSI Reset Interrupt bit is set, clear it.
4684 * Otherwise, the Soft Reset won't work.
4685 */
4686 ctrl_status = readw(&ha->reg->ctrl_status);
4687 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4688 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4689
4690 /* Issue Soft Reset */
4691 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4692 readl(&ha->reg->ctrl_status);
4693
4694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4695 return QLA_SUCCESS;
4696 }
4697
4698 /**
4699 * qla4xxx_soft_reset - performs soft reset.
4700 * @ha: Pointer to host adapter structure.
4701 **/
qla4xxx_soft_reset(struct scsi_qla_host * ha)4702 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4703 {
4704 uint32_t max_wait_time;
4705 unsigned long flags = 0;
4706 int status;
4707 uint32_t ctrl_status;
4708
4709 status = qla4xxx_hw_reset(ha);
4710 if (status != QLA_SUCCESS)
4711 return status;
4712
4713 status = QLA_ERROR;
4714 /* Wait until the Network Reset Intr bit is cleared */
4715 max_wait_time = RESET_INTR_TOV;
4716 do {
4717 spin_lock_irqsave(&ha->hardware_lock, flags);
4718 ctrl_status = readw(&ha->reg->ctrl_status);
4719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4720
4721 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4722 break;
4723
4724 msleep(1000);
4725 } while ((--max_wait_time));
4726
4727 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4728 DEBUG2(printk(KERN_WARNING
4729 "scsi%ld: Network Reset Intr not cleared by "
4730 "Network function, clearing it now!\n",
4731 ha->host_no));
4732 spin_lock_irqsave(&ha->hardware_lock, flags);
4733 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4734 readl(&ha->reg->ctrl_status);
4735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4736 }
4737
4738 /* Wait until the firmware tells us the Soft Reset is done */
4739 max_wait_time = SOFT_RESET_TOV;
4740 do {
4741 spin_lock_irqsave(&ha->hardware_lock, flags);
4742 ctrl_status = readw(&ha->reg->ctrl_status);
4743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4744
4745 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4746 status = QLA_SUCCESS;
4747 break;
4748 }
4749
4750 msleep(1000);
4751 } while ((--max_wait_time));
4752
4753 /*
4754 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4755 * after the soft reset has taken place.
4756 */
4757 spin_lock_irqsave(&ha->hardware_lock, flags);
4758 ctrl_status = readw(&ha->reg->ctrl_status);
4759 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4760 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4761 readl(&ha->reg->ctrl_status);
4762 }
4763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4764
4765 /* If soft reset fails then most probably the bios on other
4766 * function is also enabled.
4767 * Since the initialization is sequential the other fn
4768 * wont be able to acknowledge the soft reset.
4769 * Issue a force soft reset to workaround this scenario.
4770 */
4771 if (max_wait_time == 0) {
4772 /* Issue Force Soft Reset */
4773 spin_lock_irqsave(&ha->hardware_lock, flags);
4774 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4775 readl(&ha->reg->ctrl_status);
4776 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4777 /* Wait until the firmware tells us the Soft Reset is done */
4778 max_wait_time = SOFT_RESET_TOV;
4779 do {
4780 spin_lock_irqsave(&ha->hardware_lock, flags);
4781 ctrl_status = readw(&ha->reg->ctrl_status);
4782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4783
4784 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4785 status = QLA_SUCCESS;
4786 break;
4787 }
4788
4789 msleep(1000);
4790 } while ((--max_wait_time));
4791 }
4792
4793 return status;
4794 }
4795
4796 /**
4797 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4798 * @ha: Pointer to host adapter structure.
4799 * @res: returned scsi status
4800 *
4801 * This routine is called just prior to a HARD RESET to return all
4802 * outstanding commands back to the Operating System.
4803 * Caller should make sure that the following locks are released
4804 * before this calling routine: Hardware lock, and io_request_lock.
4805 **/
qla4xxx_abort_active_cmds(struct scsi_qla_host * ha,int res)4806 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4807 {
4808 struct srb *srb;
4809 int i;
4810 unsigned long flags;
4811
4812 spin_lock_irqsave(&ha->hardware_lock, flags);
4813 for (i = 0; i < ha->host->can_queue; i++) {
4814 srb = qla4xxx_del_from_active_array(ha, i);
4815 if (srb != NULL) {
4816 srb->cmd->result = res;
4817 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4818 }
4819 }
4820 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4821 }
4822
qla4xxx_dead_adapter_cleanup(struct scsi_qla_host * ha)4823 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4824 {
4825 clear_bit(AF_ONLINE, &ha->flags);
4826
4827 /* Disable the board */
4828 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4829
4830 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4831 qla4xxx_mark_all_devices_missing(ha);
4832 clear_bit(AF_INIT_DONE, &ha->flags);
4833 }
4834
qla4xxx_fail_session(struct iscsi_cls_session * cls_session)4835 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4836 {
4837 struct iscsi_session *sess;
4838 struct ddb_entry *ddb_entry;
4839
4840 sess = cls_session->dd_data;
4841 ddb_entry = sess->dd_data;
4842 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4843
4844 if (ddb_entry->ddb_type == FLASH_DDB)
4845 iscsi_block_session(ddb_entry->sess);
4846 else
4847 iscsi_session_failure(cls_session->dd_data,
4848 ISCSI_ERR_CONN_FAILED);
4849 }
4850
4851 /**
4852 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4853 * @ha: Pointer to host adapter structure.
4854 **/
qla4xxx_recover_adapter(struct scsi_qla_host * ha)4855 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4856 {
4857 int status = QLA_ERROR;
4858 uint8_t reset_chip = 0;
4859 uint32_t dev_state;
4860 unsigned long wait;
4861
4862 /* Stall incoming I/O until we are done */
4863 scsi_block_requests(ha->host);
4864 clear_bit(AF_ONLINE, &ha->flags);
4865 clear_bit(AF_LINK_UP, &ha->flags);
4866
4867 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4868
4869 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4870
4871 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4872 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4873 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4874 __func__);
4875 /* disable pause frame for ISP83xx */
4876 qla4_83xx_disable_pause(ha);
4877 }
4878
4879 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4880
4881 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4882 reset_chip = 1;
4883
4884 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4885 * do not reset adapter, jump to initialize_adapter */
4886 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4887 status = QLA_SUCCESS;
4888 goto recover_ha_init_adapter;
4889 }
4890
4891 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4892 * from eh_host_reset or ioctl module */
4893 if (is_qla80XX(ha) && !reset_chip &&
4894 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4895
4896 DEBUG2(ql4_printk(KERN_INFO, ha,
4897 "scsi%ld: %s - Performing stop_firmware...\n",
4898 ha->host_no, __func__));
4899 status = ha->isp_ops->reset_firmware(ha);
4900 if (status == QLA_SUCCESS) {
4901 ha->isp_ops->disable_intrs(ha);
4902 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4903 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4904 } else {
4905 /* If the stop_firmware fails then
4906 * reset the entire chip */
4907 reset_chip = 1;
4908 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4909 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4910 }
4911 }
4912
4913 /* Issue full chip reset if recovering from a catastrophic error,
4914 * or if stop_firmware fails for ISP-8xxx.
4915 * This is the default case for ISP-4xxx */
4916 if (is_qla40XX(ha) || reset_chip) {
4917 if (is_qla40XX(ha))
4918 goto chip_reset;
4919
4920 /* Check if 8XXX firmware is alive or not
4921 * We may have arrived here from NEED_RESET
4922 * detection only */
4923 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4924 goto chip_reset;
4925
4926 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4927 while (time_before(jiffies, wait)) {
4928 if (qla4_8xxx_check_fw_alive(ha)) {
4929 qla4xxx_mailbox_premature_completion(ha);
4930 break;
4931 }
4932
4933 set_current_state(TASK_UNINTERRUPTIBLE);
4934 schedule_timeout(HZ);
4935 }
4936 chip_reset:
4937 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4938 qla4xxx_cmd_wait(ha);
4939
4940 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4941 DEBUG2(ql4_printk(KERN_INFO, ha,
4942 "scsi%ld: %s - Performing chip reset..\n",
4943 ha->host_no, __func__));
4944 status = ha->isp_ops->reset_chip(ha);
4945 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4946 }
4947
4948 /* Flush any pending ddb changed AENs */
4949 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4950
4951 recover_ha_init_adapter:
4952 /* Upon successful firmware/chip reset, re-initialize the adapter */
4953 if (status == QLA_SUCCESS) {
4954 /* For ISP-4xxx, force function 1 to always initialize
4955 * before function 3 to prevent both funcions from
4956 * stepping on top of the other */
4957 if (is_qla40XX(ha) && (ha->mac_index == 3))
4958 ssleep(6);
4959
4960 /* NOTE: AF_ONLINE flag set upon successful completion of
4961 * qla4xxx_initialize_adapter */
4962 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4963 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4964 status = qla4_8xxx_check_init_adapter_retry(ha);
4965 if (status == QLA_ERROR) {
4966 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4967 ha->host_no, __func__);
4968 qla4xxx_dead_adapter_cleanup(ha);
4969 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4970 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4971 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4972 &ha->dpc_flags);
4973 goto exit_recover;
4974 }
4975 }
4976 }
4977
4978 /* Retry failed adapter initialization, if necessary
4979 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4980 * case to prevent ping-pong resets between functions */
4981 if (!test_bit(AF_ONLINE, &ha->flags) &&
4982 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4983 /* Adapter initialization failed, see if we can retry
4984 * resetting the ha.
4985 * Since we don't want to block the DPC for too long
4986 * with multiple resets in the same thread,
4987 * utilize DPC to retry */
4988 if (is_qla80XX(ha)) {
4989 ha->isp_ops->idc_lock(ha);
4990 dev_state = qla4_8xxx_rd_direct(ha,
4991 QLA8XXX_CRB_DEV_STATE);
4992 ha->isp_ops->idc_unlock(ha);
4993 if (dev_state == QLA8XXX_DEV_FAILED) {
4994 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4995 "recover adapter. H/W is in Failed "
4996 "state\n", __func__);
4997 qla4xxx_dead_adapter_cleanup(ha);
4998 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4999 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5000 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5001 &ha->dpc_flags);
5002 status = QLA_ERROR;
5003
5004 goto exit_recover;
5005 }
5006 }
5007
5008 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
5009 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
5010 DEBUG2(printk("scsi%ld: recover adapter - retrying "
5011 "(%d) more times\n", ha->host_no,
5012 ha->retry_reset_ha_cnt));
5013 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5014 status = QLA_ERROR;
5015 } else {
5016 if (ha->retry_reset_ha_cnt > 0) {
5017 /* Schedule another Reset HA--DPC will retry */
5018 ha->retry_reset_ha_cnt--;
5019 DEBUG2(printk("scsi%ld: recover adapter - "
5020 "retry remaining %d\n",
5021 ha->host_no,
5022 ha->retry_reset_ha_cnt));
5023 status = QLA_ERROR;
5024 }
5025
5026 if (ha->retry_reset_ha_cnt == 0) {
5027 /* Recover adapter retries have been exhausted.
5028 * Adapter DEAD */
5029 DEBUG2(printk("scsi%ld: recover adapter "
5030 "failed - board disabled\n",
5031 ha->host_no));
5032 qla4xxx_dead_adapter_cleanup(ha);
5033 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5034 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5035 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5036 &ha->dpc_flags);
5037 status = QLA_ERROR;
5038 }
5039 }
5040 } else {
5041 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5042 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5043 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5044 }
5045
5046 exit_recover:
5047 ha->adapter_error_count++;
5048
5049 if (test_bit(AF_ONLINE, &ha->flags))
5050 ha->isp_ops->enable_intrs(ha);
5051
5052 scsi_unblock_requests(ha->host);
5053
5054 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5055 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5056 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5057
5058 return status;
5059 }
5060
qla4xxx_relogin_devices(struct iscsi_cls_session * cls_session)5061 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5062 {
5063 struct iscsi_session *sess;
5064 struct ddb_entry *ddb_entry;
5065 struct scsi_qla_host *ha;
5066
5067 sess = cls_session->dd_data;
5068 ddb_entry = sess->dd_data;
5069 ha = ddb_entry->ha;
5070 if (!iscsi_is_session_online(cls_session)) {
5071 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5072 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5073 " unblock session\n", ha->host_no, __func__,
5074 ddb_entry->fw_ddb_index);
5075 iscsi_unblock_session(ddb_entry->sess);
5076 } else {
5077 /* Trigger relogin */
5078 if (ddb_entry->ddb_type == FLASH_DDB) {
5079 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5080 test_bit(DF_DISABLE_RELOGIN,
5081 &ddb_entry->flags)))
5082 qla4xxx_arm_relogin_timer(ddb_entry);
5083 } else
5084 iscsi_session_failure(cls_session->dd_data,
5085 ISCSI_ERR_CONN_FAILED);
5086 }
5087 }
5088 }
5089
qla4xxx_unblock_flash_ddb(struct iscsi_cls_session * cls_session)5090 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5091 {
5092 struct iscsi_session *sess;
5093 struct ddb_entry *ddb_entry;
5094 struct scsi_qla_host *ha;
5095
5096 sess = cls_session->dd_data;
5097 ddb_entry = sess->dd_data;
5098 ha = ddb_entry->ha;
5099 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5100 " unblock session\n", ha->host_no, __func__,
5101 ddb_entry->fw_ddb_index);
5102
5103 iscsi_unblock_session(ddb_entry->sess);
5104
5105 /* Start scan target */
5106 if (test_bit(AF_ONLINE, &ha->flags)) {
5107 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5108 " start scan\n", ha->host_no, __func__,
5109 ddb_entry->fw_ddb_index);
5110 queue_work(ddb_entry->sess->workq, &ddb_entry->sess->scan_work);
5111 }
5112 return QLA_SUCCESS;
5113 }
5114
qla4xxx_unblock_ddb(struct iscsi_cls_session * cls_session)5115 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5116 {
5117 struct iscsi_session *sess;
5118 struct ddb_entry *ddb_entry;
5119 struct scsi_qla_host *ha;
5120 int status = QLA_SUCCESS;
5121
5122 sess = cls_session->dd_data;
5123 ddb_entry = sess->dd_data;
5124 ha = ddb_entry->ha;
5125 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5126 " unblock user space session\n", ha->host_no, __func__,
5127 ddb_entry->fw_ddb_index);
5128
5129 if (!iscsi_is_session_online(cls_session)) {
5130 iscsi_conn_start(ddb_entry->conn);
5131 iscsi_conn_login_event(ddb_entry->conn,
5132 ISCSI_CONN_STATE_LOGGED_IN);
5133 } else {
5134 ql4_printk(KERN_INFO, ha,
5135 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5136 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5137 cls_session->sid);
5138 status = QLA_ERROR;
5139 }
5140
5141 return status;
5142 }
5143
qla4xxx_relogin_all_devices(struct scsi_qla_host * ha)5144 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5145 {
5146 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5147 }
5148
qla4xxx_relogin_flash_ddb(struct iscsi_cls_session * cls_sess)5149 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5150 {
5151 uint16_t relogin_timer;
5152 struct iscsi_session *sess;
5153 struct ddb_entry *ddb_entry;
5154 struct scsi_qla_host *ha;
5155
5156 sess = cls_sess->dd_data;
5157 ddb_entry = sess->dd_data;
5158 ha = ddb_entry->ha;
5159
5160 relogin_timer = max(ddb_entry->default_relogin_timeout,
5161 (uint16_t)RELOGIN_TOV);
5162 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5163
5164 DEBUG2(ql4_printk(KERN_INFO, ha,
5165 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5166 ddb_entry->fw_ddb_index, relogin_timer));
5167
5168 qla4xxx_login_flash_ddb(cls_sess);
5169 }
5170
qla4xxx_dpc_relogin(struct iscsi_cls_session * cls_sess)5171 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5172 {
5173 struct iscsi_session *sess;
5174 struct ddb_entry *ddb_entry;
5175 struct scsi_qla_host *ha;
5176
5177 sess = cls_sess->dd_data;
5178 ddb_entry = sess->dd_data;
5179 ha = ddb_entry->ha;
5180
5181 if (!(ddb_entry->ddb_type == FLASH_DDB))
5182 return;
5183
5184 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5185 return;
5186
5187 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5188 !iscsi_is_session_online(cls_sess)) {
5189 DEBUG2(ql4_printk(KERN_INFO, ha,
5190 "relogin issued\n"));
5191 qla4xxx_relogin_flash_ddb(cls_sess);
5192 }
5193 }
5194
qla4xxx_wake_dpc(struct scsi_qla_host * ha)5195 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5196 {
5197 if (ha->dpc_thread)
5198 queue_work(ha->dpc_thread, &ha->dpc_work);
5199 }
5200
5201 static struct qla4_work_evt *
qla4xxx_alloc_work(struct scsi_qla_host * ha,uint32_t data_size,enum qla4_work_type type)5202 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5203 enum qla4_work_type type)
5204 {
5205 struct qla4_work_evt *e;
5206 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5207
5208 e = kzalloc(size, GFP_ATOMIC);
5209 if (!e)
5210 return NULL;
5211
5212 INIT_LIST_HEAD(&e->list);
5213 e->type = type;
5214 return e;
5215 }
5216
qla4xxx_post_work(struct scsi_qla_host * ha,struct qla4_work_evt * e)5217 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5218 struct qla4_work_evt *e)
5219 {
5220 unsigned long flags;
5221
5222 spin_lock_irqsave(&ha->work_lock, flags);
5223 list_add_tail(&e->list, &ha->work_list);
5224 spin_unlock_irqrestore(&ha->work_lock, flags);
5225 qla4xxx_wake_dpc(ha);
5226 }
5227
qla4xxx_post_aen_work(struct scsi_qla_host * ha,enum iscsi_host_event_code aen_code,uint32_t data_size,uint8_t * data)5228 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5229 enum iscsi_host_event_code aen_code,
5230 uint32_t data_size, uint8_t *data)
5231 {
5232 struct qla4_work_evt *e;
5233
5234 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5235 if (!e)
5236 return QLA_ERROR;
5237
5238 e->u.aen.code = aen_code;
5239 e->u.aen.data_size = data_size;
5240 memcpy(e->u.aen.data, data, data_size);
5241
5242 qla4xxx_post_work(ha, e);
5243
5244 return QLA_SUCCESS;
5245 }
5246
qla4xxx_post_ping_evt_work(struct scsi_qla_host * ha,uint32_t status,uint32_t pid,uint32_t data_size,uint8_t * data)5247 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5248 uint32_t status, uint32_t pid,
5249 uint32_t data_size, uint8_t *data)
5250 {
5251 struct qla4_work_evt *e;
5252
5253 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5254 if (!e)
5255 return QLA_ERROR;
5256
5257 e->u.ping.status = status;
5258 e->u.ping.pid = pid;
5259 e->u.ping.data_size = data_size;
5260 memcpy(e->u.ping.data, data, data_size);
5261
5262 qla4xxx_post_work(ha, e);
5263
5264 return QLA_SUCCESS;
5265 }
5266
qla4xxx_do_work(struct scsi_qla_host * ha)5267 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5268 {
5269 struct qla4_work_evt *e, *tmp;
5270 unsigned long flags;
5271 LIST_HEAD(work);
5272
5273 spin_lock_irqsave(&ha->work_lock, flags);
5274 list_splice_init(&ha->work_list, &work);
5275 spin_unlock_irqrestore(&ha->work_lock, flags);
5276
5277 list_for_each_entry_safe(e, tmp, &work, list) {
5278 list_del_init(&e->list);
5279
5280 switch (e->type) {
5281 case QLA4_EVENT_AEN:
5282 iscsi_post_host_event(ha->host_no,
5283 &qla4xxx_iscsi_transport,
5284 e->u.aen.code,
5285 e->u.aen.data_size,
5286 e->u.aen.data);
5287 break;
5288 case QLA4_EVENT_PING_STATUS:
5289 iscsi_ping_comp_event(ha->host_no,
5290 &qla4xxx_iscsi_transport,
5291 e->u.ping.status,
5292 e->u.ping.pid,
5293 e->u.ping.data_size,
5294 e->u.ping.data);
5295 break;
5296 default:
5297 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5298 "supported", e->type);
5299 }
5300 kfree(e);
5301 }
5302 }
5303
5304 /**
5305 * qla4xxx_do_dpc - dpc routine
5306 * @work: Context to obtain pointer to host adapter structure.
5307 *
5308 * This routine is a task that is schedule by the interrupt handler
5309 * to perform the background processing for interrupts. We put it
5310 * on a task queue that is consumed whenever the scheduler runs; that's
5311 * so you can do anything (i.e. put the process to sleep etc). In fact,
5312 * the mid-level tries to sleep when it reaches the driver threshold
5313 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5314 **/
qla4xxx_do_dpc(struct work_struct * work)5315 static void qla4xxx_do_dpc(struct work_struct *work)
5316 {
5317 struct scsi_qla_host *ha =
5318 container_of(work, struct scsi_qla_host, dpc_work);
5319 int status = QLA_ERROR;
5320
5321 DEBUG2(ql4_printk(KERN_INFO, ha,
5322 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5323 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5324
5325 /* Initialization not yet finished. Don't do anything yet. */
5326 if (!test_bit(AF_INIT_DONE, &ha->flags))
5327 return;
5328
5329 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5330 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5331 ha->host_no, __func__, ha->flags));
5332 return;
5333 }
5334
5335 /* post events to application */
5336 qla4xxx_do_work(ha);
5337
5338 if (is_qla80XX(ha)) {
5339 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5340 if (is_qla8032(ha) || is_qla8042(ha)) {
5341 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5342 __func__);
5343 /* disable pause frame for ISP83xx */
5344 qla4_83xx_disable_pause(ha);
5345 }
5346
5347 ha->isp_ops->idc_lock(ha);
5348 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5349 QLA8XXX_DEV_FAILED);
5350 ha->isp_ops->idc_unlock(ha);
5351 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5352 qla4_8xxx_device_state_handler(ha);
5353 }
5354
5355 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5356 if (is_qla8042(ha)) {
5357 if (ha->idc_info.info2 &
5358 ENABLE_INTERNAL_LOOPBACK) {
5359 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5360 __func__);
5361 status = qla4_84xx_config_acb(ha,
5362 ACB_CONFIG_DISABLE);
5363 if (status != QLA_SUCCESS) {
5364 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5365 __func__);
5366 }
5367 }
5368 }
5369 qla4_83xx_post_idc_ack(ha);
5370 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5371 }
5372
5373 if (is_qla8042(ha) &&
5374 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5375 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5376 __func__);
5377 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5378 QLA_SUCCESS) {
5379 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5380 __func__);
5381 }
5382 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5383 }
5384
5385 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5386 qla4_8xxx_need_qsnt_handler(ha);
5387 }
5388 }
5389
5390 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5391 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5392 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5393 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5394 if ((is_qla8022(ha) && ql4xdontresethba) ||
5395 ((is_qla8032(ha) || is_qla8042(ha)) &&
5396 qla4_83xx_idc_dontreset(ha))) {
5397 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5398 ha->host_no, __func__));
5399 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5400 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5401 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5402 goto dpc_post_reset_ha;
5403 }
5404 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5405 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5406 qla4xxx_recover_adapter(ha);
5407
5408 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5409 uint8_t wait_time = RESET_INTR_TOV;
5410
5411 while ((readw(&ha->reg->ctrl_status) &
5412 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5413 if (--wait_time == 0)
5414 break;
5415 msleep(1000);
5416 }
5417 if (wait_time == 0)
5418 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5419 "bit not cleared-- resetting\n",
5420 ha->host_no, __func__));
5421 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5422 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5423 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5424 status = qla4xxx_recover_adapter(ha);
5425 }
5426 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5427 if (status == QLA_SUCCESS)
5428 ha->isp_ops->enable_intrs(ha);
5429 }
5430 }
5431
5432 dpc_post_reset_ha:
5433 /* ---- process AEN? --- */
5434 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5435 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5436
5437 /* ---- Get DHCP IP Address? --- */
5438 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5439 qla4xxx_get_dhcp_ip_address(ha);
5440
5441 /* ---- relogin device? --- */
5442 if (adapter_up(ha) &&
5443 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5444 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5445 }
5446
5447 /* ---- link change? --- */
5448 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5449 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5450 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5451 /* ---- link down? --- */
5452 qla4xxx_mark_all_devices_missing(ha);
5453 } else {
5454 /* ---- link up? --- *
5455 * F/W will auto login to all devices ONLY ONCE after
5456 * link up during driver initialization and runtime
5457 * fatal error recovery. Therefore, the driver must
5458 * manually relogin to devices when recovering from
5459 * connection failures, logouts, expired KATO, etc. */
5460 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5461 qla4xxx_build_ddb_list(ha, ha->is_reset);
5462 iscsi_host_for_each_session(ha->host,
5463 qla4xxx_login_flash_ddb);
5464 } else
5465 qla4xxx_relogin_all_devices(ha);
5466 }
5467 }
5468 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5469 if (qla4xxx_sysfs_ddb_export(ha))
5470 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5471 __func__);
5472 }
5473 }
5474
5475 /**
5476 * qla4xxx_free_adapter - release the adapter
5477 * @ha: pointer to adapter structure
5478 **/
qla4xxx_free_adapter(struct scsi_qla_host * ha)5479 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5480 {
5481 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5482
5483 /* Turn-off interrupts on the card. */
5484 ha->isp_ops->disable_intrs(ha);
5485
5486 if (is_qla40XX(ha)) {
5487 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5488 &ha->reg->ctrl_status);
5489 readl(&ha->reg->ctrl_status);
5490 } else if (is_qla8022(ha)) {
5491 writel(0, &ha->qla4_82xx_reg->host_int);
5492 readl(&ha->qla4_82xx_reg->host_int);
5493 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5494 writel(0, &ha->qla4_83xx_reg->risc_intr);
5495 readl(&ha->qla4_83xx_reg->risc_intr);
5496 }
5497
5498 /* Remove timer thread, if present */
5499 if (ha->timer_active)
5500 qla4xxx_stop_timer(ha);
5501
5502 /* Kill the kernel thread for this host */
5503 if (ha->dpc_thread)
5504 destroy_workqueue(ha->dpc_thread);
5505
5506 /* Kill the kernel thread for this host */
5507 if (ha->task_wq)
5508 destroy_workqueue(ha->task_wq);
5509
5510 /* Put firmware in known state */
5511 ha->isp_ops->reset_firmware(ha);
5512
5513 if (is_qla80XX(ha)) {
5514 ha->isp_ops->idc_lock(ha);
5515 qla4_8xxx_clear_drv_active(ha);
5516 ha->isp_ops->idc_unlock(ha);
5517 }
5518
5519 /* Detach interrupts */
5520 qla4xxx_free_irqs(ha);
5521
5522 /* free extra memory */
5523 qla4xxx_mem_free(ha);
5524 }
5525
qla4_8xxx_iospace_config(struct scsi_qla_host * ha)5526 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5527 {
5528 int status = 0;
5529 unsigned long mem_base, mem_len;
5530 struct pci_dev *pdev = ha->pdev;
5531
5532 status = pci_request_regions(pdev, DRIVER_NAME);
5533 if (status) {
5534 printk(KERN_WARNING
5535 "scsi(%ld) Failed to reserve PIO regions (%s) "
5536 "status=%d\n", ha->host_no, pci_name(pdev), status);
5537 goto iospace_error_exit;
5538 }
5539
5540 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5541 __func__, pdev->revision));
5542 ha->revision_id = pdev->revision;
5543
5544 /* remap phys address */
5545 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5546 mem_len = pci_resource_len(pdev, 0);
5547 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5548 __func__, mem_base, mem_len));
5549
5550 /* mapping of pcibase pointer */
5551 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5552 if (!ha->nx_pcibase) {
5553 printk(KERN_ERR
5554 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5555 pci_release_regions(ha->pdev);
5556 goto iospace_error_exit;
5557 }
5558
5559 /* Mapping of IO base pointer, door bell read and write pointer */
5560
5561 /* mapping of IO base pointer */
5562 if (is_qla8022(ha)) {
5563 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5564 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5565 (ha->pdev->devfn << 11));
5566 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5567 QLA82XX_CAM_RAM_DB2);
5568 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5569 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5570 ((uint8_t *)ha->nx_pcibase);
5571 }
5572
5573 return 0;
5574 iospace_error_exit:
5575 return -ENOMEM;
5576 }
5577
5578 /***
5579 * qla4xxx_iospace_config - maps registers
5580 * @ha: pointer to adapter structure
5581 *
5582 * This routines maps HBA's registers from the pci address space
5583 * into the kernel virtual address space for memory mapped i/o.
5584 **/
qla4xxx_iospace_config(struct scsi_qla_host * ha)5585 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5586 {
5587 unsigned long pio, pio_len, pio_flags;
5588 unsigned long mmio, mmio_len, mmio_flags;
5589
5590 pio = pci_resource_start(ha->pdev, 0);
5591 pio_len = pci_resource_len(ha->pdev, 0);
5592 pio_flags = pci_resource_flags(ha->pdev, 0);
5593 if (pio_flags & IORESOURCE_IO) {
5594 if (pio_len < MIN_IOBASE_LEN) {
5595 ql4_printk(KERN_WARNING, ha,
5596 "Invalid PCI I/O region size\n");
5597 pio = 0;
5598 }
5599 } else {
5600 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5601 pio = 0;
5602 }
5603
5604 /* Use MMIO operations for all accesses. */
5605 mmio = pci_resource_start(ha->pdev, 1);
5606 mmio_len = pci_resource_len(ha->pdev, 1);
5607 mmio_flags = pci_resource_flags(ha->pdev, 1);
5608
5609 if (!(mmio_flags & IORESOURCE_MEM)) {
5610 ql4_printk(KERN_ERR, ha,
5611 "region #0 not an MMIO resource, aborting\n");
5612
5613 goto iospace_error_exit;
5614 }
5615
5616 if (mmio_len < MIN_IOBASE_LEN) {
5617 ql4_printk(KERN_ERR, ha,
5618 "Invalid PCI mem region size, aborting\n");
5619 goto iospace_error_exit;
5620 }
5621
5622 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5623 ql4_printk(KERN_WARNING, ha,
5624 "Failed to reserve PIO/MMIO regions\n");
5625
5626 goto iospace_error_exit;
5627 }
5628
5629 ha->pio_address = pio;
5630 ha->pio_length = pio_len;
5631 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5632 if (!ha->reg) {
5633 ql4_printk(KERN_ERR, ha,
5634 "cannot remap MMIO, aborting\n");
5635
5636 goto iospace_error_exit;
5637 }
5638
5639 return 0;
5640
5641 iospace_error_exit:
5642 return -ENOMEM;
5643 }
5644
5645 static struct isp_operations qla4xxx_isp_ops = {
5646 .iospace_config = qla4xxx_iospace_config,
5647 .pci_config = qla4xxx_pci_config,
5648 .disable_intrs = qla4xxx_disable_intrs,
5649 .enable_intrs = qla4xxx_enable_intrs,
5650 .start_firmware = qla4xxx_start_firmware,
5651 .intr_handler = qla4xxx_intr_handler,
5652 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5653 .reset_chip = qla4xxx_soft_reset,
5654 .reset_firmware = qla4xxx_hw_reset,
5655 .queue_iocb = qla4xxx_queue_iocb,
5656 .complete_iocb = qla4xxx_complete_iocb,
5657 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5658 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5659 .get_sys_info = qla4xxx_get_sys_info,
5660 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5661 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5662 };
5663
5664 static struct isp_operations qla4_82xx_isp_ops = {
5665 .iospace_config = qla4_8xxx_iospace_config,
5666 .pci_config = qla4_8xxx_pci_config,
5667 .disable_intrs = qla4_82xx_disable_intrs,
5668 .enable_intrs = qla4_82xx_enable_intrs,
5669 .start_firmware = qla4_8xxx_load_risc,
5670 .restart_firmware = qla4_82xx_try_start_fw,
5671 .intr_handler = qla4_82xx_intr_handler,
5672 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5673 .need_reset = qla4_8xxx_need_reset,
5674 .reset_chip = qla4_82xx_isp_reset,
5675 .reset_firmware = qla4_8xxx_stop_firmware,
5676 .queue_iocb = qla4_82xx_queue_iocb,
5677 .complete_iocb = qla4_82xx_complete_iocb,
5678 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5679 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5680 .get_sys_info = qla4_8xxx_get_sys_info,
5681 .rd_reg_direct = qla4_82xx_rd_32,
5682 .wr_reg_direct = qla4_82xx_wr_32,
5683 .rd_reg_indirect = qla4_82xx_md_rd_32,
5684 .wr_reg_indirect = qla4_82xx_md_wr_32,
5685 .idc_lock = qla4_82xx_idc_lock,
5686 .idc_unlock = qla4_82xx_idc_unlock,
5687 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5688 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5689 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5690 };
5691
5692 static struct isp_operations qla4_83xx_isp_ops = {
5693 .iospace_config = qla4_8xxx_iospace_config,
5694 .pci_config = qla4_8xxx_pci_config,
5695 .disable_intrs = qla4_83xx_disable_intrs,
5696 .enable_intrs = qla4_83xx_enable_intrs,
5697 .start_firmware = qla4_8xxx_load_risc,
5698 .restart_firmware = qla4_83xx_start_firmware,
5699 .intr_handler = qla4_83xx_intr_handler,
5700 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5701 .need_reset = qla4_8xxx_need_reset,
5702 .reset_chip = qla4_83xx_isp_reset,
5703 .reset_firmware = qla4_8xxx_stop_firmware,
5704 .queue_iocb = qla4_83xx_queue_iocb,
5705 .complete_iocb = qla4_83xx_complete_iocb,
5706 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5707 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5708 .get_sys_info = qla4_8xxx_get_sys_info,
5709 .rd_reg_direct = qla4_83xx_rd_reg,
5710 .wr_reg_direct = qla4_83xx_wr_reg,
5711 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5712 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5713 .idc_lock = qla4_83xx_drv_lock,
5714 .idc_unlock = qla4_83xx_drv_unlock,
5715 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5716 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5717 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5718 };
5719
qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host * ha)5720 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5721 {
5722 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5723 }
5724
qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host * ha)5725 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5726 {
5727 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5728 }
5729
qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host * ha)5730 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5731 {
5732 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5733 }
5734
qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host * ha)5735 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5736 {
5737 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5738 }
5739
qla4xxx_show_boot_eth_info(void * data,int type,char * buf)5740 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5741 {
5742 struct scsi_qla_host *ha = data;
5743 char *str = buf;
5744 int rc;
5745
5746 switch (type) {
5747 case ISCSI_BOOT_ETH_FLAGS:
5748 rc = sprintf(str, "%d\n", (char)SYSFS_FLAG_FW_SEL_BOOT);
5749 break;
5750 case ISCSI_BOOT_ETH_INDEX:
5751 rc = sprintf(str, "0\n");
5752 break;
5753 case ISCSI_BOOT_ETH_MAC:
5754 rc = sysfs_format_mac(str, ha->my_mac,
5755 MAC_ADDR_LEN);
5756 break;
5757 default:
5758 rc = -ENOSYS;
5759 break;
5760 }
5761 return rc;
5762 }
5763
qla4xxx_eth_get_attr_visibility(void * data,int type)5764 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5765 {
5766 int rc;
5767
5768 switch (type) {
5769 case ISCSI_BOOT_ETH_FLAGS:
5770 case ISCSI_BOOT_ETH_MAC:
5771 case ISCSI_BOOT_ETH_INDEX:
5772 rc = S_IRUGO;
5773 break;
5774 default:
5775 rc = 0;
5776 break;
5777 }
5778 return rc;
5779 }
5780
qla4xxx_show_boot_ini_info(void * data,int type,char * buf)5781 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5782 {
5783 struct scsi_qla_host *ha = data;
5784 char *str = buf;
5785 int rc;
5786
5787 switch (type) {
5788 case ISCSI_BOOT_INI_INITIATOR_NAME:
5789 rc = sprintf(str, "%s\n", ha->name_string);
5790 break;
5791 default:
5792 rc = -ENOSYS;
5793 break;
5794 }
5795 return rc;
5796 }
5797
qla4xxx_ini_get_attr_visibility(void * data,int type)5798 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5799 {
5800 int rc;
5801
5802 switch (type) {
5803 case ISCSI_BOOT_INI_INITIATOR_NAME:
5804 rc = S_IRUGO;
5805 break;
5806 default:
5807 rc = 0;
5808 break;
5809 }
5810 return rc;
5811 }
5812
5813 static ssize_t
qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info * boot_sess,int type,char * buf)5814 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5815 char *buf)
5816 {
5817 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5818 char *str = buf;
5819 int rc;
5820
5821 switch (type) {
5822 case ISCSI_BOOT_TGT_NAME:
5823 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5824 break;
5825 case ISCSI_BOOT_TGT_IP_ADDR:
5826 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5827 rc = sprintf(buf, "%pI4\n",
5828 &boot_conn->dest_ipaddr.ip_address);
5829 else
5830 rc = sprintf(str, "%pI6\n",
5831 &boot_conn->dest_ipaddr.ip_address);
5832 break;
5833 case ISCSI_BOOT_TGT_PORT:
5834 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5835 break;
5836 case ISCSI_BOOT_TGT_CHAP_NAME:
5837 rc = sprintf(str, "%.*s\n",
5838 boot_conn->chap.target_chap_name_length,
5839 (char *)&boot_conn->chap.target_chap_name);
5840 break;
5841 case ISCSI_BOOT_TGT_CHAP_SECRET:
5842 rc = sprintf(str, "%.*s\n",
5843 boot_conn->chap.target_secret_length,
5844 (char *)&boot_conn->chap.target_secret);
5845 break;
5846 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5847 rc = sprintf(str, "%.*s\n",
5848 boot_conn->chap.intr_chap_name_length,
5849 (char *)&boot_conn->chap.intr_chap_name);
5850 break;
5851 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5852 rc = sprintf(str, "%.*s\n",
5853 boot_conn->chap.intr_secret_length,
5854 (char *)&boot_conn->chap.intr_secret);
5855 break;
5856 case ISCSI_BOOT_TGT_FLAGS:
5857 rc = sprintf(str, "%d\n", (char)SYSFS_FLAG_FW_SEL_BOOT);
5858 break;
5859 case ISCSI_BOOT_TGT_NIC_ASSOC:
5860 rc = sprintf(str, "0\n");
5861 break;
5862 default:
5863 rc = -ENOSYS;
5864 break;
5865 }
5866 return rc;
5867 }
5868
qla4xxx_show_boot_tgt_pri_info(void * data,int type,char * buf)5869 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5870 {
5871 struct scsi_qla_host *ha = data;
5872 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5873
5874 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5875 }
5876
qla4xxx_show_boot_tgt_sec_info(void * data,int type,char * buf)5877 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5878 {
5879 struct scsi_qla_host *ha = data;
5880 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5881
5882 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5883 }
5884
qla4xxx_tgt_get_attr_visibility(void * data,int type)5885 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5886 {
5887 int rc;
5888
5889 switch (type) {
5890 case ISCSI_BOOT_TGT_NAME:
5891 case ISCSI_BOOT_TGT_IP_ADDR:
5892 case ISCSI_BOOT_TGT_PORT:
5893 case ISCSI_BOOT_TGT_CHAP_NAME:
5894 case ISCSI_BOOT_TGT_CHAP_SECRET:
5895 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5896 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5897 case ISCSI_BOOT_TGT_NIC_ASSOC:
5898 case ISCSI_BOOT_TGT_FLAGS:
5899 rc = S_IRUGO;
5900 break;
5901 default:
5902 rc = 0;
5903 break;
5904 }
5905 return rc;
5906 }
5907
qla4xxx_boot_release(void * data)5908 static void qla4xxx_boot_release(void *data)
5909 {
5910 struct scsi_qla_host *ha = data;
5911
5912 scsi_host_put(ha->host);
5913 }
5914
get_fw_boot_info(struct scsi_qla_host * ha,uint16_t ddb_index[])5915 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5916 {
5917 dma_addr_t buf_dma;
5918 uint32_t addr, pri_addr, sec_addr;
5919 uint32_t offset;
5920 uint16_t func_num;
5921 uint8_t val;
5922 uint8_t *buf = NULL;
5923 size_t size = 13 * sizeof(uint8_t);
5924 int ret = QLA_SUCCESS;
5925
5926 func_num = PCI_FUNC(ha->pdev->devfn);
5927
5928 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5929 __func__, ha->pdev->device, func_num);
5930
5931 if (is_qla40XX(ha)) {
5932 if (func_num == 1) {
5933 addr = NVRAM_PORT0_BOOT_MODE;
5934 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5935 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5936 } else if (func_num == 3) {
5937 addr = NVRAM_PORT1_BOOT_MODE;
5938 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5939 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5940 } else {
5941 ret = QLA_ERROR;
5942 goto exit_boot_info;
5943 }
5944
5945 /* Check Boot Mode */
5946 val = rd_nvram_byte(ha, addr);
5947 if (!(val & 0x07)) {
5948 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5949 "options : 0x%x\n", __func__, val));
5950 ret = QLA_ERROR;
5951 goto exit_boot_info;
5952 }
5953
5954 /* get primary valid target index */
5955 val = rd_nvram_byte(ha, pri_addr);
5956 if (val & BIT_7)
5957 ddb_index[0] = (val & 0x7f);
5958
5959 /* get secondary valid target index */
5960 val = rd_nvram_byte(ha, sec_addr);
5961 if (val & BIT_7)
5962 ddb_index[1] = (val & 0x7f);
5963 goto exit_boot_info;
5964 } else if (is_qla80XX(ha)) {
5965 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5966 &buf_dma, GFP_KERNEL);
5967 if (!buf) {
5968 DEBUG2(ql4_printk(KERN_ERR, ha,
5969 "%s: Unable to allocate dma buffer\n",
5970 __func__));
5971 ret = QLA_ERROR;
5972 goto exit_boot_info;
5973 }
5974
5975 if (ha->port_num == 0)
5976 offset = BOOT_PARAM_OFFSET_PORT0;
5977 else if (ha->port_num == 1)
5978 offset = BOOT_PARAM_OFFSET_PORT1;
5979 else {
5980 ret = QLA_ERROR;
5981 goto exit_boot_info_free;
5982 }
5983 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5984 offset;
5985 if (qla4xxx_get_flash(ha, buf_dma, addr,
5986 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5987 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5988 " failed\n", ha->host_no, __func__));
5989 ret = QLA_ERROR;
5990 goto exit_boot_info_free;
5991 }
5992 /* Check Boot Mode */
5993 if (!(buf[1] & 0x07)) {
5994 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5995 " : 0x%x\n", buf[1]));
5996 ret = QLA_ERROR;
5997 goto exit_boot_info_free;
5998 }
5999
6000 /* get primary valid target index */
6001 if (buf[2] & BIT_7)
6002 ddb_index[0] = buf[2] & 0x7f;
6003
6004 /* get secondary valid target index */
6005 if (buf[11] & BIT_7)
6006 ddb_index[1] = buf[11] & 0x7f;
6007 } else {
6008 ret = QLA_ERROR;
6009 goto exit_boot_info;
6010 }
6011
6012 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
6013 " target ID %d\n", __func__, ddb_index[0],
6014 ddb_index[1]));
6015
6016 exit_boot_info_free:
6017 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6018 exit_boot_info:
6019 ha->pri_ddb_idx = ddb_index[0];
6020 ha->sec_ddb_idx = ddb_index[1];
6021 return ret;
6022 }
6023
6024 /**
6025 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6026 * @ha: pointer to adapter structure
6027 * @username: CHAP username to be returned
6028 * @password: CHAP password to be returned
6029 *
6030 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6031 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6032 * So from the CHAP cache find the first BIDI CHAP entry and set it
6033 * to the boot record in sysfs.
6034 **/
qla4xxx_get_bidi_chap(struct scsi_qla_host * ha,char * username,char * password)6035 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6036 char *password)
6037 {
6038 int i, ret = -EINVAL;
6039 int max_chap_entries = 0;
6040 struct ql4_chap_table *chap_table;
6041
6042 if (is_qla80XX(ha))
6043 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6044 sizeof(struct ql4_chap_table);
6045 else
6046 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6047
6048 if (!ha->chap_list) {
6049 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6050 return ret;
6051 }
6052
6053 mutex_lock(&ha->chap_sem);
6054 for (i = 0; i < max_chap_entries; i++) {
6055 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6056 if (chap_table->cookie !=
6057 cpu_to_le16(CHAP_VALID_COOKIE)) {
6058 continue;
6059 }
6060
6061 if (chap_table->flags & BIT_7) /* local */
6062 continue;
6063
6064 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6065 continue;
6066
6067 strscpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6068 strscpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6069 ret = 0;
6070 break;
6071 }
6072 mutex_unlock(&ha->chap_sem);
6073
6074 return ret;
6075 }
6076
6077
qla4xxx_get_boot_target(struct scsi_qla_host * ha,struct ql4_boot_session_info * boot_sess,uint16_t ddb_index)6078 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6079 struct ql4_boot_session_info *boot_sess,
6080 uint16_t ddb_index)
6081 {
6082 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6083 struct dev_db_entry *fw_ddb_entry;
6084 dma_addr_t fw_ddb_entry_dma;
6085 uint16_t idx;
6086 uint16_t options;
6087 int ret = QLA_SUCCESS;
6088
6089 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6090 &fw_ddb_entry_dma, GFP_KERNEL);
6091 if (!fw_ddb_entry) {
6092 DEBUG2(ql4_printk(KERN_ERR, ha,
6093 "%s: Unable to allocate dma buffer.\n",
6094 __func__));
6095 ret = QLA_ERROR;
6096 return ret;
6097 }
6098
6099 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6100 fw_ddb_entry_dma, ddb_index)) {
6101 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6102 "index [%d]\n", __func__, ddb_index));
6103 ret = QLA_ERROR;
6104 goto exit_boot_target;
6105 }
6106
6107 /* Update target name and IP from DDB */
6108 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6109 min(sizeof(boot_sess->target_name),
6110 sizeof(fw_ddb_entry->iscsi_name)));
6111
6112 options = le16_to_cpu(fw_ddb_entry->options);
6113 if (options & DDB_OPT_IPV6_DEVICE) {
6114 memcpy(&boot_conn->dest_ipaddr.ip_address,
6115 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6116 } else {
6117 boot_conn->dest_ipaddr.ip_type = 0x1;
6118 memcpy(&boot_conn->dest_ipaddr.ip_address,
6119 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6120 }
6121
6122 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6123
6124 /* update chap information */
6125 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6126
6127 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6128
6129 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6130
6131 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6132 target_chap_name,
6133 (char *)&boot_conn->chap.target_secret,
6134 idx);
6135 if (ret) {
6136 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6137 ret = QLA_ERROR;
6138 goto exit_boot_target;
6139 }
6140
6141 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6142 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6143 }
6144
6145 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6146
6147 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6148
6149 ret = qla4xxx_get_bidi_chap(ha,
6150 (char *)&boot_conn->chap.intr_chap_name,
6151 (char *)&boot_conn->chap.intr_secret);
6152
6153 if (ret) {
6154 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6155 ret = QLA_ERROR;
6156 goto exit_boot_target;
6157 }
6158
6159 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6160 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6161 }
6162
6163 exit_boot_target:
6164 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6165 fw_ddb_entry, fw_ddb_entry_dma);
6166 return ret;
6167 }
6168
qla4xxx_get_boot_info(struct scsi_qla_host * ha)6169 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6170 {
6171 uint16_t ddb_index[2];
6172 int ret = QLA_ERROR;
6173 int rval;
6174
6175 memset(ddb_index, 0, sizeof(ddb_index));
6176 ddb_index[0] = 0xffff;
6177 ddb_index[1] = 0xffff;
6178 ret = get_fw_boot_info(ha, ddb_index);
6179 if (ret != QLA_SUCCESS) {
6180 DEBUG2(ql4_printk(KERN_INFO, ha,
6181 "%s: No boot target configured.\n", __func__));
6182 return ret;
6183 }
6184
6185 if (ql4xdisablesysfsboot)
6186 return QLA_SUCCESS;
6187
6188 if (ddb_index[0] == 0xffff)
6189 goto sec_target;
6190
6191 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6192 ddb_index[0]);
6193 if (rval != QLA_SUCCESS) {
6194 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6195 "configured\n", __func__));
6196 } else
6197 ret = QLA_SUCCESS;
6198
6199 sec_target:
6200 if (ddb_index[1] == 0xffff)
6201 goto exit_get_boot_info;
6202
6203 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6204 ddb_index[1]);
6205 if (rval != QLA_SUCCESS) {
6206 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6207 " configured\n", __func__));
6208 } else
6209 ret = QLA_SUCCESS;
6210
6211 exit_get_boot_info:
6212 return ret;
6213 }
6214
qla4xxx_setup_boot_info(struct scsi_qla_host * ha)6215 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6216 {
6217 struct iscsi_boot_kobj *boot_kobj;
6218
6219 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6220 return QLA_ERROR;
6221
6222 if (ql4xdisablesysfsboot) {
6223 ql4_printk(KERN_INFO, ha,
6224 "%s: syfsboot disabled - driver will trigger login "
6225 "and publish session for discovery .\n", __func__);
6226 return QLA_SUCCESS;
6227 }
6228
6229
6230 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6231 if (!ha->boot_kset)
6232 goto kset_free;
6233
6234 if (!scsi_host_get(ha->host))
6235 goto kset_free;
6236 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6237 qla4xxx_show_boot_tgt_pri_info,
6238 qla4xxx_tgt_get_attr_visibility,
6239 qla4xxx_boot_release);
6240 if (!boot_kobj)
6241 goto put_host;
6242
6243 if (!scsi_host_get(ha->host))
6244 goto kset_free;
6245 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6246 qla4xxx_show_boot_tgt_sec_info,
6247 qla4xxx_tgt_get_attr_visibility,
6248 qla4xxx_boot_release);
6249 if (!boot_kobj)
6250 goto put_host;
6251
6252 if (!scsi_host_get(ha->host))
6253 goto kset_free;
6254 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6255 qla4xxx_show_boot_ini_info,
6256 qla4xxx_ini_get_attr_visibility,
6257 qla4xxx_boot_release);
6258 if (!boot_kobj)
6259 goto put_host;
6260
6261 if (!scsi_host_get(ha->host))
6262 goto kset_free;
6263 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6264 qla4xxx_show_boot_eth_info,
6265 qla4xxx_eth_get_attr_visibility,
6266 qla4xxx_boot_release);
6267 if (!boot_kobj)
6268 goto put_host;
6269
6270 return QLA_SUCCESS;
6271
6272 put_host:
6273 scsi_host_put(ha->host);
6274 kset_free:
6275 iscsi_boot_destroy_kset(ha->boot_kset);
6276 return -ENOMEM;
6277 }
6278
6279
qla4xxx_get_param_ddb(struct ddb_entry * ddb_entry,struct ql4_tuple_ddb * tddb)6280 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6281 struct ql4_tuple_ddb *tddb)
6282 {
6283 struct iscsi_cls_session *cls_sess;
6284 struct iscsi_cls_conn *cls_conn;
6285 struct iscsi_session *sess;
6286 struct iscsi_conn *conn;
6287
6288 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6289 cls_sess = ddb_entry->sess;
6290 sess = cls_sess->dd_data;
6291 cls_conn = ddb_entry->conn;
6292 conn = cls_conn->dd_data;
6293
6294 tddb->tpgt = sess->tpgt;
6295 tddb->port = conn->persistent_port;
6296 strscpy(tddb->iscsi_name, sess->targetname, sizeof(tddb->iscsi_name));
6297 strscpy(tddb->ip_addr, conn->persistent_address, sizeof(tddb->ip_addr));
6298 }
6299
qla4xxx_convert_param_ddb(struct dev_db_entry * fw_ddb_entry,struct ql4_tuple_ddb * tddb,uint8_t * flash_isid)6300 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6301 struct ql4_tuple_ddb *tddb,
6302 uint8_t *flash_isid)
6303 {
6304 uint16_t options = 0;
6305
6306 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6307 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6308 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6309
6310 options = le16_to_cpu(fw_ddb_entry->options);
6311 if (options & DDB_OPT_IPV6_DEVICE)
6312 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6313 else
6314 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6315
6316 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6317
6318 if (flash_isid == NULL)
6319 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6320 sizeof(tddb->isid));
6321 else
6322 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6323 }
6324
qla4xxx_compare_tuple_ddb(struct scsi_qla_host * ha,struct ql4_tuple_ddb * old_tddb,struct ql4_tuple_ddb * new_tddb,uint8_t is_isid_compare)6325 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6326 struct ql4_tuple_ddb *old_tddb,
6327 struct ql4_tuple_ddb *new_tddb,
6328 uint8_t is_isid_compare)
6329 {
6330 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6331 return QLA_ERROR;
6332
6333 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6334 return QLA_ERROR;
6335
6336 if (old_tddb->port != new_tddb->port)
6337 return QLA_ERROR;
6338
6339 /* For multi sessions, driver generates the ISID, so do not compare
6340 * ISID in reset path since it would be a comparison between the
6341 * driver generated ISID and firmware generated ISID. This could
6342 * lead to adding duplicated DDBs in the list as driver generated
6343 * ISID would not match firmware generated ISID.
6344 */
6345 if (is_isid_compare) {
6346 DEBUG2(ql4_printk(KERN_INFO, ha,
6347 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6348 __func__, old_tddb->isid, new_tddb->isid));
6349
6350 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6351 sizeof(old_tddb->isid)))
6352 return QLA_ERROR;
6353 }
6354
6355 DEBUG2(ql4_printk(KERN_INFO, ha,
6356 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6357 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6358 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6359 new_tddb->ip_addr, new_tddb->iscsi_name));
6360
6361 return QLA_SUCCESS;
6362 }
6363
qla4xxx_is_session_exists(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint32_t * index)6364 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6365 struct dev_db_entry *fw_ddb_entry,
6366 uint32_t *index)
6367 {
6368 struct ddb_entry *ddb_entry;
6369 struct ql4_tuple_ddb *fw_tddb = NULL;
6370 struct ql4_tuple_ddb *tmp_tddb = NULL;
6371 int idx;
6372 int ret = QLA_ERROR;
6373
6374 fw_tddb = vzalloc(sizeof(*fw_tddb));
6375 if (!fw_tddb) {
6376 DEBUG2(ql4_printk(KERN_WARNING, ha,
6377 "Memory Allocation failed.\n"));
6378 ret = QLA_SUCCESS;
6379 goto exit_check;
6380 }
6381
6382 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6383 if (!tmp_tddb) {
6384 DEBUG2(ql4_printk(KERN_WARNING, ha,
6385 "Memory Allocation failed.\n"));
6386 ret = QLA_SUCCESS;
6387 goto exit_check;
6388 }
6389
6390 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6391
6392 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6393 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6394 if (ddb_entry == NULL)
6395 continue;
6396
6397 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6398 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6399 ret = QLA_SUCCESS; /* found */
6400 if (index != NULL)
6401 *index = idx;
6402 goto exit_check;
6403 }
6404 }
6405
6406 exit_check:
6407 vfree(fw_tddb);
6408 vfree(tmp_tddb);
6409 return ret;
6410 }
6411
6412 /**
6413 * qla4xxx_check_existing_isid - check if target with same isid exist
6414 * in target list
6415 * @list_nt: list of target
6416 * @isid: isid to check
6417 *
6418 * This routine return QLA_SUCCESS if target with same isid exist
6419 **/
qla4xxx_check_existing_isid(struct list_head * list_nt,uint8_t * isid)6420 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6421 {
6422 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6423 struct dev_db_entry *fw_ddb_entry;
6424
6425 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6426 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6427
6428 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6429 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6430 return QLA_SUCCESS;
6431 }
6432 }
6433 return QLA_ERROR;
6434 }
6435
6436 /**
6437 * qla4xxx_update_isid - compare ddbs and updated isid
6438 * @ha: Pointer to host adapter structure.
6439 * @list_nt: list of nt target
6440 * @fw_ddb_entry: firmware ddb entry
6441 *
6442 * This routine update isid if ddbs have same iqn, same isid and
6443 * different IP addr.
6444 * Return QLA_SUCCESS if isid is updated.
6445 **/
qla4xxx_update_isid(struct scsi_qla_host * ha,struct list_head * list_nt,struct dev_db_entry * fw_ddb_entry)6446 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6447 struct list_head *list_nt,
6448 struct dev_db_entry *fw_ddb_entry)
6449 {
6450 uint8_t base_value, i;
6451
6452 base_value = fw_ddb_entry->isid[1] & 0x1f;
6453 for (i = 0; i < 8; i++) {
6454 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6455 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6456 break;
6457 }
6458
6459 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6460 return QLA_ERROR;
6461
6462 return QLA_SUCCESS;
6463 }
6464
6465 /**
6466 * qla4xxx_should_update_isid - check if isid need to update
6467 * @ha: Pointer to host adapter structure.
6468 * @old_tddb: ddb tuple
6469 * @new_tddb: ddb tuple
6470 *
6471 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6472 * same isid
6473 **/
qla4xxx_should_update_isid(struct scsi_qla_host * ha,struct ql4_tuple_ddb * old_tddb,struct ql4_tuple_ddb * new_tddb)6474 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6475 struct ql4_tuple_ddb *old_tddb,
6476 struct ql4_tuple_ddb *new_tddb)
6477 {
6478 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6479 /* Same ip */
6480 if (old_tddb->port == new_tddb->port)
6481 return QLA_ERROR;
6482 }
6483
6484 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6485 /* different iqn */
6486 return QLA_ERROR;
6487
6488 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6489 sizeof(old_tddb->isid)))
6490 /* different isid */
6491 return QLA_ERROR;
6492
6493 return QLA_SUCCESS;
6494 }
6495
6496 /**
6497 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6498 * @ha: Pointer to host adapter structure.
6499 * @list_nt: list of nt target.
6500 * @fw_ddb_entry: firmware ddb entry.
6501 *
6502 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6503 * duplicate ddb in list_nt.
6504 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6505 * Note: This function also update isid of DDB if required.
6506 **/
6507
qla4xxx_is_flash_ddb_exists(struct scsi_qla_host * ha,struct list_head * list_nt,struct dev_db_entry * fw_ddb_entry)6508 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6509 struct list_head *list_nt,
6510 struct dev_db_entry *fw_ddb_entry)
6511 {
6512 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6513 struct ql4_tuple_ddb *fw_tddb = NULL;
6514 struct ql4_tuple_ddb *tmp_tddb = NULL;
6515 int rval, ret = QLA_ERROR;
6516
6517 fw_tddb = vzalloc(sizeof(*fw_tddb));
6518 if (!fw_tddb) {
6519 DEBUG2(ql4_printk(KERN_WARNING, ha,
6520 "Memory Allocation failed.\n"));
6521 ret = QLA_SUCCESS;
6522 goto exit_check;
6523 }
6524
6525 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6526 if (!tmp_tddb) {
6527 DEBUG2(ql4_printk(KERN_WARNING, ha,
6528 "Memory Allocation failed.\n"));
6529 ret = QLA_SUCCESS;
6530 goto exit_check;
6531 }
6532
6533 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6534
6535 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6536 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6537 nt_ddb_idx->flash_isid);
6538 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6539 /* found duplicate ddb */
6540 if (ret == QLA_SUCCESS)
6541 goto exit_check;
6542 }
6543
6544 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6545 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6546
6547 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6548 if (ret == QLA_SUCCESS) {
6549 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6550 if (rval == QLA_SUCCESS)
6551 ret = QLA_ERROR;
6552 else
6553 ret = QLA_SUCCESS;
6554
6555 goto exit_check;
6556 }
6557 }
6558
6559 exit_check:
6560 vfree(fw_tddb);
6561 vfree(tmp_tddb);
6562 return ret;
6563 }
6564
qla4xxx_free_ddb_list(struct list_head * list_ddb)6565 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6566 {
6567 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6568
6569 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6570 list_del_init(&ddb_idx->list);
6571 vfree(ddb_idx);
6572 }
6573 }
6574
qla4xxx_get_ep_fwdb(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry)6575 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6576 struct dev_db_entry *fw_ddb_entry)
6577 {
6578 struct iscsi_endpoint *ep;
6579 struct sockaddr_in *addr;
6580 struct sockaddr_in6 *addr6;
6581 struct sockaddr *t_addr;
6582 struct sockaddr_storage *dst_addr;
6583 char *ip;
6584
6585 /* TODO: need to destroy on unload iscsi_endpoint*/
6586 dst_addr = vmalloc(sizeof(*dst_addr));
6587 if (!dst_addr)
6588 return NULL;
6589
6590 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6591 t_addr = (struct sockaddr *)dst_addr;
6592 t_addr->sa_family = AF_INET6;
6593 addr6 = (struct sockaddr_in6 *)dst_addr;
6594 ip = (char *)&addr6->sin6_addr;
6595 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6596 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6597
6598 } else {
6599 t_addr = (struct sockaddr *)dst_addr;
6600 t_addr->sa_family = AF_INET;
6601 addr = (struct sockaddr_in *)dst_addr;
6602 ip = (char *)&addr->sin_addr;
6603 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6604 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6605 }
6606
6607 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6608 vfree(dst_addr);
6609 if (IS_ERR(ep))
6610 return NULL;
6611 return ep;
6612 }
6613
qla4xxx_verify_boot_idx(struct scsi_qla_host * ha,uint16_t idx)6614 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6615 {
6616 if (ql4xdisablesysfsboot)
6617 return QLA_SUCCESS;
6618 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6619 return QLA_ERROR;
6620 return QLA_SUCCESS;
6621 }
6622
qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry,uint16_t idx)6623 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6624 struct ddb_entry *ddb_entry,
6625 uint16_t idx)
6626 {
6627 uint16_t def_timeout;
6628
6629 ddb_entry->ddb_type = FLASH_DDB;
6630 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6631 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6632 ddb_entry->ha = ha;
6633 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6634 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6635 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6636
6637 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6638 atomic_set(&ddb_entry->relogin_timer, 0);
6639 atomic_set(&ddb_entry->relogin_retry_count, 0);
6640 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6641 ddb_entry->default_relogin_timeout =
6642 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6643 def_timeout : LOGIN_TOV;
6644 ddb_entry->default_time2wait =
6645 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6646
6647 if (ql4xdisablesysfsboot &&
6648 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6649 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6650 }
6651
qla4xxx_wait_for_ip_configuration(struct scsi_qla_host * ha)6652 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6653 {
6654 uint32_t idx = 0;
6655 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6656 uint32_t sts[MBOX_REG_COUNT];
6657 uint32_t ip_state;
6658 unsigned long wtime;
6659 int ret;
6660
6661 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6662 do {
6663 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6664 if (ip_idx[idx] == -1)
6665 continue;
6666
6667 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6668
6669 if (ret == QLA_ERROR) {
6670 ip_idx[idx] = -1;
6671 continue;
6672 }
6673
6674 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6675
6676 DEBUG2(ql4_printk(KERN_INFO, ha,
6677 "Waiting for IP state for idx = %d, state = 0x%x\n",
6678 ip_idx[idx], ip_state));
6679 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6680 ip_state == IP_ADDRSTATE_INVALID ||
6681 ip_state == IP_ADDRSTATE_PREFERRED ||
6682 ip_state == IP_ADDRSTATE_DEPRICATED ||
6683 ip_state == IP_ADDRSTATE_DISABLING)
6684 ip_idx[idx] = -1;
6685 }
6686
6687 /* Break if all IP states checked */
6688 if ((ip_idx[0] == -1) &&
6689 (ip_idx[1] == -1) &&
6690 (ip_idx[2] == -1) &&
6691 (ip_idx[3] == -1))
6692 break;
6693 schedule_timeout_uninterruptible(HZ);
6694 } while (time_after(wtime, jiffies));
6695 }
6696
qla4xxx_cmp_fw_stentry(struct dev_db_entry * fw_ddb_entry,struct dev_db_entry * flash_ddb_entry)6697 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6698 struct dev_db_entry *flash_ddb_entry)
6699 {
6700 uint16_t options = 0;
6701 size_t ip_len = IP_ADDR_LEN;
6702
6703 options = le16_to_cpu(fw_ddb_entry->options);
6704 if (options & DDB_OPT_IPV6_DEVICE)
6705 ip_len = IPv6_ADDR_LEN;
6706
6707 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6708 return QLA_ERROR;
6709
6710 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6711 sizeof(fw_ddb_entry->isid)))
6712 return QLA_ERROR;
6713
6714 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6715 sizeof(fw_ddb_entry->port)))
6716 return QLA_ERROR;
6717
6718 return QLA_SUCCESS;
6719 }
6720
qla4xxx_find_flash_st_idx(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint32_t fw_idx,uint32_t * flash_index)6721 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6722 struct dev_db_entry *fw_ddb_entry,
6723 uint32_t fw_idx, uint32_t *flash_index)
6724 {
6725 struct dev_db_entry *flash_ddb_entry;
6726 dma_addr_t flash_ddb_entry_dma;
6727 uint32_t idx = 0;
6728 int max_ddbs;
6729 int ret = QLA_ERROR, status;
6730
6731 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6732 MAX_DEV_DB_ENTRIES;
6733
6734 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6735 &flash_ddb_entry_dma);
6736 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6737 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6738 goto exit_find_st_idx;
6739 }
6740
6741 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6742 flash_ddb_entry_dma, fw_idx);
6743 if (status == QLA_SUCCESS) {
6744 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6745 if (status == QLA_SUCCESS) {
6746 *flash_index = fw_idx;
6747 ret = QLA_SUCCESS;
6748 goto exit_find_st_idx;
6749 }
6750 }
6751
6752 for (idx = 0; idx < max_ddbs; idx++) {
6753 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6754 flash_ddb_entry_dma, idx);
6755 if (status == QLA_ERROR)
6756 continue;
6757
6758 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6759 if (status == QLA_SUCCESS) {
6760 *flash_index = idx;
6761 ret = QLA_SUCCESS;
6762 goto exit_find_st_idx;
6763 }
6764 }
6765
6766 if (idx == max_ddbs)
6767 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6768 fw_idx);
6769
6770 exit_find_st_idx:
6771 if (flash_ddb_entry)
6772 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6773 flash_ddb_entry_dma);
6774
6775 return ret;
6776 }
6777
qla4xxx_build_st_list(struct scsi_qla_host * ha,struct list_head * list_st)6778 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6779 struct list_head *list_st)
6780 {
6781 struct qla_ddb_index *st_ddb_idx;
6782 int max_ddbs;
6783 int fw_idx_size;
6784 struct dev_db_entry *fw_ddb_entry;
6785 dma_addr_t fw_ddb_dma;
6786 int ret;
6787 uint32_t idx = 0, next_idx = 0;
6788 uint32_t state = 0, conn_err = 0;
6789 uint32_t flash_index = -1;
6790 uint16_t conn_id = 0;
6791
6792 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6793 &fw_ddb_dma);
6794 if (fw_ddb_entry == NULL) {
6795 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6796 goto exit_st_list;
6797 }
6798
6799 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6800 MAX_DEV_DB_ENTRIES;
6801 fw_idx_size = sizeof(struct qla_ddb_index);
6802
6803 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6804 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6805 NULL, &next_idx, &state,
6806 &conn_err, NULL, &conn_id);
6807 if (ret == QLA_ERROR)
6808 break;
6809
6810 /* Ignore DDB if invalid state (unassigned) */
6811 if (state == DDB_DS_UNASSIGNED)
6812 goto continue_next_st;
6813
6814 /* Check if ST, add to the list_st */
6815 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6816 goto continue_next_st;
6817
6818 st_ddb_idx = vzalloc(fw_idx_size);
6819 if (!st_ddb_idx)
6820 break;
6821
6822 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6823 &flash_index);
6824 if (ret == QLA_ERROR) {
6825 ql4_printk(KERN_ERR, ha,
6826 "No flash entry for ST at idx [%d]\n", idx);
6827 st_ddb_idx->flash_ddb_idx = idx;
6828 } else {
6829 ql4_printk(KERN_INFO, ha,
6830 "ST at idx [%d] is stored at flash [%d]\n",
6831 idx, flash_index);
6832 st_ddb_idx->flash_ddb_idx = flash_index;
6833 }
6834
6835 st_ddb_idx->fw_ddb_idx = idx;
6836
6837 list_add_tail(&st_ddb_idx->list, list_st);
6838 continue_next_st:
6839 if (next_idx == 0)
6840 break;
6841 }
6842
6843 exit_st_list:
6844 if (fw_ddb_entry)
6845 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6846 }
6847
6848 /**
6849 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6850 * @ha: pointer to adapter structure
6851 * @list_ddb: List from which failed ddb to be removed
6852 *
6853 * Iterate over the list of DDBs and find and remove DDBs that are either in
6854 * no connection active state or failed state
6855 **/
qla4xxx_remove_failed_ddb(struct scsi_qla_host * ha,struct list_head * list_ddb)6856 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6857 struct list_head *list_ddb)
6858 {
6859 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6860 uint32_t next_idx = 0;
6861 uint32_t state = 0, conn_err = 0;
6862 int ret;
6863
6864 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6865 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6866 NULL, 0, NULL, &next_idx, &state,
6867 &conn_err, NULL, NULL);
6868 if (ret == QLA_ERROR)
6869 continue;
6870
6871 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6872 state == DDB_DS_SESSION_FAILED) {
6873 list_del_init(&ddb_idx->list);
6874 vfree(ddb_idx);
6875 }
6876 }
6877 }
6878
qla4xxx_update_sess_disc_idx(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry,struct dev_db_entry * fw_ddb_entry)6879 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6880 struct ddb_entry *ddb_entry,
6881 struct dev_db_entry *fw_ddb_entry)
6882 {
6883 struct iscsi_cls_session *cls_sess;
6884 struct iscsi_session *sess;
6885 uint32_t max_ddbs = 0;
6886 uint16_t ddb_link = -1;
6887
6888 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6889 MAX_DEV_DB_ENTRIES;
6890
6891 cls_sess = ddb_entry->sess;
6892 sess = cls_sess->dd_data;
6893
6894 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6895 if (ddb_link < max_ddbs)
6896 sess->discovery_parent_idx = ddb_link;
6897 else
6898 sess->discovery_parent_idx = DDB_NO_LINK;
6899 }
6900
qla4xxx_sess_conn_setup(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,int is_reset,uint16_t idx)6901 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6902 struct dev_db_entry *fw_ddb_entry,
6903 int is_reset, uint16_t idx)
6904 {
6905 struct iscsi_cls_session *cls_sess;
6906 struct iscsi_session *sess;
6907 struct iscsi_cls_conn *cls_conn;
6908 struct iscsi_endpoint *ep;
6909 uint16_t cmds_max = 32;
6910 uint16_t conn_id = 0;
6911 uint32_t initial_cmdsn = 0;
6912 int ret = QLA_SUCCESS;
6913
6914 struct ddb_entry *ddb_entry = NULL;
6915
6916 /* Create session object, with INVALID_ENTRY,
6917 * the targer_id would get set when we issue the login
6918 */
6919 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6920 cmds_max, sizeof(struct ddb_entry),
6921 sizeof(struct ql4_task_data),
6922 initial_cmdsn, INVALID_ENTRY);
6923 if (!cls_sess) {
6924 ret = QLA_ERROR;
6925 goto exit_setup;
6926 }
6927
6928 /*
6929 * so calling module_put function to decrement the
6930 * reference count.
6931 **/
6932 module_put(qla4xxx_iscsi_transport.owner);
6933 sess = cls_sess->dd_data;
6934 ddb_entry = sess->dd_data;
6935 ddb_entry->sess = cls_sess;
6936
6937 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6938 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6939 sizeof(struct dev_db_entry));
6940
6941 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6942
6943 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6944
6945 if (!cls_conn) {
6946 ret = QLA_ERROR;
6947 goto exit_setup;
6948 }
6949
6950 ddb_entry->conn = cls_conn;
6951
6952 /* Setup ep, for displaying attributes in sysfs */
6953 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6954 if (ep) {
6955 ep->conn = cls_conn;
6956 cls_conn->ep = ep;
6957 } else {
6958 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6959 ret = QLA_ERROR;
6960 goto exit_setup;
6961 }
6962
6963 /* Update sess/conn params */
6964 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6965 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6966
6967 if (is_reset == RESET_ADAPTER) {
6968 iscsi_block_session(cls_sess);
6969 /* Use the relogin path to discover new devices
6970 * by short-circuiting the logic of setting
6971 * timer to relogin - instead set the flags
6972 * to initiate login right away.
6973 */
6974 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6975 set_bit(DF_RELOGIN, &ddb_entry->flags);
6976 }
6977
6978 exit_setup:
6979 return ret;
6980 }
6981
qla4xxx_update_fw_ddb_link(struct scsi_qla_host * ha,struct list_head * list_ddb,struct dev_db_entry * fw_ddb_entry)6982 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6983 struct list_head *list_ddb,
6984 struct dev_db_entry *fw_ddb_entry)
6985 {
6986 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6987 uint16_t ddb_link;
6988
6989 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6990
6991 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6992 if (ddb_idx->fw_ddb_idx == ddb_link) {
6993 DEBUG2(ql4_printk(KERN_INFO, ha,
6994 "Updating NT parent idx from [%d] to [%d]\n",
6995 ddb_link, ddb_idx->flash_ddb_idx));
6996 fw_ddb_entry->ddb_link =
6997 cpu_to_le16(ddb_idx->flash_ddb_idx);
6998 return;
6999 }
7000 }
7001 }
7002
qla4xxx_build_nt_list(struct scsi_qla_host * ha,struct list_head * list_nt,struct list_head * list_st,int is_reset)7003 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
7004 struct list_head *list_nt,
7005 struct list_head *list_st,
7006 int is_reset)
7007 {
7008 struct dev_db_entry *fw_ddb_entry;
7009 struct ddb_entry *ddb_entry = NULL;
7010 dma_addr_t fw_ddb_dma;
7011 int max_ddbs;
7012 int fw_idx_size;
7013 int ret;
7014 uint32_t idx = 0, next_idx = 0;
7015 uint32_t state = 0, conn_err = 0;
7016 uint32_t ddb_idx = -1;
7017 uint16_t conn_id = 0;
7018 uint16_t ddb_link = -1;
7019 struct qla_ddb_index *nt_ddb_idx;
7020
7021 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7022 &fw_ddb_dma);
7023 if (fw_ddb_entry == NULL) {
7024 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7025 goto exit_nt_list;
7026 }
7027 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7028 MAX_DEV_DB_ENTRIES;
7029 fw_idx_size = sizeof(struct qla_ddb_index);
7030
7031 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7032 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7033 NULL, &next_idx, &state,
7034 &conn_err, NULL, &conn_id);
7035 if (ret == QLA_ERROR)
7036 break;
7037
7038 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7039 goto continue_next_nt;
7040
7041 /* Check if NT, then add to list it */
7042 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7043 goto continue_next_nt;
7044
7045 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7046 if (ddb_link < max_ddbs)
7047 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7048
7049 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7050 state == DDB_DS_SESSION_FAILED) &&
7051 (is_reset == INIT_ADAPTER))
7052 goto continue_next_nt;
7053
7054 DEBUG2(ql4_printk(KERN_INFO, ha,
7055 "Adding DDB to session = 0x%x\n", idx));
7056
7057 if (is_reset == INIT_ADAPTER) {
7058 nt_ddb_idx = vmalloc(fw_idx_size);
7059 if (!nt_ddb_idx)
7060 break;
7061
7062 nt_ddb_idx->fw_ddb_idx = idx;
7063
7064 /* Copy original isid as it may get updated in function
7065 * qla4xxx_update_isid(). We need original isid in
7066 * function qla4xxx_compare_tuple_ddb to find duplicate
7067 * target */
7068 memcpy(&nt_ddb_idx->flash_isid[0],
7069 &fw_ddb_entry->isid[0],
7070 sizeof(nt_ddb_idx->flash_isid));
7071
7072 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7073 fw_ddb_entry);
7074 if (ret == QLA_SUCCESS) {
7075 /* free nt_ddb_idx and do not add to list_nt */
7076 vfree(nt_ddb_idx);
7077 goto continue_next_nt;
7078 }
7079
7080 /* Copy updated isid */
7081 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7082 sizeof(struct dev_db_entry));
7083
7084 list_add_tail(&nt_ddb_idx->list, list_nt);
7085 } else if (is_reset == RESET_ADAPTER) {
7086 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7087 &ddb_idx);
7088 if (ret == QLA_SUCCESS) {
7089 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7090 ddb_idx);
7091 if (ddb_entry != NULL)
7092 qla4xxx_update_sess_disc_idx(ha,
7093 ddb_entry,
7094 fw_ddb_entry);
7095 goto continue_next_nt;
7096 }
7097 }
7098
7099 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7100 if (ret == QLA_ERROR)
7101 goto exit_nt_list;
7102
7103 continue_next_nt:
7104 if (next_idx == 0)
7105 break;
7106 }
7107
7108 exit_nt_list:
7109 if (fw_ddb_entry)
7110 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7111 }
7112
qla4xxx_build_new_nt_list(struct scsi_qla_host * ha,struct list_head * list_nt,uint16_t target_id)7113 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7114 struct list_head *list_nt,
7115 uint16_t target_id)
7116 {
7117 struct dev_db_entry *fw_ddb_entry;
7118 dma_addr_t fw_ddb_dma;
7119 int max_ddbs;
7120 int fw_idx_size;
7121 int ret;
7122 uint32_t idx = 0, next_idx = 0;
7123 uint32_t state = 0, conn_err = 0;
7124 uint16_t conn_id = 0;
7125 struct qla_ddb_index *nt_ddb_idx;
7126
7127 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7128 &fw_ddb_dma);
7129 if (fw_ddb_entry == NULL) {
7130 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7131 goto exit_new_nt_list;
7132 }
7133 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7134 MAX_DEV_DB_ENTRIES;
7135 fw_idx_size = sizeof(struct qla_ddb_index);
7136
7137 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7138 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7139 NULL, &next_idx, &state,
7140 &conn_err, NULL, &conn_id);
7141 if (ret == QLA_ERROR)
7142 break;
7143
7144 /* Check if NT, then add it to list */
7145 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7146 goto continue_next_new_nt;
7147
7148 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7149 goto continue_next_new_nt;
7150
7151 DEBUG2(ql4_printk(KERN_INFO, ha,
7152 "Adding DDB to session = 0x%x\n", idx));
7153
7154 nt_ddb_idx = vmalloc(fw_idx_size);
7155 if (!nt_ddb_idx)
7156 break;
7157
7158 nt_ddb_idx->fw_ddb_idx = idx;
7159
7160 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7161 if (ret == QLA_SUCCESS) {
7162 /* free nt_ddb_idx and do not add to list_nt */
7163 vfree(nt_ddb_idx);
7164 goto continue_next_new_nt;
7165 }
7166
7167 if (target_id < max_ddbs)
7168 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7169
7170 list_add_tail(&nt_ddb_idx->list, list_nt);
7171
7172 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7173 idx);
7174 if (ret == QLA_ERROR)
7175 goto exit_new_nt_list;
7176
7177 continue_next_new_nt:
7178 if (next_idx == 0)
7179 break;
7180 }
7181
7182 exit_new_nt_list:
7183 if (fw_ddb_entry)
7184 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7185 }
7186
7187 /**
7188 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7189 * @dev: dev associated with the sysfs entry
7190 * @data: pointer to flashnode session object
7191 *
7192 * Returns:
7193 * 1: if flashnode entry is non-persistent
7194 * 0: if flashnode entry is persistent
7195 **/
qla4xxx_sysfs_ddb_is_non_persistent(struct device * dev,void * data)7196 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7197 {
7198 struct iscsi_bus_flash_session *fnode_sess;
7199
7200 if (!iscsi_flashnode_bus_match(dev, NULL))
7201 return 0;
7202
7203 fnode_sess = iscsi_dev_to_flash_session(dev);
7204
7205 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7206 }
7207
7208 /**
7209 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7210 * @ha: pointer to host
7211 * @fw_ddb_entry: flash ddb data
7212 * @idx: target index
7213 * @user: if set then this call is made from userland else from kernel
7214 *
7215 * Returns:
7216 * On sucess: QLA_SUCCESS
7217 * On failure: QLA_ERROR
7218 *
7219 * This create separate sysfs entries for session and connection attributes of
7220 * the given fw ddb entry.
7221 * If this is invoked as a result of a userspace call then the entry is marked
7222 * as nonpersistent using flash_state field.
7223 **/
qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint16_t * idx,int user)7224 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7225 struct dev_db_entry *fw_ddb_entry,
7226 uint16_t *idx, int user)
7227 {
7228 struct iscsi_bus_flash_session *fnode_sess = NULL;
7229 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7230 int rc = QLA_ERROR;
7231
7232 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7233 &qla4xxx_iscsi_transport, 0);
7234 if (!fnode_sess) {
7235 ql4_printk(KERN_ERR, ha,
7236 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7237 __func__, *idx, ha->host_no);
7238 goto exit_tgt_create;
7239 }
7240
7241 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7242 &qla4xxx_iscsi_transport, 0);
7243 if (!fnode_conn) {
7244 ql4_printk(KERN_ERR, ha,
7245 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7246 __func__, *idx, ha->host_no);
7247 goto free_sess;
7248 }
7249
7250 if (user) {
7251 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7252 } else {
7253 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7254
7255 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7256 fnode_sess->is_boot_target = 1;
7257 else
7258 fnode_sess->is_boot_target = 0;
7259 }
7260
7261 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7262 fw_ddb_entry);
7263 if (rc)
7264 goto free_sess;
7265
7266 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7267 __func__, fnode_sess->dev.kobj.name);
7268
7269 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7270 __func__, fnode_conn->dev.kobj.name);
7271
7272 return QLA_SUCCESS;
7273
7274 free_sess:
7275 iscsi_destroy_flashnode_sess(fnode_sess);
7276
7277 exit_tgt_create:
7278 return QLA_ERROR;
7279 }
7280
7281 /**
7282 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7283 * @shost: pointer to host
7284 * @buf: type of ddb entry (ipv4/ipv6)
7285 * @len: length of buf
7286 *
7287 * This creates new ddb entry in the flash by finding first free index and
7288 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7289 **/
qla4xxx_sysfs_ddb_add(struct Scsi_Host * shost,const char * buf,int len)7290 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7291 int len)
7292 {
7293 struct scsi_qla_host *ha = to_qla_host(shost);
7294 struct dev_db_entry *fw_ddb_entry = NULL;
7295 dma_addr_t fw_ddb_entry_dma;
7296 struct device *dev;
7297 uint16_t idx = 0;
7298 uint16_t max_ddbs = 0;
7299 uint32_t options = 0;
7300 uint32_t rval = QLA_ERROR;
7301
7302 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7303 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7304 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7305 __func__));
7306 goto exit_ddb_add;
7307 }
7308
7309 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7310 MAX_DEV_DB_ENTRIES;
7311
7312 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7313 &fw_ddb_entry_dma, GFP_KERNEL);
7314 if (!fw_ddb_entry) {
7315 DEBUG2(ql4_printk(KERN_ERR, ha,
7316 "%s: Unable to allocate dma buffer\n",
7317 __func__));
7318 goto exit_ddb_add;
7319 }
7320
7321 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7322 qla4xxx_sysfs_ddb_is_non_persistent);
7323 if (dev) {
7324 ql4_printk(KERN_ERR, ha,
7325 "%s: A non-persistent entry %s found\n",
7326 __func__, dev->kobj.name);
7327 put_device(dev);
7328 goto exit_ddb_add;
7329 }
7330
7331 /* Index 0 and 1 are reserved for boot target entries */
7332 for (idx = 2; idx < max_ddbs; idx++) {
7333 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7334 fw_ddb_entry_dma, idx))
7335 break;
7336 }
7337
7338 if (idx == max_ddbs)
7339 goto exit_ddb_add;
7340
7341 if (!strncasecmp("ipv6", buf, 4))
7342 options |= IPV6_DEFAULT_DDB_ENTRY;
7343
7344 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7345 if (rval == QLA_ERROR)
7346 goto exit_ddb_add;
7347
7348 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7349
7350 exit_ddb_add:
7351 if (fw_ddb_entry)
7352 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7353 fw_ddb_entry, fw_ddb_entry_dma);
7354 if (rval == QLA_SUCCESS)
7355 return idx;
7356 else
7357 return -EIO;
7358 }
7359
7360 /**
7361 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7362 * @fnode_sess: pointer to session attrs of flash ddb entry
7363 * @fnode_conn: pointer to connection attrs of flash ddb entry
7364 *
7365 * This writes the contents of target ddb buffer to Flash with a valid cookie
7366 * value in order to make the ddb entry persistent.
7367 **/
qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session * fnode_sess,struct iscsi_bus_flash_conn * fnode_conn)7368 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7369 struct iscsi_bus_flash_conn *fnode_conn)
7370 {
7371 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7372 struct scsi_qla_host *ha = to_qla_host(shost);
7373 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7374 struct dev_db_entry *fw_ddb_entry = NULL;
7375 dma_addr_t fw_ddb_entry_dma;
7376 uint32_t options = 0;
7377 int rval = 0;
7378
7379 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7380 &fw_ddb_entry_dma, GFP_KERNEL);
7381 if (!fw_ddb_entry) {
7382 DEBUG2(ql4_printk(KERN_ERR, ha,
7383 "%s: Unable to allocate dma buffer\n",
7384 __func__));
7385 rval = -ENOMEM;
7386 goto exit_ddb_apply;
7387 }
7388
7389 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7390 options |= IPV6_DEFAULT_DDB_ENTRY;
7391
7392 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7393 if (rval == QLA_ERROR)
7394 goto exit_ddb_apply;
7395
7396 dev_db_start_offset += (fnode_sess->target_id *
7397 sizeof(*fw_ddb_entry));
7398
7399 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7400 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7401
7402 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7403 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7404
7405 if (rval == QLA_SUCCESS) {
7406 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7407 ql4_printk(KERN_INFO, ha,
7408 "%s: flash node %u of host %lu written to flash\n",
7409 __func__, fnode_sess->target_id, ha->host_no);
7410 } else {
7411 rval = -EIO;
7412 ql4_printk(KERN_ERR, ha,
7413 "%s: Error while writing flash node %u of host %lu to flash\n",
7414 __func__, fnode_sess->target_id, ha->host_no);
7415 }
7416
7417 exit_ddb_apply:
7418 if (fw_ddb_entry)
7419 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7420 fw_ddb_entry, fw_ddb_entry_dma);
7421 return rval;
7422 }
7423
qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint16_t idx)7424 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7425 struct dev_db_entry *fw_ddb_entry,
7426 uint16_t idx)
7427 {
7428 struct dev_db_entry *ddb_entry = NULL;
7429 dma_addr_t ddb_entry_dma;
7430 unsigned long wtime;
7431 uint32_t mbx_sts = 0;
7432 uint32_t state = 0, conn_err = 0;
7433 uint16_t tmo = 0;
7434 int ret = 0;
7435
7436 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7437 &ddb_entry_dma, GFP_KERNEL);
7438 if (!ddb_entry) {
7439 DEBUG2(ql4_printk(KERN_ERR, ha,
7440 "%s: Unable to allocate dma buffer\n",
7441 __func__));
7442 return QLA_ERROR;
7443 }
7444
7445 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7446
7447 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7448 if (ret != QLA_SUCCESS) {
7449 DEBUG2(ql4_printk(KERN_ERR, ha,
7450 "%s: Unable to set ddb entry for index %d\n",
7451 __func__, idx));
7452 goto exit_ddb_conn_open;
7453 }
7454
7455 qla4xxx_conn_open(ha, idx);
7456
7457 /* To ensure that sendtargets is done, wait for at least 12 secs */
7458 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7459 (ha->def_timeout < LOGIN_TOV * 10) ?
7460 ha->def_timeout : LOGIN_TOV);
7461
7462 DEBUG2(ql4_printk(KERN_INFO, ha,
7463 "Default time to wait for login to ddb %d\n", tmo));
7464
7465 wtime = jiffies + (HZ * tmo);
7466 do {
7467 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7468 NULL, &state, &conn_err, NULL,
7469 NULL);
7470 if (ret == QLA_ERROR)
7471 continue;
7472
7473 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7474 state == DDB_DS_SESSION_FAILED)
7475 break;
7476
7477 schedule_timeout_uninterruptible(HZ / 10);
7478 } while (time_after(wtime, jiffies));
7479
7480 exit_ddb_conn_open:
7481 if (ddb_entry)
7482 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7483 ddb_entry, ddb_entry_dma);
7484 return ret;
7485 }
7486
qla4xxx_ddb_login_st(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint16_t target_id)7487 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7488 struct dev_db_entry *fw_ddb_entry,
7489 uint16_t target_id)
7490 {
7491 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7492 struct list_head list_nt;
7493 uint16_t ddb_index;
7494 int ret = 0;
7495
7496 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7497 ql4_printk(KERN_WARNING, ha,
7498 "%s: A discovery already in progress!\n", __func__);
7499 return QLA_ERROR;
7500 }
7501
7502 INIT_LIST_HEAD(&list_nt);
7503
7504 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7505
7506 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7507 if (ret == QLA_ERROR)
7508 goto exit_login_st_clr_bit;
7509
7510 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7511 if (ret == QLA_ERROR)
7512 goto exit_login_st;
7513
7514 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7515
7516 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7517 list_del_init(&ddb_idx->list);
7518 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7519 vfree(ddb_idx);
7520 }
7521
7522 exit_login_st:
7523 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7524 ql4_printk(KERN_ERR, ha,
7525 "Unable to clear DDB index = 0x%x\n", ddb_index);
7526 }
7527
7528 clear_bit(ddb_index, ha->ddb_idx_map);
7529
7530 exit_login_st_clr_bit:
7531 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7532 return ret;
7533 }
7534
qla4xxx_ddb_login_nt(struct scsi_qla_host * ha,struct dev_db_entry * fw_ddb_entry,uint16_t idx)7535 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7536 struct dev_db_entry *fw_ddb_entry,
7537 uint16_t idx)
7538 {
7539 int ret = QLA_ERROR;
7540
7541 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7542 if (ret != QLA_SUCCESS)
7543 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7544 idx);
7545 else
7546 ret = -EPERM;
7547
7548 return ret;
7549 }
7550
7551 /**
7552 * qla4xxx_sysfs_ddb_login - Login to the specified target
7553 * @fnode_sess: pointer to session attrs of flash ddb entry
7554 * @fnode_conn: pointer to connection attrs of flash ddb entry
7555 *
7556 * This logs in to the specified target
7557 **/
qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session * fnode_sess,struct iscsi_bus_flash_conn * fnode_conn)7558 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7559 struct iscsi_bus_flash_conn *fnode_conn)
7560 {
7561 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7562 struct scsi_qla_host *ha = to_qla_host(shost);
7563 struct dev_db_entry *fw_ddb_entry = NULL;
7564 dma_addr_t fw_ddb_entry_dma;
7565 uint32_t options = 0;
7566 int ret = 0;
7567
7568 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7569 ql4_printk(KERN_ERR, ha,
7570 "%s: Target info is not persistent\n", __func__);
7571 ret = -EIO;
7572 goto exit_ddb_login;
7573 }
7574
7575 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7576 &fw_ddb_entry_dma, GFP_KERNEL);
7577 if (!fw_ddb_entry) {
7578 DEBUG2(ql4_printk(KERN_ERR, ha,
7579 "%s: Unable to allocate dma buffer\n",
7580 __func__));
7581 ret = -ENOMEM;
7582 goto exit_ddb_login;
7583 }
7584
7585 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7586 options |= IPV6_DEFAULT_DDB_ENTRY;
7587
7588 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7589 if (ret == QLA_ERROR)
7590 goto exit_ddb_login;
7591
7592 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7593 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7594
7595 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7596 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7597 fnode_sess->target_id);
7598 else
7599 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7600 fnode_sess->target_id);
7601
7602 if (ret > 0)
7603 ret = -EIO;
7604
7605 exit_ddb_login:
7606 if (fw_ddb_entry)
7607 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7608 fw_ddb_entry, fw_ddb_entry_dma);
7609 return ret;
7610 }
7611
7612 /**
7613 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7614 * @cls_sess: pointer to session to be logged out
7615 *
7616 * This performs session log out from the specified target
7617 **/
qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session * cls_sess)7618 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7619 {
7620 struct iscsi_session *sess;
7621 struct ddb_entry *ddb_entry = NULL;
7622 struct scsi_qla_host *ha;
7623 struct dev_db_entry *fw_ddb_entry = NULL;
7624 dma_addr_t fw_ddb_entry_dma;
7625 unsigned long flags;
7626 unsigned long wtime;
7627 uint32_t ddb_state;
7628 int options;
7629 int ret = 0;
7630
7631 sess = cls_sess->dd_data;
7632 ddb_entry = sess->dd_data;
7633 ha = ddb_entry->ha;
7634
7635 if (ddb_entry->ddb_type != FLASH_DDB) {
7636 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7637 __func__);
7638 ret = -ENXIO;
7639 goto exit_ddb_logout;
7640 }
7641
7642 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7643 ql4_printk(KERN_ERR, ha,
7644 "%s: Logout from boot target entry is not permitted.\n",
7645 __func__);
7646 ret = -EPERM;
7647 goto exit_ddb_logout;
7648 }
7649
7650 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7651 &fw_ddb_entry_dma, GFP_KERNEL);
7652 if (!fw_ddb_entry) {
7653 ql4_printk(KERN_ERR, ha,
7654 "%s: Unable to allocate dma buffer\n", __func__);
7655 ret = -ENOMEM;
7656 goto exit_ddb_logout;
7657 }
7658
7659 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7660 goto ddb_logout_init;
7661
7662 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7663 fw_ddb_entry, fw_ddb_entry_dma,
7664 NULL, NULL, &ddb_state, NULL,
7665 NULL, NULL);
7666 if (ret == QLA_ERROR)
7667 goto ddb_logout_init;
7668
7669 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7670 goto ddb_logout_init;
7671
7672 /* wait until next relogin is triggered using DF_RELOGIN and
7673 * clear DF_RELOGIN to avoid invocation of further relogin
7674 */
7675 wtime = jiffies + (HZ * RELOGIN_TOV);
7676 do {
7677 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7678 goto ddb_logout_init;
7679
7680 schedule_timeout_uninterruptible(HZ);
7681 } while ((time_after(wtime, jiffies)));
7682
7683 ddb_logout_init:
7684 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7685 atomic_set(&ddb_entry->relogin_timer, 0);
7686
7687 options = LOGOUT_OPTION_CLOSE_SESSION;
7688 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7689
7690 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7691 wtime = jiffies + (HZ * LOGOUT_TOV);
7692 do {
7693 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7694 fw_ddb_entry, fw_ddb_entry_dma,
7695 NULL, NULL, &ddb_state, NULL,
7696 NULL, NULL);
7697 if (ret == QLA_ERROR)
7698 goto ddb_logout_clr_sess;
7699
7700 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7701 (ddb_state == DDB_DS_SESSION_FAILED))
7702 goto ddb_logout_clr_sess;
7703
7704 schedule_timeout_uninterruptible(HZ);
7705 } while ((time_after(wtime, jiffies)));
7706
7707 ddb_logout_clr_sess:
7708 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7709 /*
7710 * we have decremented the reference count of the driver
7711 * when we setup the session to have the driver unload
7712 * to be seamless without actually destroying the
7713 * session
7714 **/
7715 try_module_get(qla4xxx_iscsi_transport.owner);
7716 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7717
7718 spin_lock_irqsave(&ha->hardware_lock, flags);
7719 qla4xxx_free_ddb(ha, ddb_entry);
7720 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7721 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7722
7723 iscsi_session_teardown(ddb_entry->sess);
7724
7725 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7726 ret = QLA_SUCCESS;
7727
7728 exit_ddb_logout:
7729 if (fw_ddb_entry)
7730 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7731 fw_ddb_entry, fw_ddb_entry_dma);
7732 return ret;
7733 }
7734
7735 /**
7736 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7737 * @fnode_sess: pointer to session attrs of flash ddb entry
7738 * @fnode_conn: pointer to connection attrs of flash ddb entry
7739 *
7740 * This performs log out from the specified target
7741 **/
qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session * fnode_sess,struct iscsi_bus_flash_conn * fnode_conn)7742 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7743 struct iscsi_bus_flash_conn *fnode_conn)
7744 {
7745 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7746 struct scsi_qla_host *ha = to_qla_host(shost);
7747 struct ql4_tuple_ddb *flash_tddb = NULL;
7748 struct ql4_tuple_ddb *tmp_tddb = NULL;
7749 struct dev_db_entry *fw_ddb_entry = NULL;
7750 struct ddb_entry *ddb_entry = NULL;
7751 dma_addr_t fw_ddb_dma;
7752 uint32_t next_idx = 0;
7753 uint32_t state = 0, conn_err = 0;
7754 uint16_t conn_id = 0;
7755 int idx, index;
7756 int status, ret = 0;
7757
7758 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7759 &fw_ddb_dma);
7760 if (fw_ddb_entry == NULL) {
7761 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7762 ret = -ENOMEM;
7763 goto exit_ddb_logout;
7764 }
7765
7766 flash_tddb = vzalloc(sizeof(*flash_tddb));
7767 if (!flash_tddb) {
7768 ql4_printk(KERN_WARNING, ha,
7769 "%s:Memory Allocation failed.\n", __func__);
7770 ret = -ENOMEM;
7771 goto exit_ddb_logout;
7772 }
7773
7774 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7775 if (!tmp_tddb) {
7776 ql4_printk(KERN_WARNING, ha,
7777 "%s:Memory Allocation failed.\n", __func__);
7778 ret = -ENOMEM;
7779 goto exit_ddb_logout;
7780 }
7781
7782 if (!fnode_sess->targetname) {
7783 ql4_printk(KERN_ERR, ha,
7784 "%s:Cannot logout from SendTarget entry\n",
7785 __func__);
7786 ret = -EPERM;
7787 goto exit_ddb_logout;
7788 }
7789
7790 if (fnode_sess->is_boot_target) {
7791 ql4_printk(KERN_ERR, ha,
7792 "%s: Logout from boot target entry is not permitted.\n",
7793 __func__);
7794 ret = -EPERM;
7795 goto exit_ddb_logout;
7796 }
7797
7798 strscpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7799 sizeof(flash_tddb->iscsi_name));
7800
7801 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7802 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7803 else
7804 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7805
7806 flash_tddb->tpgt = fnode_sess->tpgt;
7807 flash_tddb->port = fnode_conn->port;
7808
7809 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7810
7811 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7812 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7813 if (ddb_entry == NULL)
7814 continue;
7815
7816 if (ddb_entry->ddb_type != FLASH_DDB)
7817 continue;
7818
7819 index = ddb_entry->sess->target_id;
7820 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7821 fw_ddb_dma, NULL, &next_idx,
7822 &state, &conn_err, NULL,
7823 &conn_id);
7824 if (status == QLA_ERROR) {
7825 ret = -ENOMEM;
7826 break;
7827 }
7828
7829 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7830
7831 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7832 true);
7833 if (status == QLA_SUCCESS) {
7834 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7835 break;
7836 }
7837 }
7838
7839 if (idx == MAX_DDB_ENTRIES)
7840 ret = -ESRCH;
7841
7842 exit_ddb_logout:
7843 vfree(flash_tddb);
7844 vfree(tmp_tddb);
7845 if (fw_ddb_entry)
7846 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7847
7848 return ret;
7849 }
7850
7851 static int
qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session * fnode_sess,int param,char * buf)7852 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7853 int param, char *buf)
7854 {
7855 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7856 struct scsi_qla_host *ha = to_qla_host(shost);
7857 struct iscsi_bus_flash_conn *fnode_conn;
7858 struct ql4_chap_table chap_tbl;
7859 struct device *dev;
7860 int parent_type;
7861 int rc = 0;
7862
7863 dev = iscsi_find_flashnode_conn(fnode_sess);
7864 if (!dev)
7865 return -EIO;
7866
7867 fnode_conn = iscsi_dev_to_flash_conn(dev);
7868
7869 switch (param) {
7870 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7871 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7872 break;
7873 case ISCSI_FLASHNODE_PORTAL_TYPE:
7874 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7875 break;
7876 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7877 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7878 break;
7879 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7880 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7881 break;
7882 case ISCSI_FLASHNODE_ENTRY_EN:
7883 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7884 break;
7885 case ISCSI_FLASHNODE_HDR_DGST_EN:
7886 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7887 break;
7888 case ISCSI_FLASHNODE_DATA_DGST_EN:
7889 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7890 break;
7891 case ISCSI_FLASHNODE_IMM_DATA_EN:
7892 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7893 break;
7894 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7895 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7896 break;
7897 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7898 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7899 break;
7900 case ISCSI_FLASHNODE_PDU_INORDER:
7901 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7902 break;
7903 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7904 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7905 break;
7906 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7907 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7908 break;
7909 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7910 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7911 break;
7912 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7913 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7914 break;
7915 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7916 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7917 break;
7918 case ISCSI_FLASHNODE_ERL:
7919 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7920 break;
7921 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7922 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7923 break;
7924 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7925 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7926 break;
7927 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7928 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7929 break;
7930 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7931 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7932 break;
7933 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7934 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7935 break;
7936 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7937 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7938 break;
7939 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7940 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7941 break;
7942 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7943 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7944 break;
7945 case ISCSI_FLASHNODE_FIRST_BURST:
7946 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7947 break;
7948 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7949 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7950 break;
7951 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7952 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7953 break;
7954 case ISCSI_FLASHNODE_MAX_R2T:
7955 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7956 break;
7957 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7958 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7959 break;
7960 case ISCSI_FLASHNODE_ISID:
7961 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7962 break;
7963 case ISCSI_FLASHNODE_TSID:
7964 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7965 break;
7966 case ISCSI_FLASHNODE_PORT:
7967 rc = sprintf(buf, "%d\n", fnode_conn->port);
7968 break;
7969 case ISCSI_FLASHNODE_MAX_BURST:
7970 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7971 break;
7972 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7973 rc = sprintf(buf, "%u\n",
7974 fnode_sess->default_taskmgmt_timeout);
7975 break;
7976 case ISCSI_FLASHNODE_IPADDR:
7977 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7978 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7979 else
7980 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7981 break;
7982 case ISCSI_FLASHNODE_ALIAS:
7983 if (fnode_sess->targetalias)
7984 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7985 else
7986 rc = sprintf(buf, "\n");
7987 break;
7988 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7989 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7990 rc = sprintf(buf, "%pI6\n",
7991 fnode_conn->redirect_ipaddr);
7992 else
7993 rc = sprintf(buf, "%pI4\n",
7994 fnode_conn->redirect_ipaddr);
7995 break;
7996 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7997 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7998 break;
7999 case ISCSI_FLASHNODE_LOCAL_PORT:
8000 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
8001 break;
8002 case ISCSI_FLASHNODE_IPV4_TOS:
8003 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
8004 break;
8005 case ISCSI_FLASHNODE_IPV6_TC:
8006 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8007 rc = sprintf(buf, "%u\n",
8008 fnode_conn->ipv6_traffic_class);
8009 else
8010 rc = sprintf(buf, "\n");
8011 break;
8012 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8013 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8014 break;
8015 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8016 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8017 rc = sprintf(buf, "%pI6\n",
8018 fnode_conn->link_local_ipv6_addr);
8019 else
8020 rc = sprintf(buf, "\n");
8021 break;
8022 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8023 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8024 break;
8025 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8026 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8027 parent_type = ISCSI_DISC_PARENT_ISNS;
8028 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8029 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8030 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8031 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8032 else
8033 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8034
8035 rc = sprintf(buf, "%s\n",
8036 iscsi_get_discovery_parent_name(parent_type));
8037 break;
8038 case ISCSI_FLASHNODE_NAME:
8039 if (fnode_sess->targetname)
8040 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8041 else
8042 rc = sprintf(buf, "\n");
8043 break;
8044 case ISCSI_FLASHNODE_TPGT:
8045 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8046 break;
8047 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8048 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8049 break;
8050 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8051 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8052 break;
8053 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8054 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8055 break;
8056 case ISCSI_FLASHNODE_USERNAME:
8057 if (fnode_sess->chap_auth_en) {
8058 qla4xxx_get_uni_chap_at_index(ha,
8059 chap_tbl.name,
8060 chap_tbl.secret,
8061 fnode_sess->chap_out_idx);
8062 rc = sprintf(buf, "%s\n", chap_tbl.name);
8063 } else {
8064 rc = sprintf(buf, "\n");
8065 }
8066 break;
8067 case ISCSI_FLASHNODE_PASSWORD:
8068 if (fnode_sess->chap_auth_en) {
8069 qla4xxx_get_uni_chap_at_index(ha,
8070 chap_tbl.name,
8071 chap_tbl.secret,
8072 fnode_sess->chap_out_idx);
8073 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8074 } else {
8075 rc = sprintf(buf, "\n");
8076 }
8077 break;
8078 case ISCSI_FLASHNODE_STATSN:
8079 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8080 break;
8081 case ISCSI_FLASHNODE_EXP_STATSN:
8082 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8083 break;
8084 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8085 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8086 break;
8087 default:
8088 rc = -ENOSYS;
8089 break;
8090 }
8091
8092 put_device(dev);
8093 return rc;
8094 }
8095
8096 /**
8097 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8098 * @fnode_sess: pointer to session attrs of flash ddb entry
8099 * @fnode_conn: pointer to connection attrs of flash ddb entry
8100 * @data: Parameters and their values to update
8101 * @len: len of data
8102 *
8103 * This sets the parameter of flash ddb entry and writes them to flash
8104 **/
8105 static int
qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session * fnode_sess,struct iscsi_bus_flash_conn * fnode_conn,void * data,int len)8106 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8107 struct iscsi_bus_flash_conn *fnode_conn,
8108 void *data, int len)
8109 {
8110 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8111 struct scsi_qla_host *ha = to_qla_host(shost);
8112 struct iscsi_flashnode_param_info *fnode_param;
8113 struct ql4_chap_table chap_tbl;
8114 struct nlattr *attr;
8115 uint16_t chap_out_idx = INVALID_ENTRY;
8116 int rc = QLA_ERROR;
8117 uint32_t rem = len;
8118
8119 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8120 nla_for_each_attr(attr, data, len, rem) {
8121 if (nla_len(attr) < sizeof(*fnode_param)) {
8122 rc = -EINVAL;
8123 goto exit_set_param;
8124 }
8125
8126 fnode_param = nla_data(attr);
8127
8128 switch (fnode_param->param) {
8129 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8130 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8131 break;
8132 case ISCSI_FLASHNODE_PORTAL_TYPE:
8133 memcpy(fnode_sess->portal_type, fnode_param->value,
8134 strlen(fnode_sess->portal_type));
8135 break;
8136 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8137 fnode_sess->auto_snd_tgt_disable =
8138 fnode_param->value[0];
8139 break;
8140 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8141 fnode_sess->discovery_sess = fnode_param->value[0];
8142 break;
8143 case ISCSI_FLASHNODE_ENTRY_EN:
8144 fnode_sess->entry_state = fnode_param->value[0];
8145 break;
8146 case ISCSI_FLASHNODE_HDR_DGST_EN:
8147 fnode_conn->hdrdgst_en = fnode_param->value[0];
8148 break;
8149 case ISCSI_FLASHNODE_DATA_DGST_EN:
8150 fnode_conn->datadgst_en = fnode_param->value[0];
8151 break;
8152 case ISCSI_FLASHNODE_IMM_DATA_EN:
8153 fnode_sess->imm_data_en = fnode_param->value[0];
8154 break;
8155 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8156 fnode_sess->initial_r2t_en = fnode_param->value[0];
8157 break;
8158 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8159 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8160 break;
8161 case ISCSI_FLASHNODE_PDU_INORDER:
8162 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8163 break;
8164 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8165 fnode_sess->chap_auth_en = fnode_param->value[0];
8166 /* Invalidate chap index if chap auth is disabled */
8167 if (!fnode_sess->chap_auth_en)
8168 fnode_sess->chap_out_idx = INVALID_ENTRY;
8169
8170 break;
8171 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8172 fnode_conn->snack_req_en = fnode_param->value[0];
8173 break;
8174 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8175 fnode_sess->discovery_logout_en = fnode_param->value[0];
8176 break;
8177 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8178 fnode_sess->bidi_chap_en = fnode_param->value[0];
8179 break;
8180 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8181 fnode_sess->discovery_auth_optional =
8182 fnode_param->value[0];
8183 break;
8184 case ISCSI_FLASHNODE_ERL:
8185 fnode_sess->erl = fnode_param->value[0];
8186 break;
8187 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8188 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8189 break;
8190 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8191 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8192 break;
8193 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8194 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8195 break;
8196 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8197 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8198 break;
8199 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8200 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8201 break;
8202 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8203 fnode_conn->fragment_disable = fnode_param->value[0];
8204 break;
8205 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8206 fnode_conn->max_recv_dlength =
8207 *(unsigned *)fnode_param->value;
8208 break;
8209 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8210 fnode_conn->max_xmit_dlength =
8211 *(unsigned *)fnode_param->value;
8212 break;
8213 case ISCSI_FLASHNODE_FIRST_BURST:
8214 fnode_sess->first_burst =
8215 *(unsigned *)fnode_param->value;
8216 break;
8217 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8218 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8219 break;
8220 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8221 fnode_sess->time2retain =
8222 *(uint16_t *)fnode_param->value;
8223 break;
8224 case ISCSI_FLASHNODE_MAX_R2T:
8225 fnode_sess->max_r2t =
8226 *(uint16_t *)fnode_param->value;
8227 break;
8228 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8229 fnode_conn->keepalive_timeout =
8230 *(uint16_t *)fnode_param->value;
8231 break;
8232 case ISCSI_FLASHNODE_ISID:
8233 memcpy(fnode_sess->isid, fnode_param->value,
8234 sizeof(fnode_sess->isid));
8235 break;
8236 case ISCSI_FLASHNODE_TSID:
8237 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8238 break;
8239 case ISCSI_FLASHNODE_PORT:
8240 fnode_conn->port = *(uint16_t *)fnode_param->value;
8241 break;
8242 case ISCSI_FLASHNODE_MAX_BURST:
8243 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8244 break;
8245 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8246 fnode_sess->default_taskmgmt_timeout =
8247 *(uint16_t *)fnode_param->value;
8248 break;
8249 case ISCSI_FLASHNODE_IPADDR:
8250 memcpy(fnode_conn->ipaddress, fnode_param->value,
8251 IPv6_ADDR_LEN);
8252 break;
8253 case ISCSI_FLASHNODE_ALIAS:
8254 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8255 (char *)fnode_param->value);
8256 break;
8257 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8258 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8259 IPv6_ADDR_LEN);
8260 break;
8261 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8262 fnode_conn->max_segment_size =
8263 *(unsigned *)fnode_param->value;
8264 break;
8265 case ISCSI_FLASHNODE_LOCAL_PORT:
8266 fnode_conn->local_port =
8267 *(uint16_t *)fnode_param->value;
8268 break;
8269 case ISCSI_FLASHNODE_IPV4_TOS:
8270 fnode_conn->ipv4_tos = fnode_param->value[0];
8271 break;
8272 case ISCSI_FLASHNODE_IPV6_TC:
8273 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8274 break;
8275 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8276 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8277 break;
8278 case ISCSI_FLASHNODE_NAME:
8279 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8280 (char *)fnode_param->value);
8281 break;
8282 case ISCSI_FLASHNODE_TPGT:
8283 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8284 break;
8285 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8286 memcpy(fnode_conn->link_local_ipv6_addr,
8287 fnode_param->value, IPv6_ADDR_LEN);
8288 break;
8289 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8290 fnode_sess->discovery_parent_idx =
8291 *(uint16_t *)fnode_param->value;
8292 break;
8293 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8294 fnode_conn->tcp_xmit_wsf =
8295 *(uint8_t *)fnode_param->value;
8296 break;
8297 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8298 fnode_conn->tcp_recv_wsf =
8299 *(uint8_t *)fnode_param->value;
8300 break;
8301 case ISCSI_FLASHNODE_STATSN:
8302 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8303 break;
8304 case ISCSI_FLASHNODE_EXP_STATSN:
8305 fnode_conn->exp_statsn =
8306 *(uint32_t *)fnode_param->value;
8307 break;
8308 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8309 chap_out_idx = *(uint16_t *)fnode_param->value;
8310 if (!qla4xxx_get_uni_chap_at_index(ha,
8311 chap_tbl.name,
8312 chap_tbl.secret,
8313 chap_out_idx)) {
8314 fnode_sess->chap_out_idx = chap_out_idx;
8315 /* Enable chap auth if chap index is valid */
8316 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8317 }
8318 break;
8319 default:
8320 ql4_printk(KERN_ERR, ha,
8321 "%s: No such sysfs attribute\n", __func__);
8322 rc = -ENOSYS;
8323 goto exit_set_param;
8324 }
8325 }
8326
8327 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8328
8329 exit_set_param:
8330 return rc;
8331 }
8332
8333 /**
8334 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8335 * @fnode_sess: pointer to session attrs of flash ddb entry
8336 *
8337 * This invalidates the flash ddb entry at the given index
8338 **/
qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session * fnode_sess)8339 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8340 {
8341 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8342 struct scsi_qla_host *ha = to_qla_host(shost);
8343 uint32_t dev_db_start_offset;
8344 uint32_t dev_db_end_offset;
8345 struct dev_db_entry *fw_ddb_entry = NULL;
8346 dma_addr_t fw_ddb_entry_dma;
8347 uint16_t *ddb_cookie = NULL;
8348 size_t ddb_size = 0;
8349 void *pddb = NULL;
8350 int target_id;
8351 int rc = 0;
8352
8353 if (fnode_sess->is_boot_target) {
8354 rc = -EPERM;
8355 DEBUG2(ql4_printk(KERN_ERR, ha,
8356 "%s: Deletion of boot target entry is not permitted.\n",
8357 __func__));
8358 goto exit_ddb_del;
8359 }
8360
8361 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8362 goto sysfs_ddb_del;
8363
8364 if (is_qla40XX(ha)) {
8365 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8366 dev_db_end_offset = FLASH_OFFSET_DB_END;
8367 dev_db_start_offset += (fnode_sess->target_id *
8368 sizeof(*fw_ddb_entry));
8369 ddb_size = sizeof(*fw_ddb_entry);
8370 } else {
8371 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8372 (ha->hw.flt_region_ddb << 2);
8373 /* flt_ddb_size is DDB table size for both ports
8374 * so divide it by 2 to calculate the offset for second port
8375 */
8376 if (ha->port_num == 1)
8377 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8378
8379 dev_db_end_offset = dev_db_start_offset +
8380 (ha->hw.flt_ddb_size / 2);
8381
8382 dev_db_start_offset += (fnode_sess->target_id *
8383 sizeof(*fw_ddb_entry));
8384 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8385
8386 ddb_size = sizeof(*ddb_cookie);
8387 }
8388
8389 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8390 __func__, dev_db_start_offset, dev_db_end_offset));
8391
8392 if (dev_db_start_offset > dev_db_end_offset) {
8393 rc = -EIO;
8394 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8395 __func__, fnode_sess->target_id));
8396 goto exit_ddb_del;
8397 }
8398
8399 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8400 &fw_ddb_entry_dma, GFP_KERNEL);
8401 if (!pddb) {
8402 rc = -ENOMEM;
8403 DEBUG2(ql4_printk(KERN_ERR, ha,
8404 "%s: Unable to allocate dma buffer\n",
8405 __func__));
8406 goto exit_ddb_del;
8407 }
8408
8409 if (is_qla40XX(ha)) {
8410 fw_ddb_entry = pddb;
8411 memset(fw_ddb_entry, 0, ddb_size);
8412 ddb_cookie = &fw_ddb_entry->cookie;
8413 } else {
8414 ddb_cookie = pddb;
8415 }
8416
8417 /* invalidate the cookie */
8418 *ddb_cookie = 0xFFEE;
8419 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8420 ddb_size, FLASH_OPT_RMW_COMMIT);
8421
8422 sysfs_ddb_del:
8423 target_id = fnode_sess->target_id;
8424 iscsi_destroy_flashnode_sess(fnode_sess);
8425 ql4_printk(KERN_INFO, ha,
8426 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8427 __func__, target_id, ha->host_no);
8428 exit_ddb_del:
8429 if (pddb)
8430 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8431 fw_ddb_entry_dma);
8432 return rc;
8433 }
8434
8435 /**
8436 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8437 * @ha: pointer to adapter structure
8438 *
8439 * Export the firmware DDB for all send targets and normal targets to sysfs.
8440 **/
qla4xxx_sysfs_ddb_export(struct scsi_qla_host * ha)8441 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8442 {
8443 struct dev_db_entry *fw_ddb_entry = NULL;
8444 dma_addr_t fw_ddb_entry_dma;
8445 uint16_t max_ddbs;
8446 uint16_t idx = 0;
8447 int ret = QLA_SUCCESS;
8448
8449 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8450 sizeof(*fw_ddb_entry),
8451 &fw_ddb_entry_dma, GFP_KERNEL);
8452 if (!fw_ddb_entry) {
8453 DEBUG2(ql4_printk(KERN_ERR, ha,
8454 "%s: Unable to allocate dma buffer\n",
8455 __func__));
8456 return -ENOMEM;
8457 }
8458
8459 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8460 MAX_DEV_DB_ENTRIES;
8461
8462 for (idx = 0; idx < max_ddbs; idx++) {
8463 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8464 idx))
8465 continue;
8466
8467 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8468 if (ret) {
8469 ret = -EIO;
8470 break;
8471 }
8472 }
8473
8474 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8475 fw_ddb_entry_dma);
8476
8477 return ret;
8478 }
8479
qla4xxx_sysfs_ddb_remove(struct scsi_qla_host * ha)8480 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8481 {
8482 iscsi_destroy_all_flashnode(ha->host);
8483 }
8484
8485 /**
8486 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8487 * @ha: pointer to adapter structure
8488 * @is_reset: Is this init path or reset path
8489 *
8490 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8491 * using connection open, then create the list of normal targets (nt)
8492 * from firmware DDBs. Based on the list of nt setup session and connection
8493 * objects.
8494 **/
qla4xxx_build_ddb_list(struct scsi_qla_host * ha,int is_reset)8495 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8496 {
8497 uint16_t tmo = 0;
8498 struct list_head list_st, list_nt;
8499 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8500 unsigned long wtime;
8501
8502 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8503 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8504 ha->is_reset = is_reset;
8505 return;
8506 }
8507
8508 INIT_LIST_HEAD(&list_st);
8509 INIT_LIST_HEAD(&list_nt);
8510
8511 qla4xxx_build_st_list(ha, &list_st);
8512
8513 /* Before issuing conn open mbox, ensure all IPs states are configured
8514 * Note, conn open fails if IPs are not configured
8515 */
8516 qla4xxx_wait_for_ip_configuration(ha);
8517
8518 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8519 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8520 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8521 }
8522
8523 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8524 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8525 (ha->def_timeout < LOGIN_TOV * 10) ?
8526 ha->def_timeout : LOGIN_TOV);
8527
8528 DEBUG2(ql4_printk(KERN_INFO, ha,
8529 "Default time to wait for build ddb %d\n", tmo));
8530
8531 wtime = jiffies + (HZ * tmo);
8532 do {
8533 if (list_empty(&list_st))
8534 break;
8535
8536 qla4xxx_remove_failed_ddb(ha, &list_st);
8537 schedule_timeout_uninterruptible(HZ / 10);
8538 } while (time_after(wtime, jiffies));
8539
8540
8541 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8542
8543 qla4xxx_free_ddb_list(&list_st);
8544 qla4xxx_free_ddb_list(&list_nt);
8545
8546 qla4xxx_free_ddb_index(ha);
8547 }
8548
8549 /**
8550 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8551 * response.
8552 * @ha: pointer to adapter structure
8553 *
8554 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8555 * set in DDB and we will wait for login response of boot targets during
8556 * probe.
8557 **/
qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host * ha)8558 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8559 {
8560 struct ddb_entry *ddb_entry;
8561 struct dev_db_entry *fw_ddb_entry = NULL;
8562 dma_addr_t fw_ddb_entry_dma;
8563 unsigned long wtime;
8564 uint32_t ddb_state;
8565 int max_ddbs, idx, ret;
8566
8567 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8568 MAX_DEV_DB_ENTRIES;
8569
8570 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8571 &fw_ddb_entry_dma, GFP_KERNEL);
8572 if (!fw_ddb_entry) {
8573 ql4_printk(KERN_ERR, ha,
8574 "%s: Unable to allocate dma buffer\n", __func__);
8575 goto exit_login_resp;
8576 }
8577
8578 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8579
8580 for (idx = 0; idx < max_ddbs; idx++) {
8581 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8582 if (ddb_entry == NULL)
8583 continue;
8584
8585 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8586 DEBUG2(ql4_printk(KERN_INFO, ha,
8587 "%s: DDB index [%d]\n", __func__,
8588 ddb_entry->fw_ddb_index));
8589 do {
8590 ret = qla4xxx_get_fwddb_entry(ha,
8591 ddb_entry->fw_ddb_index,
8592 fw_ddb_entry, fw_ddb_entry_dma,
8593 NULL, NULL, &ddb_state, NULL,
8594 NULL, NULL);
8595 if (ret == QLA_ERROR)
8596 goto exit_login_resp;
8597
8598 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8599 (ddb_state == DDB_DS_SESSION_FAILED))
8600 break;
8601
8602 schedule_timeout_uninterruptible(HZ);
8603
8604 } while ((time_after(wtime, jiffies)));
8605
8606 if (!time_after(wtime, jiffies)) {
8607 DEBUG2(ql4_printk(KERN_INFO, ha,
8608 "%s: Login response wait timer expired\n",
8609 __func__));
8610 goto exit_login_resp;
8611 }
8612 }
8613 }
8614
8615 exit_login_resp:
8616 if (fw_ddb_entry)
8617 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8618 fw_ddb_entry, fw_ddb_entry_dma);
8619 }
8620
8621 /**
8622 * qla4xxx_probe_adapter - callback function to probe HBA
8623 * @pdev: pointer to pci_dev structure
8624 * @ent: pointer to pci_device entry
8625 *
8626 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8627 * It returns zero if successful. It also initializes all data necessary for
8628 * the driver.
8629 **/
qla4xxx_probe_adapter(struct pci_dev * pdev,const struct pci_device_id * ent)8630 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8631 const struct pci_device_id *ent)
8632 {
8633 int ret = -ENODEV, status;
8634 struct Scsi_Host *host;
8635 struct scsi_qla_host *ha;
8636 uint8_t init_retry_count = 0;
8637 char buf[34];
8638 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8639 uint32_t dev_state;
8640
8641 if (pci_enable_device(pdev))
8642 return -1;
8643
8644 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8645 if (host == NULL) {
8646 printk(KERN_WARNING
8647 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8648 goto probe_disable_device;
8649 }
8650
8651 /* Clear our data area */
8652 ha = to_qla_host(host);
8653 memset(ha, 0, sizeof(*ha));
8654
8655 /* Save the information from PCI BIOS. */
8656 ha->pdev = pdev;
8657 ha->host = host;
8658 ha->host_no = host->host_no;
8659 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8660
8661 /* Setup Runtime configurable options */
8662 if (is_qla8022(ha)) {
8663 ha->isp_ops = &qla4_82xx_isp_ops;
8664 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8665 ha->qdr_sn_window = -1;
8666 ha->ddr_mn_window = -1;
8667 ha->curr_window = 255;
8668 nx_legacy_intr = &legacy_intr[ha->func_num];
8669 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8670 ha->nx_legacy_intr.tgt_status_reg =
8671 nx_legacy_intr->tgt_status_reg;
8672 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8673 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8674 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8675 ha->isp_ops = &qla4_83xx_isp_ops;
8676 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8677 } else {
8678 ha->isp_ops = &qla4xxx_isp_ops;
8679 }
8680
8681 if (is_qla80XX(ha)) {
8682 rwlock_init(&ha->hw_lock);
8683 ha->pf_bit = ha->func_num << 16;
8684 /* Set EEH reset type to fundamental if required by hba */
8685 pdev->needs_freset = 1;
8686 }
8687
8688 /* Configure PCI I/O space. */
8689 ret = ha->isp_ops->iospace_config(ha);
8690 if (ret)
8691 goto probe_failed_ioconfig;
8692
8693 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8694 pdev->device, pdev->irq, ha->reg);
8695
8696 qla4xxx_config_dma_addressing(ha);
8697
8698 /* Initialize lists and spinlocks. */
8699 INIT_LIST_HEAD(&ha->free_srb_q);
8700
8701 mutex_init(&ha->mbox_sem);
8702 mutex_init(&ha->chap_sem);
8703 init_completion(&ha->mbx_intr_comp);
8704 init_completion(&ha->disable_acb_comp);
8705 init_completion(&ha->idc_comp);
8706 init_completion(&ha->link_up_comp);
8707
8708 spin_lock_init(&ha->hardware_lock);
8709 spin_lock_init(&ha->work_lock);
8710
8711 /* Initialize work list */
8712 INIT_LIST_HEAD(&ha->work_list);
8713
8714 /* Allocate dma buffers */
8715 if (qla4xxx_mem_alloc(ha)) {
8716 ql4_printk(KERN_WARNING, ha,
8717 "[ERROR] Failed to allocate memory for adapter\n");
8718
8719 ret = -ENOMEM;
8720 goto probe_failed;
8721 }
8722
8723 host->cmd_per_lun = 3;
8724 host->max_channel = 0;
8725 host->max_lun = MAX_LUNS - 1;
8726 host->max_id = MAX_TARGETS;
8727 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8728 host->can_queue = MAX_SRBS ;
8729 host->transportt = qla4xxx_scsi_transport;
8730
8731 pci_set_drvdata(pdev, ha);
8732
8733 ret = scsi_add_host(host, &pdev->dev);
8734 if (ret)
8735 goto probe_failed;
8736
8737 if (is_qla80XX(ha))
8738 qla4_8xxx_get_flash_info(ha);
8739
8740 if (is_qla8032(ha) || is_qla8042(ha)) {
8741 qla4_83xx_read_reset_template(ha);
8742 /*
8743 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8744 * If DONRESET_BIT0 is set, drivers should not set dev_state
8745 * to NEED_RESET. But if NEED_RESET is set, drivers should
8746 * should honor the reset.
8747 */
8748 if (ql4xdontresethba == 1)
8749 qla4_83xx_set_idc_dontreset(ha);
8750 }
8751
8752 /*
8753 * Initialize the Host adapter request/response queues and
8754 * firmware
8755 * NOTE: interrupts enabled upon successful completion
8756 */
8757 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8758
8759 /* Dont retry adapter initialization if IRQ allocation failed */
8760 if (is_qla80XX(ha) && (status == QLA_ERROR))
8761 goto skip_retry_init;
8762
8763 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8764 init_retry_count++ < MAX_INIT_RETRIES) {
8765
8766 if (is_qla80XX(ha)) {
8767 ha->isp_ops->idc_lock(ha);
8768 dev_state = qla4_8xxx_rd_direct(ha,
8769 QLA8XXX_CRB_DEV_STATE);
8770 ha->isp_ops->idc_unlock(ha);
8771 if (dev_state == QLA8XXX_DEV_FAILED) {
8772 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8773 "initialize adapter. H/W is in failed state\n",
8774 __func__);
8775 break;
8776 }
8777 }
8778 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8779 "(%d)\n", __func__, init_retry_count));
8780
8781 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8782 continue;
8783
8784 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8785 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8786 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8787 goto skip_retry_init;
8788 }
8789 }
8790
8791 skip_retry_init:
8792 if (!test_bit(AF_ONLINE, &ha->flags)) {
8793 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8794
8795 if ((is_qla8022(ha) && ql4xdontresethba) ||
8796 ((is_qla8032(ha) || is_qla8042(ha)) &&
8797 qla4_83xx_idc_dontreset(ha))) {
8798 /* Put the device in failed state. */
8799 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8800 ha->isp_ops->idc_lock(ha);
8801 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8802 QLA8XXX_DEV_FAILED);
8803 ha->isp_ops->idc_unlock(ha);
8804 }
8805 ret = -ENODEV;
8806 goto remove_host;
8807 }
8808
8809 /* Startup the kernel thread for this host adapter. */
8810 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8811 "qla4xxx_dpc\n", __func__));
8812 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8813 ha->dpc_thread = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, buf);
8814 if (!ha->dpc_thread) {
8815 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8816 ret = -ENODEV;
8817 goto remove_host;
8818 }
8819 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8820
8821 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8822 ha->host_no);
8823 if (!ha->task_wq) {
8824 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8825 ret = -ENODEV;
8826 goto remove_host;
8827 }
8828
8829 /*
8830 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8831 * (which is called indirectly by qla4xxx_initialize_adapter),
8832 * so that irqs will be registered after crbinit but before
8833 * mbx_intr_enable.
8834 */
8835 if (is_qla40XX(ha)) {
8836 ret = qla4xxx_request_irqs(ha);
8837 if (ret) {
8838 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8839 "interrupt %d already in use.\n", pdev->irq);
8840 goto remove_host;
8841 }
8842 }
8843
8844 pci_save_state(ha->pdev);
8845 ha->isp_ops->enable_intrs(ha);
8846
8847 /* Start timer thread. */
8848 qla4xxx_start_timer(ha, 1);
8849
8850 set_bit(AF_INIT_DONE, &ha->flags);
8851
8852 qla4_8xxx_alloc_sysfs_attr(ha);
8853
8854 printk(KERN_INFO
8855 " QLogic iSCSI HBA Driver version: %s\n"
8856 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8857 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8858 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8859 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8860
8861 /* Set the driver version */
8862 if (is_qla80XX(ha))
8863 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8864
8865 if (qla4xxx_setup_boot_info(ha))
8866 ql4_printk(KERN_ERR, ha,
8867 "%s: No iSCSI boot target configured\n", __func__);
8868
8869 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8870 /* Perform the build ddb list and login to each */
8871 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8872 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8873 qla4xxx_wait_login_resp_boot_tgt(ha);
8874
8875 qla4xxx_create_chap_list(ha);
8876
8877 qla4xxx_create_ifaces(ha);
8878 return 0;
8879
8880 remove_host:
8881 scsi_remove_host(ha->host);
8882
8883 probe_failed:
8884 qla4xxx_free_adapter(ha);
8885
8886 probe_failed_ioconfig:
8887 scsi_host_put(ha->host);
8888
8889 probe_disable_device:
8890 pci_disable_device(pdev);
8891
8892 return ret;
8893 }
8894
8895 /**
8896 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8897 * @ha: pointer to adapter structure
8898 *
8899 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8900 * so that the other port will not re-initialize while in the process of
8901 * removing the ha due to driver unload or hba hotplug.
8902 **/
qla4xxx_prevent_other_port_reinit(struct scsi_qla_host * ha)8903 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8904 {
8905 struct scsi_qla_host *other_ha = NULL;
8906 struct pci_dev *other_pdev = NULL;
8907 int fn = ISP4XXX_PCI_FN_2;
8908
8909 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8910 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8911 fn = ISP4XXX_PCI_FN_1;
8912
8913 other_pdev =
8914 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8915 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8916 fn));
8917
8918 /* Get other_ha if other_pdev is valid and state is enable*/
8919 if (other_pdev) {
8920 if (atomic_read(&other_pdev->enable_cnt)) {
8921 other_ha = pci_get_drvdata(other_pdev);
8922 if (other_ha) {
8923 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8924 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8925 "Prevent %s reinit\n", __func__,
8926 dev_name(&other_ha->pdev->dev)));
8927 }
8928 }
8929 pci_dev_put(other_pdev);
8930 }
8931 }
8932
qla4xxx_destroy_ddb(struct scsi_qla_host * ha,struct ddb_entry * ddb_entry)8933 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8934 struct ddb_entry *ddb_entry)
8935 {
8936 struct dev_db_entry *fw_ddb_entry = NULL;
8937 dma_addr_t fw_ddb_entry_dma;
8938 unsigned long wtime;
8939 uint32_t ddb_state;
8940 int options;
8941 int status;
8942
8943 options = LOGOUT_OPTION_CLOSE_SESSION;
8944 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8945 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8946 goto clear_ddb;
8947 }
8948
8949 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8950 &fw_ddb_entry_dma, GFP_KERNEL);
8951 if (!fw_ddb_entry) {
8952 ql4_printk(KERN_ERR, ha,
8953 "%s: Unable to allocate dma buffer\n", __func__);
8954 goto clear_ddb;
8955 }
8956
8957 wtime = jiffies + (HZ * LOGOUT_TOV);
8958 do {
8959 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8960 fw_ddb_entry, fw_ddb_entry_dma,
8961 NULL, NULL, &ddb_state, NULL,
8962 NULL, NULL);
8963 if (status == QLA_ERROR)
8964 goto free_ddb;
8965
8966 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8967 (ddb_state == DDB_DS_SESSION_FAILED))
8968 goto free_ddb;
8969
8970 schedule_timeout_uninterruptible(HZ);
8971 } while ((time_after(wtime, jiffies)));
8972
8973 free_ddb:
8974 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8975 fw_ddb_entry, fw_ddb_entry_dma);
8976 clear_ddb:
8977 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8978 }
8979
qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host * ha)8980 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8981 {
8982 struct ddb_entry *ddb_entry;
8983 int idx;
8984
8985 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8986
8987 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8988 if ((ddb_entry != NULL) &&
8989 (ddb_entry->ddb_type == FLASH_DDB)) {
8990
8991 qla4xxx_destroy_ddb(ha, ddb_entry);
8992 /*
8993 * we have decremented the reference count of the driver
8994 * when we setup the session to have the driver unload
8995 * to be seamless without actually destroying the
8996 * session
8997 **/
8998 try_module_get(qla4xxx_iscsi_transport.owner);
8999 iscsi_destroy_endpoint(ddb_entry->conn->ep);
9000 qla4xxx_free_ddb(ha, ddb_entry);
9001 iscsi_session_teardown(ddb_entry->sess);
9002 }
9003 }
9004 }
9005 /**
9006 * qla4xxx_remove_adapter - callback function to remove adapter.
9007 * @pdev: PCI device pointer
9008 **/
qla4xxx_remove_adapter(struct pci_dev * pdev)9009 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
9010 {
9011 struct scsi_qla_host *ha;
9012
9013 /*
9014 * If the PCI device is disabled then it means probe_adapter had
9015 * failed and resources already cleaned up on probe_adapter exit.
9016 */
9017 if (!pci_is_enabled(pdev))
9018 return;
9019
9020 ha = pci_get_drvdata(pdev);
9021
9022 if (is_qla40XX(ha))
9023 qla4xxx_prevent_other_port_reinit(ha);
9024
9025 /* destroy iface from sysfs */
9026 qla4xxx_destroy_ifaces(ha);
9027
9028 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9029 iscsi_boot_destroy_kset(ha->boot_kset);
9030
9031 qla4xxx_destroy_fw_ddb_session(ha);
9032 qla4_8xxx_free_sysfs_attr(ha);
9033
9034 qla4xxx_sysfs_ddb_remove(ha);
9035 scsi_remove_host(ha->host);
9036
9037 qla4xxx_free_adapter(ha);
9038
9039 scsi_host_put(ha->host);
9040
9041 pci_disable_device(pdev);
9042 }
9043
9044 /**
9045 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9046 * @ha: HA context
9047 */
qla4xxx_config_dma_addressing(struct scsi_qla_host * ha)9048 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9049 {
9050 /* Update our PCI device dma_mask for full 64 bit mask */
9051 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9052 dev_dbg(&ha->pdev->dev,
9053 "Failed to set 64 bit PCI consistent mask; "
9054 "using 32 bit.\n");
9055 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9056 }
9057 }
9058
qla4xxx_slave_alloc(struct scsi_device * sdev)9059 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9060 {
9061 struct iscsi_cls_session *cls_sess;
9062 struct iscsi_session *sess;
9063 struct ddb_entry *ddb;
9064 int queue_depth = QL4_DEF_QDEPTH;
9065
9066 cls_sess = starget_to_session(sdev->sdev_target);
9067 sess = cls_sess->dd_data;
9068 ddb = sess->dd_data;
9069
9070 sdev->hostdata = ddb;
9071
9072 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9073 queue_depth = ql4xmaxqdepth;
9074
9075 scsi_change_queue_depth(sdev, queue_depth);
9076 return 0;
9077 }
9078
9079 /**
9080 * qla4xxx_del_from_active_array - returns an active srb
9081 * @ha: Pointer to host adapter structure.
9082 * @index: index into the active_array
9083 *
9084 * This routine removes and returns the srb at the specified index
9085 **/
qla4xxx_del_from_active_array(struct scsi_qla_host * ha,uint32_t index)9086 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9087 uint32_t index)
9088 {
9089 struct srb *srb = NULL;
9090 struct scsi_cmnd *cmd = NULL;
9091
9092 cmd = scsi_host_find_tag(ha->host, index);
9093 if (!cmd)
9094 return srb;
9095
9096 srb = qla4xxx_cmd_priv(cmd)->srb;
9097 if (!srb)
9098 return srb;
9099
9100 /* update counters */
9101 if (srb->flags & SRB_DMA_VALID) {
9102 ha->iocb_cnt -= srb->iocb_cnt;
9103 if (srb->cmd)
9104 srb->cmd->host_scribble =
9105 (unsigned char *)(unsigned long) MAX_SRBS;
9106 }
9107 return srb;
9108 }
9109
9110 /**
9111 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9112 * @ha: Pointer to host adapter structure.
9113 * @cmd: Scsi Command to wait on.
9114 *
9115 * This routine waits for the command to be returned by the Firmware
9116 * for some max time.
9117 **/
qla4xxx_eh_wait_on_command(struct scsi_qla_host * ha,struct scsi_cmnd * cmd)9118 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9119 struct scsi_cmnd *cmd)
9120 {
9121 int done = 0;
9122 struct srb *rp;
9123 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9124 int ret = SUCCESS;
9125
9126 /* Dont wait on command if PCI error is being handled
9127 * by PCI AER driver
9128 */
9129 if (unlikely(pci_channel_offline(ha->pdev)) ||
9130 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9131 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9132 ha->host_no, __func__);
9133 return ret;
9134 }
9135
9136 do {
9137 /* Checking to see if its returned to OS */
9138 rp = qla4xxx_cmd_priv(cmd)->srb;
9139 if (rp == NULL) {
9140 done++;
9141 break;
9142 }
9143
9144 msleep(2000);
9145 } while (max_wait_time--);
9146
9147 return done;
9148 }
9149
9150 /**
9151 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9152 * @ha: Pointer to host adapter structure
9153 **/
qla4xxx_wait_for_hba_online(struct scsi_qla_host * ha)9154 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9155 {
9156 unsigned long wait_online;
9157
9158 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9159 while (time_before(jiffies, wait_online)) {
9160
9161 if (adapter_up(ha))
9162 return QLA_SUCCESS;
9163
9164 msleep(2000);
9165 }
9166
9167 return QLA_ERROR;
9168 }
9169
9170 /**
9171 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9172 * @ha: pointer to HBA
9173 * @stgt: pointer to SCSI target
9174 * @sdev: pointer to SCSI device
9175 *
9176 * This function waits for all outstanding commands to a lun to complete. It
9177 * returns 0 if all pending commands are returned and 1 otherwise.
9178 **/
qla4xxx_eh_wait_for_commands(struct scsi_qla_host * ha,struct scsi_target * stgt,struct scsi_device * sdev)9179 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9180 struct scsi_target *stgt,
9181 struct scsi_device *sdev)
9182 {
9183 int cnt;
9184 int status = 0;
9185 struct scsi_cmnd *cmd;
9186
9187 /*
9188 * Waiting for all commands for the designated target or dev
9189 * in the active array
9190 */
9191 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9192 cmd = scsi_host_find_tag(ha->host, cnt);
9193 if (cmd && stgt == scsi_target(cmd->device) &&
9194 (!sdev || sdev == cmd->device)) {
9195 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9196 status++;
9197 break;
9198 }
9199 }
9200 }
9201 return status;
9202 }
9203
9204 /**
9205 * qla4xxx_eh_abort - callback for abort task.
9206 * @cmd: Pointer to Linux's SCSI command structure
9207 *
9208 * This routine is called by the Linux OS to abort the specified
9209 * command.
9210 **/
qla4xxx_eh_abort(struct scsi_cmnd * cmd)9211 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9212 {
9213 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9214 unsigned int id = cmd->device->id;
9215 uint64_t lun = cmd->device->lun;
9216 unsigned long flags;
9217 struct srb *srb = NULL;
9218 int ret = SUCCESS;
9219 int wait = 0;
9220 int rval;
9221
9222 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9223 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9224
9225 rval = qla4xxx_isp_check_reg(ha);
9226 if (rval != QLA_SUCCESS) {
9227 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9228 return FAILED;
9229 }
9230
9231 spin_lock_irqsave(&ha->hardware_lock, flags);
9232 srb = qla4xxx_cmd_priv(cmd)->srb;
9233 if (!srb) {
9234 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9235 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9236 ha->host_no, id, lun);
9237 return SUCCESS;
9238 }
9239 kref_get(&srb->srb_ref);
9240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9241
9242 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9243 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9244 ha->host_no, id, lun));
9245 ret = FAILED;
9246 } else {
9247 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9248 ha->host_no, id, lun));
9249 wait = 1;
9250 }
9251
9252 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9253
9254 /* Wait for command to complete */
9255 if (wait) {
9256 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9257 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9258 ha->host_no, id, lun));
9259 ret = FAILED;
9260 }
9261 }
9262
9263 ql4_printk(KERN_INFO, ha,
9264 "scsi%ld:%d:%llu: Abort command - %s\n",
9265 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9266
9267 return ret;
9268 }
9269
9270 /**
9271 * qla4xxx_eh_device_reset - callback for target reset.
9272 * @cmd: Pointer to Linux's SCSI command structure
9273 *
9274 * This routine is called by the Linux OS to reset all luns on the
9275 * specified target.
9276 **/
qla4xxx_eh_device_reset(struct scsi_cmnd * cmd)9277 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9278 {
9279 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9280 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9281 int ret = FAILED, stat;
9282 int rval;
9283
9284 if (!ddb_entry)
9285 return ret;
9286
9287 ret = iscsi_block_scsi_eh(cmd);
9288 if (ret)
9289 return ret;
9290 ret = FAILED;
9291
9292 ql4_printk(KERN_INFO, ha,
9293 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9294 cmd->device->channel, cmd->device->id, cmd->device->lun);
9295
9296 DEBUG2(printk(KERN_INFO
9297 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9298 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9299 cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9300 ha->dpc_flags, cmd->result, cmd->allowed));
9301
9302 rval = qla4xxx_isp_check_reg(ha);
9303 if (rval != QLA_SUCCESS) {
9304 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9305 return FAILED;
9306 }
9307
9308 /* FIXME: wait for hba to go online */
9309 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9310 if (stat != QLA_SUCCESS) {
9311 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9312 goto eh_dev_reset_done;
9313 }
9314
9315 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9316 cmd->device)) {
9317 ql4_printk(KERN_INFO, ha,
9318 "DEVICE RESET FAILED - waiting for "
9319 "commands.\n");
9320 goto eh_dev_reset_done;
9321 }
9322
9323 /* Send marker. */
9324 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9325 MM_LUN_RESET) != QLA_SUCCESS)
9326 goto eh_dev_reset_done;
9327
9328 ql4_printk(KERN_INFO, ha,
9329 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9330 ha->host_no, cmd->device->channel, cmd->device->id,
9331 cmd->device->lun);
9332
9333 ret = SUCCESS;
9334
9335 eh_dev_reset_done:
9336
9337 return ret;
9338 }
9339
9340 /**
9341 * qla4xxx_eh_target_reset - callback for target reset.
9342 * @cmd: Pointer to Linux's SCSI command structure
9343 *
9344 * This routine is called by the Linux OS to reset the target.
9345 **/
qla4xxx_eh_target_reset(struct scsi_cmnd * cmd)9346 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9347 {
9348 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9349 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9350 int stat, ret;
9351 int rval;
9352
9353 if (!ddb_entry)
9354 return FAILED;
9355
9356 ret = iscsi_block_scsi_eh(cmd);
9357 if (ret)
9358 return ret;
9359
9360 starget_printk(KERN_INFO, scsi_target(cmd->device),
9361 "WARM TARGET RESET ISSUED.\n");
9362
9363 DEBUG2(printk(KERN_INFO
9364 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9365 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9366 ha->host_no, cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9367 ha->dpc_flags, cmd->result, cmd->allowed));
9368
9369 rval = qla4xxx_isp_check_reg(ha);
9370 if (rval != QLA_SUCCESS) {
9371 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9372 return FAILED;
9373 }
9374
9375 stat = qla4xxx_reset_target(ha, ddb_entry);
9376 if (stat != QLA_SUCCESS) {
9377 starget_printk(KERN_INFO, scsi_target(cmd->device),
9378 "WARM TARGET RESET FAILED.\n");
9379 return FAILED;
9380 }
9381
9382 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9383 NULL)) {
9384 starget_printk(KERN_INFO, scsi_target(cmd->device),
9385 "WARM TARGET DEVICE RESET FAILED - "
9386 "waiting for commands.\n");
9387 return FAILED;
9388 }
9389
9390 /* Send marker. */
9391 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9392 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9393 starget_printk(KERN_INFO, scsi_target(cmd->device),
9394 "WARM TARGET DEVICE RESET FAILED - "
9395 "marker iocb failed.\n");
9396 return FAILED;
9397 }
9398
9399 starget_printk(KERN_INFO, scsi_target(cmd->device),
9400 "WARM TARGET RESET SUCCEEDED.\n");
9401 return SUCCESS;
9402 }
9403
9404 /**
9405 * qla4xxx_is_eh_active - check if error handler is running
9406 * @shost: Pointer to SCSI Host struct
9407 *
9408 * This routine finds that if reset host is called in EH
9409 * scenario or from some application like sg_reset
9410 **/
qla4xxx_is_eh_active(struct Scsi_Host * shost)9411 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9412 {
9413 if (shost->shost_state == SHOST_RECOVERY)
9414 return 1;
9415 return 0;
9416 }
9417
9418 /**
9419 * qla4xxx_eh_host_reset - kernel callback
9420 * @cmd: Pointer to Linux's SCSI command structure
9421 *
9422 * This routine is invoked by the Linux kernel to perform fatal error
9423 * recovery on the specified adapter.
9424 **/
qla4xxx_eh_host_reset(struct scsi_cmnd * cmd)9425 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9426 {
9427 int return_status = FAILED;
9428 struct scsi_qla_host *ha;
9429 int rval;
9430
9431 ha = to_qla_host(cmd->device->host);
9432
9433 rval = qla4xxx_isp_check_reg(ha);
9434 if (rval != QLA_SUCCESS) {
9435 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9436 return FAILED;
9437 }
9438
9439 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9440 qla4_83xx_set_idc_dontreset(ha);
9441
9442 /*
9443 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9444 * protocol drivers, we should not set device_state to NEED_RESET
9445 */
9446 if (ql4xdontresethba ||
9447 ((is_qla8032(ha) || is_qla8042(ha)) &&
9448 qla4_83xx_idc_dontreset(ha))) {
9449 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9450 ha->host_no, __func__));
9451
9452 /* Clear outstanding srb in queues */
9453 if (qla4xxx_is_eh_active(cmd->device->host))
9454 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9455
9456 return FAILED;
9457 }
9458
9459 ql4_printk(KERN_INFO, ha,
9460 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9461 cmd->device->channel, cmd->device->id, cmd->device->lun);
9462
9463 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9464 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9465 "DEAD.\n", ha->host_no, cmd->device->channel,
9466 __func__));
9467
9468 return FAILED;
9469 }
9470
9471 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9472 if (is_qla80XX(ha))
9473 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9474 else
9475 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9476 }
9477
9478 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9479 return_status = SUCCESS;
9480
9481 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9482 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9483
9484 return return_status;
9485 }
9486
qla4xxx_context_reset(struct scsi_qla_host * ha)9487 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9488 {
9489 uint32_t mbox_cmd[MBOX_REG_COUNT];
9490 uint32_t mbox_sts[MBOX_REG_COUNT];
9491 struct addr_ctrl_blk_def *acb = NULL;
9492 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9493 int rval = QLA_SUCCESS;
9494 dma_addr_t acb_dma;
9495
9496 acb = dma_alloc_coherent(&ha->pdev->dev,
9497 sizeof(struct addr_ctrl_blk_def),
9498 &acb_dma, GFP_KERNEL);
9499 if (!acb) {
9500 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9501 __func__);
9502 rval = -ENOMEM;
9503 goto exit_port_reset;
9504 }
9505
9506 memset(acb, 0, acb_len);
9507
9508 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9509 if (rval != QLA_SUCCESS) {
9510 rval = -EIO;
9511 goto exit_free_acb;
9512 }
9513
9514 rval = qla4xxx_disable_acb(ha);
9515 if (rval != QLA_SUCCESS) {
9516 rval = -EIO;
9517 goto exit_free_acb;
9518 }
9519
9520 wait_for_completion_timeout(&ha->disable_acb_comp,
9521 DISABLE_ACB_TOV * HZ);
9522
9523 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9524 if (rval != QLA_SUCCESS) {
9525 rval = -EIO;
9526 goto exit_free_acb;
9527 }
9528
9529 exit_free_acb:
9530 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9531 acb, acb_dma);
9532 exit_port_reset:
9533 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9534 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9535 return rval;
9536 }
9537
qla4xxx_host_reset(struct Scsi_Host * shost,int reset_type)9538 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9539 {
9540 struct scsi_qla_host *ha = to_qla_host(shost);
9541 int rval = QLA_SUCCESS;
9542 uint32_t idc_ctrl;
9543
9544 if (ql4xdontresethba) {
9545 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9546 __func__));
9547 rval = -EPERM;
9548 goto exit_host_reset;
9549 }
9550
9551 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9552 goto recover_adapter;
9553
9554 switch (reset_type) {
9555 case SCSI_ADAPTER_RESET:
9556 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9557 break;
9558 case SCSI_FIRMWARE_RESET:
9559 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9560 if (is_qla80XX(ha))
9561 /* set firmware context reset */
9562 set_bit(DPC_RESET_HA_FW_CONTEXT,
9563 &ha->dpc_flags);
9564 else {
9565 rval = qla4xxx_context_reset(ha);
9566 goto exit_host_reset;
9567 }
9568 }
9569 break;
9570 }
9571
9572 recover_adapter:
9573 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9574 * reset is issued by application */
9575 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9576 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9577 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9578 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9579 (idc_ctrl | GRACEFUL_RESET_BIT1));
9580 }
9581
9582 rval = qla4xxx_recover_adapter(ha);
9583 if (rval != QLA_SUCCESS) {
9584 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9585 __func__));
9586 rval = -EIO;
9587 }
9588
9589 exit_host_reset:
9590 return rval;
9591 }
9592
9593 /* PCI AER driver recovers from all correctable errors w/o
9594 * driver intervention. For uncorrectable errors PCI AER
9595 * driver calls the following device driver's callbacks
9596 *
9597 * - Fatal Errors - link_reset
9598 * - Non-Fatal Errors - driver's error_detected() which
9599 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9600 *
9601 * PCI AER driver calls
9602 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9603 * returns RECOVERED or NEED_RESET if fw_hung
9604 * NEED_RESET - driver's slot_reset()
9605 * DISCONNECT - device is dead & cannot recover
9606 * RECOVERED - driver's resume()
9607 */
9608 static pci_ers_result_t
qla4xxx_pci_error_detected(struct pci_dev * pdev,pci_channel_state_t state)9609 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9610 {
9611 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9612
9613 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9614 ha->host_no, __func__, state);
9615
9616 if (!is_aer_supported(ha))
9617 return PCI_ERS_RESULT_NONE;
9618
9619 switch (state) {
9620 case pci_channel_io_normal:
9621 clear_bit(AF_EEH_BUSY, &ha->flags);
9622 return PCI_ERS_RESULT_CAN_RECOVER;
9623 case pci_channel_io_frozen:
9624 set_bit(AF_EEH_BUSY, &ha->flags);
9625 qla4xxx_mailbox_premature_completion(ha);
9626 qla4xxx_free_irqs(ha);
9627 pci_disable_device(pdev);
9628 /* Return back all IOs */
9629 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9630 return PCI_ERS_RESULT_NEED_RESET;
9631 case pci_channel_io_perm_failure:
9632 set_bit(AF_EEH_BUSY, &ha->flags);
9633 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9634 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9635 return PCI_ERS_RESULT_DISCONNECT;
9636 }
9637 return PCI_ERS_RESULT_NEED_RESET;
9638 }
9639
9640 /**
9641 * qla4xxx_pci_mmio_enabled() - gets called if
9642 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9643 * and read/write to the device still works.
9644 * @pdev: PCI device pointer
9645 **/
9646 static pci_ers_result_t
qla4xxx_pci_mmio_enabled(struct pci_dev * pdev)9647 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9648 {
9649 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9650
9651 if (!is_aer_supported(ha))
9652 return PCI_ERS_RESULT_NONE;
9653
9654 return PCI_ERS_RESULT_RECOVERED;
9655 }
9656
qla4_8xxx_error_recovery(struct scsi_qla_host * ha)9657 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9658 {
9659 uint32_t rval = QLA_ERROR;
9660 int fn;
9661 struct pci_dev *other_pdev = NULL;
9662
9663 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9664
9665 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9666
9667 if (test_bit(AF_ONLINE, &ha->flags)) {
9668 clear_bit(AF_ONLINE, &ha->flags);
9669 clear_bit(AF_LINK_UP, &ha->flags);
9670 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9671 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9672 }
9673
9674 fn = PCI_FUNC(ha->pdev->devfn);
9675 if (is_qla8022(ha)) {
9676 while (fn > 0) {
9677 fn--;
9678 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9679 ha->host_no, __func__, fn);
9680 /* Get the pci device given the domain, bus,
9681 * slot/function number */
9682 other_pdev = pci_get_domain_bus_and_slot(
9683 pci_domain_nr(ha->pdev->bus),
9684 ha->pdev->bus->number,
9685 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9686 fn));
9687
9688 if (!other_pdev)
9689 continue;
9690
9691 if (atomic_read(&other_pdev->enable_cnt)) {
9692 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9693 ha->host_no, __func__, fn);
9694 pci_dev_put(other_pdev);
9695 break;
9696 }
9697 pci_dev_put(other_pdev);
9698 }
9699 } else {
9700 /* this case is meant for ISP83xx/ISP84xx only */
9701 if (qla4_83xx_can_perform_reset(ha)) {
9702 /* reset fn as iSCSI is going to perform the reset */
9703 fn = 0;
9704 }
9705 }
9706
9707 /* The first function on the card, the reset owner will
9708 * start & initialize the firmware. The other functions
9709 * on the card will reset the firmware context
9710 */
9711 if (!fn) {
9712 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9713 "0x%x is the owner\n", ha->host_no, __func__,
9714 ha->pdev->devfn);
9715
9716 ha->isp_ops->idc_lock(ha);
9717 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9718 QLA8XXX_DEV_COLD);
9719 ha->isp_ops->idc_unlock(ha);
9720
9721 rval = qla4_8xxx_update_idc_reg(ha);
9722 if (rval == QLA_ERROR) {
9723 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9724 ha->host_no, __func__);
9725 ha->isp_ops->idc_lock(ha);
9726 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9727 QLA8XXX_DEV_FAILED);
9728 ha->isp_ops->idc_unlock(ha);
9729 goto exit_error_recovery;
9730 }
9731
9732 clear_bit(AF_FW_RECOVERY, &ha->flags);
9733 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9734
9735 if (rval != QLA_SUCCESS) {
9736 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9737 "FAILED\n", ha->host_no, __func__);
9738 qla4xxx_free_irqs(ha);
9739 ha->isp_ops->idc_lock(ha);
9740 qla4_8xxx_clear_drv_active(ha);
9741 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9742 QLA8XXX_DEV_FAILED);
9743 ha->isp_ops->idc_unlock(ha);
9744 } else {
9745 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9746 "READY\n", ha->host_no, __func__);
9747 ha->isp_ops->idc_lock(ha);
9748 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9749 QLA8XXX_DEV_READY);
9750 /* Clear driver state register */
9751 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9752 qla4_8xxx_set_drv_active(ha);
9753 ha->isp_ops->idc_unlock(ha);
9754 ha->isp_ops->enable_intrs(ha);
9755 }
9756 } else {
9757 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9758 "the reset owner\n", ha->host_no, __func__,
9759 ha->pdev->devfn);
9760 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9761 QLA8XXX_DEV_READY)) {
9762 clear_bit(AF_FW_RECOVERY, &ha->flags);
9763 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9764 if (rval == QLA_SUCCESS)
9765 ha->isp_ops->enable_intrs(ha);
9766 else
9767 qla4xxx_free_irqs(ha);
9768
9769 ha->isp_ops->idc_lock(ha);
9770 qla4_8xxx_set_drv_active(ha);
9771 ha->isp_ops->idc_unlock(ha);
9772 }
9773 }
9774 exit_error_recovery:
9775 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9776 return rval;
9777 }
9778
9779 static pci_ers_result_t
qla4xxx_pci_slot_reset(struct pci_dev * pdev)9780 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9781 {
9782 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9783 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9784 int rc;
9785
9786 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9787 ha->host_no, __func__);
9788
9789 if (!is_aer_supported(ha))
9790 return PCI_ERS_RESULT_NONE;
9791
9792 /* Restore the saved state of PCIe device -
9793 * BAR registers, PCI Config space, PCIX, MSI,
9794 * IOV states
9795 */
9796 pci_restore_state(pdev);
9797
9798 /* pci_restore_state() clears the saved_state flag of the device
9799 * save restored state which resets saved_state flag
9800 */
9801 pci_save_state(pdev);
9802
9803 /* Initialize device or resume if in suspended state */
9804 rc = pci_enable_device(pdev);
9805 if (rc) {
9806 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9807 "device after reset\n", ha->host_no, __func__);
9808 goto exit_slot_reset;
9809 }
9810
9811 ha->isp_ops->disable_intrs(ha);
9812
9813 if (is_qla80XX(ha)) {
9814 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9815 ret = PCI_ERS_RESULT_RECOVERED;
9816 goto exit_slot_reset;
9817 } else
9818 goto exit_slot_reset;
9819 }
9820
9821 exit_slot_reset:
9822 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9823 "device after reset\n", ha->host_no, __func__, ret);
9824 return ret;
9825 }
9826
9827 static void
qla4xxx_pci_resume(struct pci_dev * pdev)9828 qla4xxx_pci_resume(struct pci_dev *pdev)
9829 {
9830 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9831 int ret;
9832
9833 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9834 ha->host_no, __func__);
9835
9836 ret = qla4xxx_wait_for_hba_online(ha);
9837 if (ret != QLA_SUCCESS) {
9838 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9839 "resume I/O from slot/link_reset\n", ha->host_no,
9840 __func__);
9841 }
9842
9843 clear_bit(AF_EEH_BUSY, &ha->flags);
9844 }
9845
9846 static const struct pci_error_handlers qla4xxx_err_handler = {
9847 .error_detected = qla4xxx_pci_error_detected,
9848 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9849 .slot_reset = qla4xxx_pci_slot_reset,
9850 .resume = qla4xxx_pci_resume,
9851 };
9852
9853 static struct pci_device_id qla4xxx_pci_tbl[] = {
9854 {
9855 .vendor = PCI_VENDOR_ID_QLOGIC,
9856 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9857 .subvendor = PCI_ANY_ID,
9858 .subdevice = PCI_ANY_ID,
9859 },
9860 {
9861 .vendor = PCI_VENDOR_ID_QLOGIC,
9862 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9863 .subvendor = PCI_ANY_ID,
9864 .subdevice = PCI_ANY_ID,
9865 },
9866 {
9867 .vendor = PCI_VENDOR_ID_QLOGIC,
9868 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9869 .subvendor = PCI_ANY_ID,
9870 .subdevice = PCI_ANY_ID,
9871 },
9872 {
9873 .vendor = PCI_VENDOR_ID_QLOGIC,
9874 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9875 .subvendor = PCI_ANY_ID,
9876 .subdevice = PCI_ANY_ID,
9877 },
9878 {
9879 .vendor = PCI_VENDOR_ID_QLOGIC,
9880 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9881 .subvendor = PCI_ANY_ID,
9882 .subdevice = PCI_ANY_ID,
9883 },
9884 {
9885 .vendor = PCI_VENDOR_ID_QLOGIC,
9886 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9887 .subvendor = PCI_ANY_ID,
9888 .subdevice = PCI_ANY_ID,
9889 },
9890 {0, 0},
9891 };
9892 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9893
9894 static struct pci_driver qla4xxx_pci_driver = {
9895 .name = DRIVER_NAME,
9896 .id_table = qla4xxx_pci_tbl,
9897 .probe = qla4xxx_probe_adapter,
9898 .remove = qla4xxx_remove_adapter,
9899 .err_handler = &qla4xxx_err_handler,
9900 };
9901
qla4xxx_module_init(void)9902 static int __init qla4xxx_module_init(void)
9903 {
9904 int ret;
9905
9906 if (ql4xqfulltracking)
9907 qla4xxx_driver_template.track_queue_depth = 1;
9908
9909 /* Allocate cache for SRBs. */
9910 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9911 SLAB_HWCACHE_ALIGN, NULL);
9912 if (srb_cachep == NULL) {
9913 printk(KERN_ERR
9914 "%s: Unable to allocate SRB cache..."
9915 "Failing load!\n", DRIVER_NAME);
9916 ret = -ENOMEM;
9917 goto no_srp_cache;
9918 }
9919
9920 /* Derive version string. */
9921 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9922 if (ql4xextended_error_logging)
9923 strcat(qla4xxx_version_str, "-debug");
9924
9925 qla4xxx_scsi_transport =
9926 iscsi_register_transport(&qla4xxx_iscsi_transport);
9927 if (!qla4xxx_scsi_transport){
9928 ret = -ENODEV;
9929 goto release_srb_cache;
9930 }
9931
9932 ret = pci_register_driver(&qla4xxx_pci_driver);
9933 if (ret)
9934 goto unregister_transport;
9935
9936 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9937 return 0;
9938
9939 unregister_transport:
9940 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9941 release_srb_cache:
9942 kmem_cache_destroy(srb_cachep);
9943 no_srp_cache:
9944 return ret;
9945 }
9946
qla4xxx_module_exit(void)9947 static void __exit qla4xxx_module_exit(void)
9948 {
9949 pci_unregister_driver(&qla4xxx_pci_driver);
9950 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9951 kmem_cache_destroy(srb_cachep);
9952 }
9953
9954 module_init(qla4xxx_module_init);
9955 module_exit(qla4xxx_module_exit);
9956
9957 MODULE_AUTHOR("QLogic Corporation");
9958 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9959 MODULE_LICENSE("GPL");
9960 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);
9961