0001
0002
0003
0004
0005
0006
0007 #include <linux/types.h>
0008 #include <asm/byteorder.h>
0009 #include <asm/param.h>
0010 #include <linux/delay.h>
0011 #include <linux/dma-mapping.h>
0012 #include <linux/etherdevice.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/kernel.h>
0015 #include <linux/log2.h>
0016 #include <linux/module.h>
0017 #include <linux/pci.h>
0018 #include <linux/slab.h>
0019 #include <linux/stddef.h>
0020 #include <linux/string.h>
0021 #include <linux/workqueue.h>
0022 #include <linux/errno.h>
0023 #include <linux/list.h>
0024 #include <linux/spinlock.h>
0025 #include <linux/qed/qed_iscsi_if.h>
0026 #include "qed.h"
0027 #include "qed_cxt.h"
0028 #include "qed_dev_api.h"
0029 #include "qed_hsi.h"
0030 #include "qed_hw.h"
0031 #include "qed_int.h"
0032 #include "qed_iro_hsi.h"
0033 #include "qed_iscsi.h"
0034 #include "qed_ll2.h"
0035 #include "qed_mcp.h"
0036 #include "qed_sp.h"
0037 #include "qed_sriov.h"
0038 #include "qed_reg_addr.h"
0039
0040 struct qed_iscsi_conn {
0041 struct list_head list_entry;
0042 bool free_on_delete;
0043
0044 u16 conn_id;
0045 u32 icid;
0046 u32 fw_cid;
0047
0048 u8 layer_code;
0049 u8 offl_flags;
0050 u8 connect_mode;
0051 u32 initial_ack;
0052 dma_addr_t sq_pbl_addr;
0053 struct qed_chain r2tq;
0054 struct qed_chain xhq;
0055 struct qed_chain uhq;
0056
0057 struct tcp_upload_params *tcp_upload_params_virt_addr;
0058 dma_addr_t tcp_upload_params_phys_addr;
0059 struct scsi_terminate_extra_params *queue_cnts_virt_addr;
0060 dma_addr_t queue_cnts_phys_addr;
0061 dma_addr_t syn_phy_addr;
0062
0063 u16 syn_ip_payload_length;
0064 u8 local_mac[6];
0065 u8 remote_mac[6];
0066 u16 vlan_id;
0067 u16 tcp_flags;
0068 u8 ip_version;
0069 u32 remote_ip[4];
0070 u32 local_ip[4];
0071 u8 ka_max_probe_cnt;
0072 u8 dup_ack_theshold;
0073 u32 rcv_next;
0074 u32 snd_una;
0075 u32 snd_next;
0076 u32 snd_max;
0077 u32 snd_wnd;
0078 u32 rcv_wnd;
0079 u32 snd_wl1;
0080 u32 cwnd;
0081 u32 ss_thresh;
0082 u16 srtt;
0083 u16 rtt_var;
0084 u32 ts_recent;
0085 u32 ts_recent_age;
0086 u32 total_rt;
0087 u32 ka_timeout_delta;
0088 u32 rt_timeout_delta;
0089 u8 dup_ack_cnt;
0090 u8 snd_wnd_probe_cnt;
0091 u8 ka_probe_cnt;
0092 u8 rt_cnt;
0093 u32 flow_label;
0094 u32 ka_timeout;
0095 u32 ka_interval;
0096 u32 max_rt_time;
0097 u32 initial_rcv_wnd;
0098 u8 ttl;
0099 u8 tos_or_tc;
0100 u16 remote_port;
0101 u16 local_port;
0102 u16 mss;
0103 u8 snd_wnd_scale;
0104 u8 rcv_wnd_scale;
0105 u16 da_timeout_value;
0106 u8 ack_frequency;
0107
0108 u8 update_flag;
0109 u8 default_cq;
0110 u32 max_seq_size;
0111 u32 max_recv_pdu_length;
0112 u32 max_send_pdu_length;
0113 u32 first_seq_length;
0114 u32 exp_stat_sn;
0115 u32 stat_sn;
0116 u16 physical_q0;
0117 u16 physical_q1;
0118 u8 abortive_dsconnect;
0119 };
0120
0121 static int qed_iscsi_async_event(struct qed_hwfn *p_hwfn, u8 fw_event_code,
0122 __le16 echo, union event_ring_data *data,
0123 u8 fw_return_code)
0124 {
0125 if (p_hwfn->p_iscsi_info->event_cb) {
0126 struct qed_iscsi_info *p_iscsi = p_hwfn->p_iscsi_info;
0127
0128 return p_iscsi->event_cb(p_iscsi->event_context,
0129 fw_event_code, data);
0130 } else {
0131 DP_NOTICE(p_hwfn, "iSCSI async completion is not set\n");
0132 return -EINVAL;
0133 }
0134 }
0135
0136 static int
0137 qed_sp_iscsi_func_start(struct qed_hwfn *p_hwfn,
0138 enum spq_mode comp_mode,
0139 struct qed_spq_comp_cb *p_comp_addr,
0140 void *event_context, iscsi_event_cb_t async_event_cb)
0141 {
0142 struct iscsi_init_ramrod_params *p_ramrod = NULL;
0143 struct scsi_init_func_queues *p_queue = NULL;
0144 struct qed_iscsi_pf_params *p_params = NULL;
0145 struct iscsi_spe_func_init *p_init = NULL;
0146 struct qed_spq_entry *p_ent = NULL;
0147 struct qed_sp_init_data init_data;
0148 int rc = 0;
0149 u32 dval;
0150 u16 val;
0151 u8 i;
0152
0153
0154 memset(&init_data, 0, sizeof(init_data));
0155 init_data.cid = qed_spq_get_cid(p_hwfn);
0156 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0157 init_data.comp_mode = comp_mode;
0158 init_data.p_comp_data = p_comp_addr;
0159
0160 rc = qed_sp_init_request(p_hwfn, &p_ent,
0161 ISCSI_RAMROD_CMD_ID_INIT_FUNC,
0162 PROTOCOLID_TCP_ULP, &init_data);
0163 if (rc)
0164 return rc;
0165
0166 p_ramrod = &p_ent->ramrod.iscsi_init;
0167 p_init = &p_ramrod->iscsi_init_spe;
0168 p_params = &p_hwfn->pf_params.iscsi_pf_params;
0169 p_queue = &p_init->q_params;
0170
0171
0172 if (p_params->num_queues > p_hwfn->hw_info.feat_num[QED_ISCSI_CQ]) {
0173 DP_ERR(p_hwfn,
0174 "Cannot satisfy CQ amount. Queues requested %d, CQs available %d. Aborting function start\n",
0175 p_params->num_queues,
0176 p_hwfn->hw_info.feat_num[QED_ISCSI_CQ]);
0177 qed_sp_destroy_request(p_hwfn, p_ent);
0178 return -EINVAL;
0179 }
0180
0181 val = p_params->half_way_close_timeout;
0182 p_init->half_way_close_timeout = cpu_to_le16(val);
0183 p_init->num_sq_pages_in_ring = p_params->num_sq_pages_in_ring;
0184 p_init->num_r2tq_pages_in_ring = p_params->num_r2tq_pages_in_ring;
0185 p_init->num_uhq_pages_in_ring = p_params->num_uhq_pages_in_ring;
0186 p_init->ll2_rx_queue_id =
0187 p_hwfn->hw_info.resc_start[QED_LL2_RAM_QUEUE] +
0188 p_params->ll2_ooo_queue_id;
0189
0190 p_init->func_params.log_page_size = p_params->log_page_size;
0191 val = p_params->num_tasks;
0192 p_init->func_params.num_tasks = cpu_to_le16(val);
0193 p_init->debug_mode.flags = p_params->debug_mode;
0194
0195 DMA_REGPAIR_LE(p_queue->glbl_q_params_addr,
0196 p_params->glbl_q_params_addr);
0197
0198 val = p_params->cq_num_entries;
0199 p_queue->cq_num_entries = cpu_to_le16(val);
0200 val = p_params->cmdq_num_entries;
0201 p_queue->cmdq_num_entries = cpu_to_le16(val);
0202 p_queue->num_queues = p_params->num_queues;
0203 dval = (u8)p_hwfn->hw_info.resc_start[QED_CMDQS_CQS];
0204 p_queue->queue_relative_offset = (u8)dval;
0205 p_queue->cq_sb_pi = p_params->gl_rq_pi;
0206 p_queue->cmdq_sb_pi = p_params->gl_cmd_pi;
0207
0208 for (i = 0; i < p_params->num_queues; i++) {
0209 val = qed_get_igu_sb_id(p_hwfn, i);
0210 p_queue->cq_cmdq_sb_num_arr[i] = cpu_to_le16(val);
0211 }
0212
0213 p_queue->bdq_resource_id = (u8)RESC_START(p_hwfn, QED_BDQ);
0214
0215 DMA_REGPAIR_LE(p_queue->bdq_pbl_base_address[BDQ_ID_RQ],
0216 p_params->bdq_pbl_base_addr[BDQ_ID_RQ]);
0217 p_queue->bdq_pbl_num_entries[BDQ_ID_RQ] =
0218 p_params->bdq_pbl_num_entries[BDQ_ID_RQ];
0219 val = p_params->bdq_xoff_threshold[BDQ_ID_RQ];
0220 p_queue->bdq_xoff_threshold[BDQ_ID_RQ] = cpu_to_le16(val);
0221 val = p_params->bdq_xon_threshold[BDQ_ID_RQ];
0222 p_queue->bdq_xon_threshold[BDQ_ID_RQ] = cpu_to_le16(val);
0223
0224 DMA_REGPAIR_LE(p_queue->bdq_pbl_base_address[BDQ_ID_IMM_DATA],
0225 p_params->bdq_pbl_base_addr[BDQ_ID_IMM_DATA]);
0226 p_queue->bdq_pbl_num_entries[BDQ_ID_IMM_DATA] =
0227 p_params->bdq_pbl_num_entries[BDQ_ID_IMM_DATA];
0228 val = p_params->bdq_xoff_threshold[BDQ_ID_IMM_DATA];
0229 p_queue->bdq_xoff_threshold[BDQ_ID_IMM_DATA] = cpu_to_le16(val);
0230 val = p_params->bdq_xon_threshold[BDQ_ID_IMM_DATA];
0231 p_queue->bdq_xon_threshold[BDQ_ID_IMM_DATA] = cpu_to_le16(val);
0232 val = p_params->rq_buffer_size;
0233 p_queue->rq_buffer_size = cpu_to_le16(val);
0234 if (p_params->is_target) {
0235 SET_FIELD(p_queue->q_validity,
0236 SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
0237 if (p_queue->bdq_pbl_num_entries[BDQ_ID_IMM_DATA])
0238 SET_FIELD(p_queue->q_validity,
0239 SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID, 1);
0240 SET_FIELD(p_queue->q_validity,
0241 SCSI_INIT_FUNC_QUEUES_CMD_VALID, 1);
0242 } else {
0243 SET_FIELD(p_queue->q_validity,
0244 SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
0245 }
0246 p_ramrod->tcp_init.two_msl_timer = cpu_to_le32(p_params->two_msl_timer);
0247 val = p_params->tx_sws_timer;
0248 p_ramrod->tcp_init.tx_sws_timer = cpu_to_le16(val);
0249 p_ramrod->tcp_init.max_fin_rt = p_params->max_fin_rt;
0250
0251 p_hwfn->p_iscsi_info->event_context = event_context;
0252 p_hwfn->p_iscsi_info->event_cb = async_event_cb;
0253
0254 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_TCP_ULP,
0255 qed_iscsi_async_event);
0256
0257 return qed_spq_post(p_hwfn, p_ent, NULL);
0258 }
0259
0260 static int qed_sp_iscsi_conn_offload(struct qed_hwfn *p_hwfn,
0261 struct qed_iscsi_conn *p_conn,
0262 enum spq_mode comp_mode,
0263 struct qed_spq_comp_cb *p_comp_addr)
0264 {
0265 struct iscsi_spe_conn_offload *p_ramrod = NULL;
0266 struct tcp_offload_params_opt2 *p_tcp2 = NULL;
0267 struct tcp_offload_params *p_tcp = NULL;
0268 struct qed_spq_entry *p_ent = NULL;
0269 struct qed_sp_init_data init_data;
0270 dma_addr_t r2tq_pbl_addr;
0271 dma_addr_t xhq_pbl_addr;
0272 dma_addr_t uhq_pbl_addr;
0273 u16 physical_q;
0274 __le16 tmp;
0275 int rc = 0;
0276 u32 dval;
0277 u16 wval;
0278 u16 *p;
0279 u8 i;
0280
0281
0282 memset(&init_data, 0, sizeof(init_data));
0283 init_data.cid = p_conn->icid;
0284 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0285 init_data.comp_mode = comp_mode;
0286 init_data.p_comp_data = p_comp_addr;
0287
0288 rc = qed_sp_init_request(p_hwfn, &p_ent,
0289 ISCSI_RAMROD_CMD_ID_OFFLOAD_CONN,
0290 PROTOCOLID_TCP_ULP, &init_data);
0291 if (rc)
0292 return rc;
0293
0294 p_ramrod = &p_ent->ramrod.iscsi_conn_offload;
0295
0296
0297 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
0298 p_conn->physical_q0 = physical_q;
0299 p_ramrod->iscsi.physical_q0 = cpu_to_le16(physical_q);
0300
0301
0302 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
0303 p_conn->physical_q1 = physical_q;
0304 p_ramrod->iscsi.physical_q1 = cpu_to_le16(physical_q);
0305
0306 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
0307
0308 DMA_REGPAIR_LE(p_ramrod->iscsi.sq_pbl_addr, p_conn->sq_pbl_addr);
0309
0310 r2tq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->r2tq);
0311 DMA_REGPAIR_LE(p_ramrod->iscsi.r2tq_pbl_addr, r2tq_pbl_addr);
0312
0313 xhq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->xhq);
0314 DMA_REGPAIR_LE(p_ramrod->iscsi.xhq_pbl_addr, xhq_pbl_addr);
0315
0316 uhq_pbl_addr = qed_chain_get_pbl_phys(&p_conn->uhq);
0317 DMA_REGPAIR_LE(p_ramrod->iscsi.uhq_pbl_addr, uhq_pbl_addr);
0318
0319 p_ramrod->iscsi.initial_ack = cpu_to_le32(p_conn->initial_ack);
0320 p_ramrod->iscsi.flags = p_conn->offl_flags;
0321 p_ramrod->iscsi.default_cq = p_conn->default_cq;
0322 p_ramrod->iscsi.stat_sn = cpu_to_le32(p_conn->stat_sn);
0323
0324 if (!GET_FIELD(p_ramrod->iscsi.flags,
0325 ISCSI_CONN_OFFLOAD_PARAMS_TCP_ON_CHIP_1B)) {
0326 p_tcp = &p_ramrod->tcp;
0327
0328 p = (u16 *)p_conn->local_mac;
0329 tmp = cpu_to_le16(get_unaligned_be16(p));
0330 p_tcp->local_mac_addr_hi = tmp;
0331 tmp = cpu_to_le16(get_unaligned_be16(p + 1));
0332 p_tcp->local_mac_addr_mid = tmp;
0333 tmp = cpu_to_le16(get_unaligned_be16(p + 2));
0334 p_tcp->local_mac_addr_lo = tmp;
0335
0336 p = (u16 *)p_conn->remote_mac;
0337 tmp = cpu_to_le16(get_unaligned_be16(p));
0338 p_tcp->remote_mac_addr_hi = tmp;
0339 tmp = cpu_to_le16(get_unaligned_be16(p + 1));
0340 p_tcp->remote_mac_addr_mid = tmp;
0341 tmp = cpu_to_le16(get_unaligned_be16(p + 2));
0342 p_tcp->remote_mac_addr_lo = tmp;
0343
0344 p_tcp->vlan_id = cpu_to_le16(p_conn->vlan_id);
0345
0346 p_tcp->flags = cpu_to_le16(p_conn->tcp_flags);
0347 p_tcp->ip_version = p_conn->ip_version;
0348 for (i = 0; i < 4; i++) {
0349 dval = p_conn->remote_ip[i];
0350 p_tcp->remote_ip[i] = cpu_to_le32(dval);
0351 dval = p_conn->local_ip[i];
0352 p_tcp->local_ip[i] = cpu_to_le32(dval);
0353 }
0354 p_tcp->ka_max_probe_cnt = p_conn->ka_max_probe_cnt;
0355 p_tcp->dup_ack_theshold = p_conn->dup_ack_theshold;
0356
0357 p_tcp->rcv_next = cpu_to_le32(p_conn->rcv_next);
0358 p_tcp->snd_una = cpu_to_le32(p_conn->snd_una);
0359 p_tcp->snd_next = cpu_to_le32(p_conn->snd_next);
0360 p_tcp->snd_max = cpu_to_le32(p_conn->snd_max);
0361 p_tcp->snd_wnd = cpu_to_le32(p_conn->snd_wnd);
0362 p_tcp->rcv_wnd = cpu_to_le32(p_conn->rcv_wnd);
0363 p_tcp->snd_wl1 = cpu_to_le32(p_conn->snd_wl1);
0364 p_tcp->cwnd = cpu_to_le32(p_conn->cwnd);
0365 p_tcp->ss_thresh = cpu_to_le32(p_conn->ss_thresh);
0366 p_tcp->srtt = cpu_to_le16(p_conn->srtt);
0367 p_tcp->rtt_var = cpu_to_le16(p_conn->rtt_var);
0368 p_tcp->ts_recent = cpu_to_le32(p_conn->ts_recent);
0369 p_tcp->ts_recent_age = cpu_to_le32(p_conn->ts_recent_age);
0370 p_tcp->total_rt = cpu_to_le32(p_conn->total_rt);
0371 dval = p_conn->ka_timeout_delta;
0372 p_tcp->ka_timeout_delta = cpu_to_le32(dval);
0373 dval = p_conn->rt_timeout_delta;
0374 p_tcp->rt_timeout_delta = cpu_to_le32(dval);
0375 p_tcp->dup_ack_cnt = p_conn->dup_ack_cnt;
0376 p_tcp->snd_wnd_probe_cnt = p_conn->snd_wnd_probe_cnt;
0377 p_tcp->ka_probe_cnt = p_conn->ka_probe_cnt;
0378 p_tcp->rt_cnt = p_conn->rt_cnt;
0379 p_tcp->flow_label = cpu_to_le32(p_conn->flow_label);
0380 p_tcp->ka_timeout = cpu_to_le32(p_conn->ka_timeout);
0381 p_tcp->ka_interval = cpu_to_le32(p_conn->ka_interval);
0382 p_tcp->max_rt_time = cpu_to_le32(p_conn->max_rt_time);
0383 dval = p_conn->initial_rcv_wnd;
0384 p_tcp->initial_rcv_wnd = cpu_to_le32(dval);
0385 p_tcp->ttl = p_conn->ttl;
0386 p_tcp->tos_or_tc = p_conn->tos_or_tc;
0387 p_tcp->remote_port = cpu_to_le16(p_conn->remote_port);
0388 p_tcp->local_port = cpu_to_le16(p_conn->local_port);
0389 p_tcp->mss = cpu_to_le16(p_conn->mss);
0390 p_tcp->snd_wnd_scale = p_conn->snd_wnd_scale;
0391 p_tcp->rcv_wnd_scale = p_conn->rcv_wnd_scale;
0392 wval = p_conn->da_timeout_value;
0393 p_tcp->da_timeout_value = cpu_to_le16(wval);
0394 p_tcp->ack_frequency = p_conn->ack_frequency;
0395 p_tcp->connect_mode = p_conn->connect_mode;
0396 } else {
0397 p_tcp2 =
0398 &((struct iscsi_spe_conn_offload_option2 *)p_ramrod)->tcp;
0399
0400 p = (u16 *)p_conn->local_mac;
0401 tmp = cpu_to_le16(get_unaligned_be16(p));
0402 p_tcp2->local_mac_addr_hi = tmp;
0403 tmp = cpu_to_le16(get_unaligned_be16(p + 1));
0404 p_tcp2->local_mac_addr_mid = tmp;
0405 tmp = cpu_to_le16(get_unaligned_be16(p + 2));
0406 p_tcp2->local_mac_addr_lo = tmp;
0407
0408 p = (u16 *)p_conn->remote_mac;
0409 tmp = cpu_to_le16(get_unaligned_be16(p));
0410 p_tcp2->remote_mac_addr_hi = tmp;
0411 tmp = cpu_to_le16(get_unaligned_be16(p + 1));
0412 p_tcp2->remote_mac_addr_mid = tmp;
0413 tmp = cpu_to_le16(get_unaligned_be16(p + 2));
0414 p_tcp2->remote_mac_addr_lo = tmp;
0415
0416 p_tcp2->vlan_id = cpu_to_le16(p_conn->vlan_id);
0417 p_tcp2->flags = cpu_to_le16(p_conn->tcp_flags);
0418
0419 p_tcp2->ip_version = p_conn->ip_version;
0420 for (i = 0; i < 4; i++) {
0421 dval = p_conn->remote_ip[i];
0422 p_tcp2->remote_ip[i] = cpu_to_le32(dval);
0423 dval = p_conn->local_ip[i];
0424 p_tcp2->local_ip[i] = cpu_to_le32(dval);
0425 }
0426
0427 p_tcp2->flow_label = cpu_to_le32(p_conn->flow_label);
0428 p_tcp2->ttl = p_conn->ttl;
0429 p_tcp2->tos_or_tc = p_conn->tos_or_tc;
0430 p_tcp2->remote_port = cpu_to_le16(p_conn->remote_port);
0431 p_tcp2->local_port = cpu_to_le16(p_conn->local_port);
0432 p_tcp2->mss = cpu_to_le16(p_conn->mss);
0433 p_tcp2->rcv_wnd_scale = p_conn->rcv_wnd_scale;
0434 p_tcp2->connect_mode = p_conn->connect_mode;
0435 wval = p_conn->syn_ip_payload_length;
0436 p_tcp2->syn_ip_payload_length = cpu_to_le16(wval);
0437 p_tcp2->syn_phy_addr_lo = DMA_LO_LE(p_conn->syn_phy_addr);
0438 p_tcp2->syn_phy_addr_hi = DMA_HI_LE(p_conn->syn_phy_addr);
0439 p_tcp2->cwnd = cpu_to_le32(p_conn->cwnd);
0440 p_tcp2->ka_max_probe_cnt = p_conn->ka_probe_cnt;
0441 p_tcp2->ka_timeout = cpu_to_le32(p_conn->ka_timeout);
0442 p_tcp2->max_rt_time = cpu_to_le32(p_conn->max_rt_time);
0443 p_tcp2->ka_interval = cpu_to_le32(p_conn->ka_interval);
0444 }
0445
0446 return qed_spq_post(p_hwfn, p_ent, NULL);
0447 }
0448
0449 static int qed_sp_iscsi_conn_update(struct qed_hwfn *p_hwfn,
0450 struct qed_iscsi_conn *p_conn,
0451 enum spq_mode comp_mode,
0452 struct qed_spq_comp_cb *p_comp_addr)
0453 {
0454 struct iscsi_conn_update_ramrod_params *p_ramrod = NULL;
0455 struct qed_spq_entry *p_ent = NULL;
0456 struct qed_sp_init_data init_data;
0457 int rc;
0458 u32 dval;
0459
0460
0461 memset(&init_data, 0, sizeof(init_data));
0462 init_data.cid = p_conn->icid;
0463 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0464 init_data.comp_mode = comp_mode;
0465 init_data.p_comp_data = p_comp_addr;
0466
0467 rc = qed_sp_init_request(p_hwfn, &p_ent,
0468 ISCSI_RAMROD_CMD_ID_UPDATE_CONN,
0469 PROTOCOLID_TCP_ULP, &init_data);
0470 if (rc)
0471 return rc;
0472
0473 p_ramrod = &p_ent->ramrod.iscsi_conn_update;
0474
0475 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
0476 p_ramrod->flags = p_conn->update_flag;
0477 p_ramrod->max_seq_size = cpu_to_le32(p_conn->max_seq_size);
0478 dval = p_conn->max_recv_pdu_length;
0479 p_ramrod->max_recv_pdu_length = cpu_to_le32(dval);
0480 dval = p_conn->max_send_pdu_length;
0481 p_ramrod->max_send_pdu_length = cpu_to_le32(dval);
0482 dval = p_conn->first_seq_length;
0483 p_ramrod->first_seq_length = cpu_to_le32(dval);
0484 p_ramrod->exp_stat_sn = cpu_to_le32(p_conn->exp_stat_sn);
0485
0486 return qed_spq_post(p_hwfn, p_ent, NULL);
0487 }
0488
0489 static int
0490 qed_sp_iscsi_mac_update(struct qed_hwfn *p_hwfn,
0491 struct qed_iscsi_conn *p_conn,
0492 enum spq_mode comp_mode,
0493 struct qed_spq_comp_cb *p_comp_addr)
0494 {
0495 struct iscsi_spe_conn_mac_update *p_ramrod = NULL;
0496 struct qed_spq_entry *p_ent = NULL;
0497 struct qed_sp_init_data init_data;
0498 int rc = -EINVAL;
0499 u8 ucval;
0500
0501
0502 memset(&init_data, 0, sizeof(init_data));
0503 init_data.cid = p_conn->icid;
0504 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0505 init_data.comp_mode = comp_mode;
0506 init_data.p_comp_data = p_comp_addr;
0507
0508 rc = qed_sp_init_request(p_hwfn, &p_ent,
0509 ISCSI_RAMROD_CMD_ID_MAC_UPDATE,
0510 PROTOCOLID_TCP_ULP, &init_data);
0511 if (rc)
0512 return rc;
0513
0514 p_ramrod = &p_ent->ramrod.iscsi_conn_mac_update;
0515
0516 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
0517 ucval = p_conn->remote_mac[1];
0518 ((u8 *)(&p_ramrod->remote_mac_addr_hi))[0] = ucval;
0519 ucval = p_conn->remote_mac[0];
0520 ((u8 *)(&p_ramrod->remote_mac_addr_hi))[1] = ucval;
0521 ucval = p_conn->remote_mac[3];
0522 ((u8 *)(&p_ramrod->remote_mac_addr_mid))[0] = ucval;
0523 ucval = p_conn->remote_mac[2];
0524 ((u8 *)(&p_ramrod->remote_mac_addr_mid))[1] = ucval;
0525 ucval = p_conn->remote_mac[5];
0526 ((u8 *)(&p_ramrod->remote_mac_addr_lo))[0] = ucval;
0527 ucval = p_conn->remote_mac[4];
0528 ((u8 *)(&p_ramrod->remote_mac_addr_lo))[1] = ucval;
0529
0530 return qed_spq_post(p_hwfn, p_ent, NULL);
0531 }
0532
0533 static int qed_sp_iscsi_conn_terminate(struct qed_hwfn *p_hwfn,
0534 struct qed_iscsi_conn *p_conn,
0535 enum spq_mode comp_mode,
0536 struct qed_spq_comp_cb *p_comp_addr)
0537 {
0538 struct iscsi_spe_conn_termination *p_ramrod = NULL;
0539 struct qed_spq_entry *p_ent = NULL;
0540 struct qed_sp_init_data init_data;
0541 int rc = -EINVAL;
0542
0543
0544 memset(&init_data, 0, sizeof(init_data));
0545 init_data.cid = p_conn->icid;
0546 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0547 init_data.comp_mode = comp_mode;
0548 init_data.p_comp_data = p_comp_addr;
0549
0550 rc = qed_sp_init_request(p_hwfn, &p_ent,
0551 ISCSI_RAMROD_CMD_ID_TERMINATION_CONN,
0552 PROTOCOLID_TCP_ULP, &init_data);
0553 if (rc)
0554 return rc;
0555
0556 p_ramrod = &p_ent->ramrod.iscsi_conn_terminate;
0557
0558 p_ramrod->conn_id = cpu_to_le16(p_conn->conn_id);
0559 p_ramrod->abortive = p_conn->abortive_dsconnect;
0560
0561 DMA_REGPAIR_LE(p_ramrod->query_params_addr,
0562 p_conn->tcp_upload_params_phys_addr);
0563 DMA_REGPAIR_LE(p_ramrod->queue_cnts_addr, p_conn->queue_cnts_phys_addr);
0564
0565 return qed_spq_post(p_hwfn, p_ent, NULL);
0566 }
0567
0568 static int qed_sp_iscsi_conn_clear_sq(struct qed_hwfn *p_hwfn,
0569 struct qed_iscsi_conn *p_conn,
0570 enum spq_mode comp_mode,
0571 struct qed_spq_comp_cb *p_comp_addr)
0572 {
0573 struct qed_spq_entry *p_ent = NULL;
0574 struct qed_sp_init_data init_data;
0575 int rc = -EINVAL;
0576
0577
0578 memset(&init_data, 0, sizeof(init_data));
0579 init_data.cid = p_conn->icid;
0580 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0581 init_data.comp_mode = comp_mode;
0582 init_data.p_comp_data = p_comp_addr;
0583
0584 rc = qed_sp_init_request(p_hwfn, &p_ent,
0585 ISCSI_RAMROD_CMD_ID_CLEAR_SQ,
0586 PROTOCOLID_TCP_ULP, &init_data);
0587 if (rc)
0588 return rc;
0589
0590 return qed_spq_post(p_hwfn, p_ent, NULL);
0591 }
0592
0593 static int qed_sp_iscsi_func_stop(struct qed_hwfn *p_hwfn,
0594 enum spq_mode comp_mode,
0595 struct qed_spq_comp_cb *p_comp_addr)
0596 {
0597 struct qed_spq_entry *p_ent = NULL;
0598 struct qed_sp_init_data init_data;
0599 int rc = 0;
0600
0601
0602 memset(&init_data, 0, sizeof(init_data));
0603 init_data.cid = qed_spq_get_cid(p_hwfn);
0604 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
0605 init_data.comp_mode = comp_mode;
0606 init_data.p_comp_data = p_comp_addr;
0607
0608 rc = qed_sp_init_request(p_hwfn, &p_ent,
0609 ISCSI_RAMROD_CMD_ID_DESTROY_FUNC,
0610 PROTOCOLID_TCP_ULP, &init_data);
0611 if (rc)
0612 return rc;
0613
0614 rc = qed_spq_post(p_hwfn, p_ent, NULL);
0615
0616 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_TCP_ULP);
0617 return rc;
0618 }
0619
0620 static void __iomem *qed_iscsi_get_db_addr(struct qed_hwfn *p_hwfn, u32 cid)
0621 {
0622 return (u8 __iomem *)p_hwfn->doorbells +
0623 qed_db_addr(cid, DQ_DEMS_LEGACY);
0624 }
0625
0626 static void __iomem *qed_iscsi_get_primary_bdq_prod(struct qed_hwfn *p_hwfn,
0627 u8 bdq_id)
0628 {
0629 if (RESC_NUM(p_hwfn, QED_BDQ)) {
0630 return (u8 __iomem *)p_hwfn->regview +
0631 GET_GTT_BDQ_REG_ADDR(GTT_BAR0_MAP_REG_MSDM_RAM,
0632 MSTORM_SCSI_BDQ_EXT_PROD,
0633 RESC_START(p_hwfn, QED_BDQ), bdq_id);
0634 } else {
0635 DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
0636 return NULL;
0637 }
0638 }
0639
0640 static void __iomem *qed_iscsi_get_secondary_bdq_prod(struct qed_hwfn *p_hwfn,
0641 u8 bdq_id)
0642 {
0643 if (RESC_NUM(p_hwfn, QED_BDQ)) {
0644 return (u8 __iomem *)p_hwfn->regview +
0645 GET_GTT_BDQ_REG_ADDR(GTT_BAR0_MAP_REG_TSDM_RAM,
0646 TSTORM_SCSI_BDQ_EXT_PROD,
0647 RESC_START(p_hwfn, QED_BDQ), bdq_id);
0648 } else {
0649 DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
0650 return NULL;
0651 }
0652 }
0653
0654 static int qed_iscsi_setup_connection(struct qed_iscsi_conn *p_conn)
0655 {
0656 if (!p_conn->queue_cnts_virt_addr)
0657 goto nomem;
0658 memset(p_conn->queue_cnts_virt_addr, 0,
0659 sizeof(*p_conn->queue_cnts_virt_addr));
0660
0661 if (!p_conn->tcp_upload_params_virt_addr)
0662 goto nomem;
0663 memset(p_conn->tcp_upload_params_virt_addr, 0,
0664 sizeof(*p_conn->tcp_upload_params_virt_addr));
0665
0666 if (!p_conn->r2tq.p_virt_addr)
0667 goto nomem;
0668 qed_chain_pbl_zero_mem(&p_conn->r2tq);
0669
0670 if (!p_conn->uhq.p_virt_addr)
0671 goto nomem;
0672 qed_chain_pbl_zero_mem(&p_conn->uhq);
0673
0674 if (!p_conn->xhq.p_virt_addr)
0675 goto nomem;
0676 qed_chain_pbl_zero_mem(&p_conn->xhq);
0677
0678 return 0;
0679 nomem:
0680 return -ENOMEM;
0681 }
0682
0683 static int qed_iscsi_allocate_connection(struct qed_hwfn *p_hwfn,
0684 struct qed_iscsi_conn **p_out_conn)
0685 {
0686 struct scsi_terminate_extra_params *p_q_cnts = NULL;
0687 struct qed_iscsi_pf_params *p_params = NULL;
0688 struct qed_chain_init_params params = {
0689 .mode = QED_CHAIN_MODE_PBL,
0690 .intended_use = QED_CHAIN_USE_TO_CONSUME_PRODUCE,
0691 .cnt_type = QED_CHAIN_CNT_TYPE_U16,
0692 };
0693 struct tcp_upload_params *p_tcp = NULL;
0694 struct qed_iscsi_conn *p_conn = NULL;
0695 int rc = 0;
0696
0697
0698 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
0699 if (!list_empty(&p_hwfn->p_iscsi_info->free_list))
0700 p_conn = list_first_entry(&p_hwfn->p_iscsi_info->free_list,
0701 struct qed_iscsi_conn, list_entry);
0702 if (p_conn) {
0703 list_del(&p_conn->list_entry);
0704 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
0705 *p_out_conn = p_conn;
0706 return 0;
0707 }
0708 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
0709
0710
0711 p_params = &p_hwfn->pf_params.iscsi_pf_params;
0712
0713 p_conn = kzalloc(sizeof(*p_conn), GFP_KERNEL);
0714 if (!p_conn)
0715 return -ENOMEM;
0716
0717 p_q_cnts = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
0718 sizeof(*p_q_cnts),
0719 &p_conn->queue_cnts_phys_addr,
0720 GFP_KERNEL);
0721 if (!p_q_cnts)
0722 goto nomem_queue_cnts_param;
0723 p_conn->queue_cnts_virt_addr = p_q_cnts;
0724
0725 p_tcp = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
0726 sizeof(*p_tcp),
0727 &p_conn->tcp_upload_params_phys_addr,
0728 GFP_KERNEL);
0729 if (!p_tcp)
0730 goto nomem_upload_param;
0731 p_conn->tcp_upload_params_virt_addr = p_tcp;
0732
0733 params.num_elems = p_params->num_r2tq_pages_in_ring *
0734 QED_CHAIN_PAGE_SIZE / sizeof(struct iscsi_wqe);
0735 params.elem_size = sizeof(struct iscsi_wqe);
0736
0737 rc = qed_chain_alloc(p_hwfn->cdev, &p_conn->r2tq, ¶ms);
0738 if (rc)
0739 goto nomem_r2tq;
0740
0741 params.num_elems = p_params->num_uhq_pages_in_ring *
0742 QED_CHAIN_PAGE_SIZE / sizeof(struct iscsi_uhqe);
0743 params.elem_size = sizeof(struct iscsi_uhqe);
0744
0745 rc = qed_chain_alloc(p_hwfn->cdev, &p_conn->uhq, ¶ms);
0746 if (rc)
0747 goto nomem_uhq;
0748
0749 params.elem_size = sizeof(struct iscsi_xhqe);
0750
0751 rc = qed_chain_alloc(p_hwfn->cdev, &p_conn->xhq, ¶ms);
0752 if (rc)
0753 goto nomem;
0754
0755 p_conn->free_on_delete = true;
0756 *p_out_conn = p_conn;
0757 return 0;
0758
0759 nomem:
0760 qed_chain_free(p_hwfn->cdev, &p_conn->uhq);
0761 nomem_uhq:
0762 qed_chain_free(p_hwfn->cdev, &p_conn->r2tq);
0763 nomem_r2tq:
0764 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
0765 sizeof(struct tcp_upload_params),
0766 p_conn->tcp_upload_params_virt_addr,
0767 p_conn->tcp_upload_params_phys_addr);
0768 nomem_upload_param:
0769 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
0770 sizeof(struct scsi_terminate_extra_params),
0771 p_conn->queue_cnts_virt_addr,
0772 p_conn->queue_cnts_phys_addr);
0773 nomem_queue_cnts_param:
0774 kfree(p_conn);
0775
0776 return -ENOMEM;
0777 }
0778
0779 static int qed_iscsi_acquire_connection(struct qed_hwfn *p_hwfn,
0780 struct qed_iscsi_conn *p_in_conn,
0781 struct qed_iscsi_conn **p_out_conn)
0782 {
0783 struct qed_iscsi_conn *p_conn = NULL;
0784 int rc = 0;
0785 u32 icid;
0786
0787 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
0788 rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_TCP_ULP, &icid);
0789 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
0790 if (rc)
0791 return rc;
0792
0793
0794 if (p_in_conn)
0795 p_conn = p_in_conn;
0796 else
0797 rc = qed_iscsi_allocate_connection(p_hwfn, &p_conn);
0798
0799 if (!rc)
0800 rc = qed_iscsi_setup_connection(p_conn);
0801
0802 if (rc) {
0803 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
0804 qed_cxt_release_cid(p_hwfn, icid);
0805 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
0806 return rc;
0807 }
0808
0809 p_conn->icid = icid;
0810 p_conn->conn_id = (u16)icid;
0811 p_conn->fw_cid = (p_hwfn->hw_info.opaque_fid << 16) | icid;
0812
0813 *p_out_conn = p_conn;
0814
0815 return rc;
0816 }
0817
0818 static void qed_iscsi_release_connection(struct qed_hwfn *p_hwfn,
0819 struct qed_iscsi_conn *p_conn)
0820 {
0821 spin_lock_bh(&p_hwfn->p_iscsi_info->lock);
0822 list_add_tail(&p_conn->list_entry, &p_hwfn->p_iscsi_info->free_list);
0823 qed_cxt_release_cid(p_hwfn, p_conn->icid);
0824 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
0825 }
0826
0827 static void qed_iscsi_free_connection(struct qed_hwfn *p_hwfn,
0828 struct qed_iscsi_conn *p_conn)
0829 {
0830 qed_chain_free(p_hwfn->cdev, &p_conn->xhq);
0831 qed_chain_free(p_hwfn->cdev, &p_conn->uhq);
0832 qed_chain_free(p_hwfn->cdev, &p_conn->r2tq);
0833 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
0834 sizeof(struct tcp_upload_params),
0835 p_conn->tcp_upload_params_virt_addr,
0836 p_conn->tcp_upload_params_phys_addr);
0837 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
0838 sizeof(struct scsi_terminate_extra_params),
0839 p_conn->queue_cnts_virt_addr,
0840 p_conn->queue_cnts_phys_addr);
0841 kfree(p_conn);
0842 }
0843
0844 int qed_iscsi_alloc(struct qed_hwfn *p_hwfn)
0845 {
0846 struct qed_iscsi_info *p_iscsi_info;
0847
0848 p_iscsi_info = kzalloc(sizeof(*p_iscsi_info), GFP_KERNEL);
0849 if (!p_iscsi_info)
0850 return -ENOMEM;
0851
0852 INIT_LIST_HEAD(&p_iscsi_info->free_list);
0853
0854 p_hwfn->p_iscsi_info = p_iscsi_info;
0855 return 0;
0856 }
0857
0858 void qed_iscsi_setup(struct qed_hwfn *p_hwfn)
0859 {
0860 spin_lock_init(&p_hwfn->p_iscsi_info->lock);
0861 }
0862
0863 void qed_iscsi_free(struct qed_hwfn *p_hwfn)
0864 {
0865 struct qed_iscsi_conn *p_conn = NULL;
0866
0867 if (!p_hwfn->p_iscsi_info)
0868 return;
0869
0870 while (!list_empty(&p_hwfn->p_iscsi_info->free_list)) {
0871 p_conn = list_first_entry(&p_hwfn->p_iscsi_info->free_list,
0872 struct qed_iscsi_conn, list_entry);
0873 if (p_conn) {
0874 list_del(&p_conn->list_entry);
0875 qed_iscsi_free_connection(p_hwfn, p_conn);
0876 }
0877 }
0878
0879 kfree(p_hwfn->p_iscsi_info);
0880 p_hwfn->p_iscsi_info = NULL;
0881 }
0882
0883 static void _qed_iscsi_get_tstats(struct qed_hwfn *p_hwfn,
0884 struct qed_ptt *p_ptt,
0885 struct qed_iscsi_stats *p_stats)
0886 {
0887 struct tstorm_iscsi_stats_drv tstats;
0888 u32 tstats_addr;
0889
0890 memset(&tstats, 0, sizeof(tstats));
0891 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
0892 TSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
0893 qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));
0894
0895 p_stats->iscsi_rx_bytes_cnt =
0896 HILO_64_REGPAIR(tstats.iscsi_rx_bytes_cnt);
0897 p_stats->iscsi_rx_packet_cnt =
0898 HILO_64_REGPAIR(tstats.iscsi_rx_packet_cnt);
0899 p_stats->iscsi_rx_new_ooo_isle_events_cnt =
0900 HILO_64_REGPAIR(tstats.iscsi_rx_new_ooo_isle_events_cnt);
0901 p_stats->iscsi_cmdq_threshold_cnt =
0902 le32_to_cpu(tstats.iscsi_cmdq_threshold_cnt);
0903 p_stats->iscsi_rq_threshold_cnt =
0904 le32_to_cpu(tstats.iscsi_rq_threshold_cnt);
0905 p_stats->iscsi_immq_threshold_cnt =
0906 le32_to_cpu(tstats.iscsi_immq_threshold_cnt);
0907 }
0908
0909 static void _qed_iscsi_get_mstats(struct qed_hwfn *p_hwfn,
0910 struct qed_ptt *p_ptt,
0911 struct qed_iscsi_stats *p_stats)
0912 {
0913 struct mstorm_iscsi_stats_drv mstats;
0914 u32 mstats_addr;
0915
0916 memset(&mstats, 0, sizeof(mstats));
0917 mstats_addr = BAR0_MAP_REG_MSDM_RAM +
0918 MSTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
0919 qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, sizeof(mstats));
0920
0921 p_stats->iscsi_rx_dropped_pdus_task_not_valid =
0922 HILO_64_REGPAIR(mstats.iscsi_rx_dropped_pdus_task_not_valid);
0923 }
0924
0925 static void _qed_iscsi_get_ustats(struct qed_hwfn *p_hwfn,
0926 struct qed_ptt *p_ptt,
0927 struct qed_iscsi_stats *p_stats)
0928 {
0929 struct ustorm_iscsi_stats_drv ustats;
0930 u32 ustats_addr;
0931
0932 memset(&ustats, 0, sizeof(ustats));
0933 ustats_addr = BAR0_MAP_REG_USDM_RAM +
0934 USTORM_ISCSI_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
0935 qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats));
0936
0937 p_stats->iscsi_rx_data_pdu_cnt =
0938 HILO_64_REGPAIR(ustats.iscsi_rx_data_pdu_cnt);
0939 p_stats->iscsi_rx_r2t_pdu_cnt =
0940 HILO_64_REGPAIR(ustats.iscsi_rx_r2t_pdu_cnt);
0941 p_stats->iscsi_rx_total_pdu_cnt =
0942 HILO_64_REGPAIR(ustats.iscsi_rx_total_pdu_cnt);
0943 }
0944
0945 static void _qed_iscsi_get_xstats(struct qed_hwfn *p_hwfn,
0946 struct qed_ptt *p_ptt,
0947 struct qed_iscsi_stats *p_stats)
0948 {
0949 struct xstorm_iscsi_stats_drv xstats;
0950 u32 xstats_addr;
0951
0952 memset(&xstats, 0, sizeof(xstats));
0953 xstats_addr = BAR0_MAP_REG_XSDM_RAM +
0954 XSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
0955 qed_memcpy_from(p_hwfn, p_ptt, &xstats, xstats_addr, sizeof(xstats));
0956
0957 p_stats->iscsi_tx_go_to_slow_start_event_cnt =
0958 HILO_64_REGPAIR(xstats.iscsi_tx_go_to_slow_start_event_cnt);
0959 p_stats->iscsi_tx_fast_retransmit_event_cnt =
0960 HILO_64_REGPAIR(xstats.iscsi_tx_fast_retransmit_event_cnt);
0961 }
0962
0963 static void _qed_iscsi_get_ystats(struct qed_hwfn *p_hwfn,
0964 struct qed_ptt *p_ptt,
0965 struct qed_iscsi_stats *p_stats)
0966 {
0967 struct ystorm_iscsi_stats_drv ystats;
0968 u32 ystats_addr;
0969
0970 memset(&ystats, 0, sizeof(ystats));
0971 ystats_addr = BAR0_MAP_REG_YSDM_RAM +
0972 YSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
0973 qed_memcpy_from(p_hwfn, p_ptt, &ystats, ystats_addr, sizeof(ystats));
0974
0975 p_stats->iscsi_tx_data_pdu_cnt =
0976 HILO_64_REGPAIR(ystats.iscsi_tx_data_pdu_cnt);
0977 p_stats->iscsi_tx_r2t_pdu_cnt =
0978 HILO_64_REGPAIR(ystats.iscsi_tx_r2t_pdu_cnt);
0979 p_stats->iscsi_tx_total_pdu_cnt =
0980 HILO_64_REGPAIR(ystats.iscsi_tx_total_pdu_cnt);
0981 }
0982
0983 static void _qed_iscsi_get_pstats(struct qed_hwfn *p_hwfn,
0984 struct qed_ptt *p_ptt,
0985 struct qed_iscsi_stats *p_stats)
0986 {
0987 struct pstorm_iscsi_stats_drv pstats;
0988 u32 pstats_addr;
0989
0990 memset(&pstats, 0, sizeof(pstats));
0991 pstats_addr = BAR0_MAP_REG_PSDM_RAM +
0992 PSTORM_ISCSI_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
0993 qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));
0994
0995 p_stats->iscsi_tx_bytes_cnt =
0996 HILO_64_REGPAIR(pstats.iscsi_tx_bytes_cnt);
0997 p_stats->iscsi_tx_packet_cnt =
0998 HILO_64_REGPAIR(pstats.iscsi_tx_packet_cnt);
0999 }
1000
1001 static int qed_iscsi_get_stats(struct qed_hwfn *p_hwfn,
1002 struct qed_iscsi_stats *stats)
1003 {
1004 struct qed_ptt *p_ptt;
1005
1006 memset(stats, 0, sizeof(*stats));
1007
1008 p_ptt = qed_ptt_acquire(p_hwfn);
1009 if (!p_ptt) {
1010 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1011 return -EAGAIN;
1012 }
1013
1014 _qed_iscsi_get_tstats(p_hwfn, p_ptt, stats);
1015 _qed_iscsi_get_mstats(p_hwfn, p_ptt, stats);
1016 _qed_iscsi_get_ustats(p_hwfn, p_ptt, stats);
1017
1018 _qed_iscsi_get_xstats(p_hwfn, p_ptt, stats);
1019 _qed_iscsi_get_ystats(p_hwfn, p_ptt, stats);
1020 _qed_iscsi_get_pstats(p_hwfn, p_ptt, stats);
1021
1022 qed_ptt_release(p_hwfn, p_ptt);
1023
1024 return 0;
1025 }
1026
1027 struct qed_hash_iscsi_con {
1028 struct hlist_node node;
1029 struct qed_iscsi_conn *con;
1030 };
1031
1032 static int qed_fill_iscsi_dev_info(struct qed_dev *cdev,
1033 struct qed_dev_iscsi_info *info)
1034 {
1035 struct qed_hwfn *hwfn = QED_AFFIN_HWFN(cdev);
1036
1037 int rc;
1038
1039 memset(info, 0, sizeof(*info));
1040 rc = qed_fill_dev_info(cdev, &info->common);
1041
1042 info->primary_dbq_rq_addr =
1043 qed_iscsi_get_primary_bdq_prod(hwfn, BDQ_ID_RQ);
1044 info->secondary_bdq_rq_addr =
1045 qed_iscsi_get_secondary_bdq_prod(hwfn, BDQ_ID_RQ);
1046
1047 info->num_cqs = FEAT_NUM(hwfn, QED_ISCSI_CQ);
1048
1049 return rc;
1050 }
1051
1052 static void qed_register_iscsi_ops(struct qed_dev *cdev,
1053 struct qed_iscsi_cb_ops *ops, void *cookie)
1054 {
1055 cdev->protocol_ops.iscsi = ops;
1056 cdev->ops_cookie = cookie;
1057 }
1058
1059 static struct qed_hash_iscsi_con *qed_iscsi_get_hash(struct qed_dev *cdev,
1060 u32 handle)
1061 {
1062 struct qed_hash_iscsi_con *hash_con = NULL;
1063
1064 if (!(cdev->flags & QED_FLAG_STORAGE_STARTED))
1065 return NULL;
1066
1067 hash_for_each_possible(cdev->connections, hash_con, node, handle) {
1068 if (hash_con->con->icid == handle)
1069 break;
1070 }
1071
1072 if (!hash_con || (hash_con->con->icid != handle))
1073 return NULL;
1074
1075 return hash_con;
1076 }
1077
1078 static int qed_iscsi_stop(struct qed_dev *cdev)
1079 {
1080 int rc;
1081
1082 if (!(cdev->flags & QED_FLAG_STORAGE_STARTED)) {
1083 DP_NOTICE(cdev, "iscsi already stopped\n");
1084 return 0;
1085 }
1086
1087 if (!hash_empty(cdev->connections)) {
1088 DP_NOTICE(cdev,
1089 "Can't stop iscsi - not all connections were returned\n");
1090 return -EINVAL;
1091 }
1092
1093
1094 rc = qed_sp_iscsi_func_stop(QED_AFFIN_HWFN(cdev), QED_SPQ_MODE_EBLOCK,
1095 NULL);
1096 cdev->flags &= ~QED_FLAG_STORAGE_STARTED;
1097
1098 return rc;
1099 }
1100
1101 static int qed_iscsi_start(struct qed_dev *cdev,
1102 struct qed_iscsi_tid *tasks,
1103 void *event_context,
1104 iscsi_event_cb_t async_event_cb)
1105 {
1106 int rc;
1107 struct qed_tid_mem *tid_info;
1108
1109 if (cdev->flags & QED_FLAG_STORAGE_STARTED) {
1110 DP_NOTICE(cdev, "iscsi already started;\n");
1111 return 0;
1112 }
1113
1114 rc = qed_sp_iscsi_func_start(QED_AFFIN_HWFN(cdev), QED_SPQ_MODE_EBLOCK,
1115 NULL, event_context, async_event_cb);
1116 if (rc) {
1117 DP_NOTICE(cdev, "Failed to start iscsi\n");
1118 return rc;
1119 }
1120
1121 cdev->flags |= QED_FLAG_STORAGE_STARTED;
1122 hash_init(cdev->connections);
1123
1124 if (!tasks)
1125 return 0;
1126
1127 tid_info = kzalloc(sizeof(*tid_info), GFP_KERNEL);
1128
1129 if (!tid_info) {
1130 qed_iscsi_stop(cdev);
1131 return -ENOMEM;
1132 }
1133
1134 rc = qed_cxt_get_tid_mem_info(QED_AFFIN_HWFN(cdev), tid_info);
1135 if (rc) {
1136 DP_NOTICE(cdev, "Failed to gather task information\n");
1137 qed_iscsi_stop(cdev);
1138 kfree(tid_info);
1139 return rc;
1140 }
1141
1142
1143 tasks->size = tid_info->tid_size;
1144 tasks->num_tids_per_block = tid_info->num_tids_per_block;
1145 memcpy(tasks->blocks, tid_info->blocks,
1146 MAX_TID_BLOCKS_ISCSI * sizeof(u8 *));
1147
1148 kfree(tid_info);
1149
1150 return 0;
1151 }
1152
1153 static int qed_iscsi_acquire_conn(struct qed_dev *cdev,
1154 u32 *handle,
1155 u32 *fw_cid, void __iomem **p_doorbell)
1156 {
1157 struct qed_hash_iscsi_con *hash_con;
1158 int rc;
1159
1160
1161 hash_con = kzalloc(sizeof(*hash_con), GFP_ATOMIC);
1162 if (!hash_con)
1163 return -ENOMEM;
1164
1165
1166 rc = qed_iscsi_acquire_connection(QED_AFFIN_HWFN(cdev), NULL,
1167 &hash_con->con);
1168 if (rc) {
1169 DP_NOTICE(cdev, "Failed to acquire Connection\n");
1170 kfree(hash_con);
1171 return rc;
1172 }
1173
1174
1175 *handle = hash_con->con->icid;
1176 *fw_cid = hash_con->con->fw_cid;
1177 hash_add(cdev->connections, &hash_con->node, *handle);
1178
1179 if (p_doorbell)
1180 *p_doorbell = qed_iscsi_get_db_addr(QED_AFFIN_HWFN(cdev),
1181 *handle);
1182
1183 return 0;
1184 }
1185
1186 static int qed_iscsi_release_conn(struct qed_dev *cdev, u32 handle)
1187 {
1188 struct qed_hash_iscsi_con *hash_con;
1189
1190 hash_con = qed_iscsi_get_hash(cdev, handle);
1191 if (!hash_con) {
1192 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1193 handle);
1194 return -EINVAL;
1195 }
1196
1197 hlist_del(&hash_con->node);
1198 qed_iscsi_release_connection(QED_AFFIN_HWFN(cdev), hash_con->con);
1199 kfree(hash_con);
1200
1201 return 0;
1202 }
1203
1204 static int qed_iscsi_offload_conn(struct qed_dev *cdev,
1205 u32 handle,
1206 struct qed_iscsi_params_offload *conn_info)
1207 {
1208 struct qed_hash_iscsi_con *hash_con;
1209 struct qed_iscsi_conn *con;
1210
1211 hash_con = qed_iscsi_get_hash(cdev, handle);
1212 if (!hash_con) {
1213 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1214 handle);
1215 return -EINVAL;
1216 }
1217
1218
1219 con = hash_con->con;
1220
1221 ether_addr_copy(con->local_mac, conn_info->src.mac);
1222 ether_addr_copy(con->remote_mac, conn_info->dst.mac);
1223 memcpy(con->local_ip, conn_info->src.ip, sizeof(con->local_ip));
1224 memcpy(con->remote_ip, conn_info->dst.ip, sizeof(con->remote_ip));
1225 con->local_port = conn_info->src.port;
1226 con->remote_port = conn_info->dst.port;
1227
1228 con->layer_code = conn_info->layer_code;
1229 con->sq_pbl_addr = conn_info->sq_pbl_addr;
1230 con->initial_ack = conn_info->initial_ack;
1231 con->vlan_id = conn_info->vlan_id;
1232 con->tcp_flags = conn_info->tcp_flags;
1233 con->ip_version = conn_info->ip_version;
1234 con->default_cq = conn_info->default_cq;
1235 con->ka_max_probe_cnt = conn_info->ka_max_probe_cnt;
1236 con->dup_ack_theshold = conn_info->dup_ack_theshold;
1237 con->rcv_next = conn_info->rcv_next;
1238 con->snd_una = conn_info->snd_una;
1239 con->snd_next = conn_info->snd_next;
1240 con->snd_max = conn_info->snd_max;
1241 con->snd_wnd = conn_info->snd_wnd;
1242 con->rcv_wnd = conn_info->rcv_wnd;
1243 con->snd_wl1 = conn_info->snd_wl1;
1244 con->cwnd = conn_info->cwnd;
1245 con->ss_thresh = conn_info->ss_thresh;
1246 con->srtt = conn_info->srtt;
1247 con->rtt_var = conn_info->rtt_var;
1248 con->ts_recent = conn_info->ts_recent;
1249 con->ts_recent_age = conn_info->ts_recent_age;
1250 con->total_rt = conn_info->total_rt;
1251 con->ka_timeout_delta = conn_info->ka_timeout_delta;
1252 con->rt_timeout_delta = conn_info->rt_timeout_delta;
1253 con->dup_ack_cnt = conn_info->dup_ack_cnt;
1254 con->snd_wnd_probe_cnt = conn_info->snd_wnd_probe_cnt;
1255 con->ka_probe_cnt = conn_info->ka_probe_cnt;
1256 con->rt_cnt = conn_info->rt_cnt;
1257 con->flow_label = conn_info->flow_label;
1258 con->ka_timeout = conn_info->ka_timeout;
1259 con->ka_interval = conn_info->ka_interval;
1260 con->max_rt_time = conn_info->max_rt_time;
1261 con->initial_rcv_wnd = conn_info->initial_rcv_wnd;
1262 con->ttl = conn_info->ttl;
1263 con->tos_or_tc = conn_info->tos_or_tc;
1264 con->remote_port = conn_info->remote_port;
1265 con->local_port = conn_info->local_port;
1266 con->mss = conn_info->mss;
1267 con->snd_wnd_scale = conn_info->snd_wnd_scale;
1268 con->rcv_wnd_scale = conn_info->rcv_wnd_scale;
1269 con->da_timeout_value = conn_info->da_timeout_value;
1270 con->ack_frequency = conn_info->ack_frequency;
1271
1272
1273 con->offl_flags = 0x1;
1274
1275 return qed_sp_iscsi_conn_offload(QED_AFFIN_HWFN(cdev), con,
1276 QED_SPQ_MODE_EBLOCK, NULL);
1277 }
1278
1279 static int qed_iscsi_update_conn(struct qed_dev *cdev,
1280 u32 handle,
1281 struct qed_iscsi_params_update *conn_info)
1282 {
1283 struct qed_hash_iscsi_con *hash_con;
1284 struct qed_iscsi_conn *con;
1285
1286 hash_con = qed_iscsi_get_hash(cdev, handle);
1287 if (!hash_con) {
1288 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1289 handle);
1290 return -EINVAL;
1291 }
1292
1293
1294 con = hash_con->con;
1295 con->update_flag = conn_info->update_flag;
1296 con->max_seq_size = conn_info->max_seq_size;
1297 con->max_recv_pdu_length = conn_info->max_recv_pdu_length;
1298 con->max_send_pdu_length = conn_info->max_send_pdu_length;
1299 con->first_seq_length = conn_info->first_seq_length;
1300 con->exp_stat_sn = conn_info->exp_stat_sn;
1301
1302 return qed_sp_iscsi_conn_update(QED_AFFIN_HWFN(cdev), con,
1303 QED_SPQ_MODE_EBLOCK, NULL);
1304 }
1305
1306 static int qed_iscsi_clear_conn_sq(struct qed_dev *cdev, u32 handle)
1307 {
1308 struct qed_hash_iscsi_con *hash_con;
1309
1310 hash_con = qed_iscsi_get_hash(cdev, handle);
1311 if (!hash_con) {
1312 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1313 handle);
1314 return -EINVAL;
1315 }
1316
1317 return qed_sp_iscsi_conn_clear_sq(QED_AFFIN_HWFN(cdev), hash_con->con,
1318 QED_SPQ_MODE_EBLOCK, NULL);
1319 }
1320
1321 static int qed_iscsi_destroy_conn(struct qed_dev *cdev,
1322 u32 handle, u8 abrt_conn)
1323 {
1324 struct qed_hash_iscsi_con *hash_con;
1325
1326 hash_con = qed_iscsi_get_hash(cdev, handle);
1327 if (!hash_con) {
1328 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1329 handle);
1330 return -EINVAL;
1331 }
1332
1333 hash_con->con->abortive_dsconnect = abrt_conn;
1334
1335 return qed_sp_iscsi_conn_terminate(QED_AFFIN_HWFN(cdev), hash_con->con,
1336 QED_SPQ_MODE_EBLOCK, NULL);
1337 }
1338
1339 static int qed_iscsi_stats(struct qed_dev *cdev, struct qed_iscsi_stats *stats)
1340 {
1341 return qed_iscsi_get_stats(QED_AFFIN_HWFN(cdev), stats);
1342 }
1343
1344 static int qed_iscsi_change_mac(struct qed_dev *cdev,
1345 u32 handle, const u8 *mac)
1346 {
1347 struct qed_hash_iscsi_con *hash_con;
1348
1349 hash_con = qed_iscsi_get_hash(cdev, handle);
1350 if (!hash_con) {
1351 DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
1352 handle);
1353 return -EINVAL;
1354 }
1355
1356 return qed_sp_iscsi_mac_update(QED_AFFIN_HWFN(cdev), hash_con->con,
1357 QED_SPQ_MODE_EBLOCK, NULL);
1358 }
1359
1360 void qed_get_protocol_stats_iscsi(struct qed_dev *cdev,
1361 struct qed_mcp_iscsi_stats *stats)
1362 {
1363 struct qed_iscsi_stats proto_stats;
1364
1365
1366 memset(&proto_stats, 0, sizeof(proto_stats));
1367 if (qed_iscsi_stats(cdev, &proto_stats)) {
1368 DP_VERBOSE(cdev, QED_MSG_STORAGE,
1369 "Failed to collect ISCSI statistics\n");
1370 return;
1371 }
1372
1373
1374 stats->rx_pdus = proto_stats.iscsi_rx_total_pdu_cnt;
1375 stats->tx_pdus = proto_stats.iscsi_tx_total_pdu_cnt;
1376 stats->rx_bytes = proto_stats.iscsi_rx_bytes_cnt;
1377 stats->tx_bytes = proto_stats.iscsi_tx_bytes_cnt;
1378 }
1379
1380 static const struct qed_iscsi_ops qed_iscsi_ops_pass = {
1381 .common = &qed_common_ops_pass,
1382 .ll2 = &qed_ll2_ops_pass,
1383 .fill_dev_info = &qed_fill_iscsi_dev_info,
1384 .register_ops = &qed_register_iscsi_ops,
1385 .start = &qed_iscsi_start,
1386 .stop = &qed_iscsi_stop,
1387 .acquire_conn = &qed_iscsi_acquire_conn,
1388 .release_conn = &qed_iscsi_release_conn,
1389 .offload_conn = &qed_iscsi_offload_conn,
1390 .update_conn = &qed_iscsi_update_conn,
1391 .destroy_conn = &qed_iscsi_destroy_conn,
1392 .clear_sq = &qed_iscsi_clear_conn_sq,
1393 .get_stats = &qed_iscsi_stats,
1394 .change_mac = &qed_iscsi_change_mac,
1395 };
1396
1397 const struct qed_iscsi_ops *qed_get_iscsi_ops(void)
1398 {
1399 return &qed_iscsi_ops_pass;
1400 }
1401 EXPORT_SYMBOL(qed_get_iscsi_ops);
1402
1403 void qed_put_iscsi_ops(void)
1404 {
1405 }
1406 EXPORT_SYMBOL(qed_put_iscsi_ops);