1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2008 Cisco Systems, Inc. All rights reserved. 4 * Copyright 2007 Nuova Systems, Inc. All rights reserved. 5 */ 6 7 #include <linux/workqueue.h> 8 #include "fnic.h" 9 #include "fdls_fc.h" 10 #include "fnic_fdls.h" 11 #include <scsi/fc/fc_fcp.h> 12 #include <scsi/scsi_transport_fc.h> 13 #include <linux/utsname.h> 14 15 #define FC_FC4_TYPE_SCSI 0x08 16 #define PORT_SPEED_BIT_8 8 17 #define PORT_SPEED_BIT_9 9 18 #define PORT_SPEED_BIT_14 14 19 #define PORT_SPEED_BIT_15 15 20 21 /* FNIC FDMI Register HBA Macros */ 22 #define FNIC_FDMI_NUM_PORTS 1 23 #define FNIC_FDMI_NUM_HBA_ATTRS 9 24 #define FNIC_FDMI_TYPE_NODE_NAME 0X1 25 #define FNIC_FDMI_TYPE_MANUFACTURER 0X2 26 #define FNIC_FDMI_MANUFACTURER "Cisco Systems" 27 #define FNIC_FDMI_TYPE_SERIAL_NUMBER 0X3 28 #define FNIC_FDMI_TYPE_MODEL 0X4 29 #define FNIC_FDMI_TYPE_MODEL_DES 0X5 30 #define FNIC_FDMI_MODEL_DESCRIPTION "Cisco Virtual Interface Card" 31 #define FNIC_FDMI_TYPE_HARDWARE_VERSION 0X6 32 #define FNIC_FDMI_TYPE_DRIVER_VERSION 0X7 33 #define FNIC_FDMI_TYPE_ROM_VERSION 0X8 34 #define FNIC_FDMI_TYPE_FIRMWARE_VERSION 0X9 35 #define FNIC_FDMI_NN_LEN 8 36 #define FNIC_FDMI_MANU_LEN 20 37 #define FNIC_FDMI_SERIAL_LEN 16 38 #define FNIC_FDMI_MODEL_LEN 12 39 #define FNIC_FDMI_MODEL_DES_LEN 56 40 #define FNIC_FDMI_HW_VER_LEN 16 41 #define FNIC_FDMI_DR_VER_LEN 28 42 #define FNIC_FDMI_ROM_VER_LEN 8 43 #define FNIC_FDMI_FW_VER_LEN 16 44 45 /* FNIC FDMI Register PA Macros */ 46 #define FNIC_FDMI_TYPE_FC4_TYPES 0X1 47 #define FNIC_FDMI_TYPE_SUPPORTED_SPEEDS 0X2 48 #define FNIC_FDMI_TYPE_CURRENT_SPEED 0X3 49 #define FNIC_FDMI_TYPE_MAX_FRAME_SIZE 0X4 50 #define FNIC_FDMI_TYPE_OS_NAME 0X5 51 #define FNIC_FDMI_TYPE_HOST_NAME 0X6 52 #define FNIC_FDMI_NUM_PORT_ATTRS 6 53 #define FNIC_FDMI_FC4_LEN 32 54 #define FNIC_FDMI_SUPP_SPEED_LEN 4 55 #define FNIC_FDMI_CUR_SPEED_LEN 4 56 #define FNIC_FDMI_MFS_LEN 4 57 #define FNIC_FDMI_MFS 0x800 58 #define FNIC_FDMI_OS_NAME_LEN 16 59 #define FNIC_FDMI_HN_LEN 24 60 61 #define FDLS_FDMI_PLOGI_PENDING 0x1 62 #define FDLS_FDMI_REG_HBA_PENDING 0x2 63 #define FDLS_FDMI_RPA_PENDING 0x4 64 #define FDLS_FDMI_ABORT_PENDING 0x8 65 #define FDLS_FDMI_MAX_RETRY 3 66 67 #define RETRIES_EXHAUSTED(iport) \ 68 (iport->fabric.retry_counter == FABRIC_LOGO_MAX_RETRY) 69 70 #define FNIC_TPORT_MAX_NEXUS_RESTART (8) 71 72 #define SCHEDULE_OXID_FREE_RETRY_TIME (300) 73 74 /* Private Functions */ 75 static void fdls_fdmi_register_hba(struct fnic_iport_s *iport); 76 static void fdls_fdmi_register_pa(struct fnic_iport_s *iport); 77 static void fdls_send_rpn_id(struct fnic_iport_s *iport); 78 static void fdls_process_flogi_rsp(struct fnic_iport_s *iport, 79 struct fc_frame_header *fchdr, 80 void *rx_frame); 81 static void fnic_fdls_start_plogi(struct fnic_iport_s *iport); 82 static void fnic_fdls_start_flogi(struct fnic_iport_s *iport); 83 static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport, 84 uint32_t fcid, 85 uint64_t wwpn); 86 static void fdls_target_restart_nexus(struct fnic_tport_s *tport); 87 static void fdls_start_tport_timer(struct fnic_iport_s *iport, 88 struct fnic_tport_s *tport, int timeout); 89 static void fdls_tport_timer_callback(struct timer_list *t); 90 static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport); 91 static void fdls_start_fabric_timer(struct fnic_iport_s *iport, 92 int timeout); 93 static void fdls_init_plogi_frame(uint8_t *frame, struct fnic_iport_s *iport); 94 static void fdls_init_els_acc_frame(uint8_t *frame, struct fnic_iport_s *iport); 95 static void fdls_init_els_rjt_frame(uint8_t *frame, struct fnic_iport_s *iport); 96 static void fdls_init_logo_frame(uint8_t *frame, struct fnic_iport_s *iport); 97 static void fdls_init_fabric_abts_frame(uint8_t *frame, 98 struct fnic_iport_s *iport); 99 100 uint8_t *fdls_alloc_frame(struct fnic_iport_s *iport) 101 { 102 struct fnic *fnic = iport->fnic; 103 uint8_t *frame = NULL; 104 105 frame = mempool_alloc(fnic->frame_pool, GFP_ATOMIC); 106 if (frame == NULL) { 107 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 108 "Failed to allocate frame"); 109 return NULL; 110 } 111 112 memset(frame, 0, FNIC_FCOE_FRAME_MAXSZ); 113 return frame; 114 } 115 116 /** 117 * fdls_alloc_oxid - Allocate an oxid from the bitmap based oxid pool 118 * @iport: Handle to iport instance 119 * @oxid_frame_type: Type of frame to allocate 120 * @active_oxid: the oxid which is in use 121 * 122 * Called with fnic lock held 123 */ 124 uint16_t fdls_alloc_oxid(struct fnic_iport_s *iport, int oxid_frame_type, 125 uint16_t *active_oxid) 126 { 127 struct fnic *fnic = iport->fnic; 128 struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool; 129 int idx; 130 uint16_t oxid; 131 132 lockdep_assert_held(&fnic->fnic_lock); 133 134 /* 135 * Allocate next available oxid from bitmap 136 */ 137 idx = find_next_zero_bit(oxid_pool->bitmap, FNIC_OXID_POOL_SZ, oxid_pool->next_idx); 138 if (idx == FNIC_OXID_POOL_SZ) { 139 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 140 "Alloc oxid: all oxid slots are busy iport state:%d\n", 141 iport->state); 142 return FNIC_UNASSIGNED_OXID; 143 } 144 145 WARN_ON(test_and_set_bit(idx, oxid_pool->bitmap)); 146 oxid_pool->next_idx = (idx + 1) % FNIC_OXID_POOL_SZ; /* cycle through the bitmap */ 147 148 oxid = FNIC_OXID_ENCODE(idx, oxid_frame_type); 149 *active_oxid = oxid; 150 151 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 152 "alloc oxid: 0x%x, iport state: %d\n", 153 oxid, iport->state); 154 return oxid; 155 } 156 157 /** 158 * fdls_free_oxid_idx - Free the oxid using the idx 159 * @iport: Handle to iport instance 160 * @oxid_idx: The index to free 161 * 162 * Free the oxid immediately and make it available for new requests 163 * Called with fnic lock held 164 */ 165 static void fdls_free_oxid_idx(struct fnic_iport_s *iport, uint16_t oxid_idx) 166 { 167 struct fnic *fnic = iport->fnic; 168 struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool; 169 170 lockdep_assert_held(&fnic->fnic_lock); 171 172 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 173 "free oxid idx: 0x%x\n", oxid_idx); 174 175 WARN_ON(!test_and_clear_bit(oxid_idx, oxid_pool->bitmap)); 176 } 177 178 /** 179 * fdls_reclaim_oxid_handler - Callback handler for delayed_oxid_work 180 * @work: Handle to work_struct 181 * 182 * Scheduled when an oxid is to be freed later 183 * After freeing expired oxid(s), the handler schedules 184 * another callback with the remaining time 185 * of next unexpired entry in the reclaim list. 186 */ 187 void fdls_reclaim_oxid_handler(struct work_struct *work) 188 { 189 struct fnic_oxid_pool_s *oxid_pool = container_of(work, 190 struct fnic_oxid_pool_s, oxid_reclaim_work.work); 191 struct fnic_iport_s *iport = container_of(oxid_pool, 192 struct fnic_iport_s, oxid_pool); 193 struct fnic *fnic = iport->fnic; 194 struct reclaim_entry_s *reclaim_entry, *next; 195 unsigned long delay_j, cur_jiffies; 196 197 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 198 "Reclaim oxid callback\n"); 199 200 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 201 202 /* Though the work was scheduled for one entry, 203 * walk through and free the expired entries which might have been scheduled 204 * at around the same time as the first entry 205 */ 206 list_for_each_entry_safe(reclaim_entry, next, 207 &(oxid_pool->oxid_reclaim_list), links) { 208 209 /* The list is always maintained in the order of expiry time */ 210 cur_jiffies = jiffies; 211 if (time_before(cur_jiffies, reclaim_entry->expires)) 212 break; 213 214 list_del(&reclaim_entry->links); 215 fdls_free_oxid_idx(iport, reclaim_entry->oxid_idx); 216 kfree(reclaim_entry); 217 } 218 219 /* schedule to free up the next entry */ 220 if (!list_empty(&oxid_pool->oxid_reclaim_list)) { 221 reclaim_entry = list_first_entry(&oxid_pool->oxid_reclaim_list, 222 struct reclaim_entry_s, links); 223 224 delay_j = reclaim_entry->expires - cur_jiffies; 225 schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j); 226 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 227 "Scheduling next callback at:%ld jiffies\n", delay_j); 228 } 229 230 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 231 } 232 233 /** 234 * fdls_free_oxid - Helper function to free the oxid 235 * @iport: Handle to iport instance 236 * @oxid: oxid to free 237 * @active_oxid: the oxid which is in use 238 * 239 * Called with fnic lock held 240 */ 241 void fdls_free_oxid(struct fnic_iport_s *iport, 242 uint16_t oxid, uint16_t *active_oxid) 243 { 244 fdls_free_oxid_idx(iport, FNIC_OXID_IDX(oxid)); 245 *active_oxid = FNIC_UNASSIGNED_OXID; 246 } 247 248 /** 249 * fdls_schedule_oxid_free - Schedule oxid to be freed later 250 * @iport: Handle to iport instance 251 * @active_oxid: the oxid which is in use 252 * 253 * Gets called in a rare case scenario when both a command 254 * (fdls or target discovery) timed out and the following ABTS 255 * timed out as well, without a link change. 256 * 257 * Called with fnic lock held 258 */ 259 void fdls_schedule_oxid_free(struct fnic_iport_s *iport, uint16_t *active_oxid) 260 { 261 struct fnic *fnic = iport->fnic; 262 struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool; 263 struct reclaim_entry_s *reclaim_entry; 264 unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport)); 265 int oxid_idx = FNIC_OXID_IDX(*active_oxid); 266 267 lockdep_assert_held(&fnic->fnic_lock); 268 269 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 270 "Schedule oxid free. oxid: 0x%x\n", *active_oxid); 271 272 *active_oxid = FNIC_UNASSIGNED_OXID; 273 274 reclaim_entry = (struct reclaim_entry_s *) 275 kzalloc(sizeof(struct reclaim_entry_s), GFP_ATOMIC); 276 277 if (!reclaim_entry) { 278 FNIC_FCS_DBG(KERN_WARNING, fnic->host, fnic->fnic_num, 279 "Failed to allocate memory for reclaim struct for oxid idx: %d\n", 280 oxid_idx); 281 282 /* Retry the scheduling */ 283 WARN_ON(test_and_set_bit(oxid_idx, oxid_pool->pending_schedule_free)); 284 schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry, 0); 285 return; 286 } 287 288 reclaim_entry->oxid_idx = oxid_idx; 289 reclaim_entry->expires = round_jiffies(jiffies + delay_j); 290 291 list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list); 292 293 schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j); 294 } 295 296 /** 297 * fdls_schedule_oxid_free_retry_work - Thread to schedule the 298 * oxid to be freed later 299 * 300 * @work: Handle to the work struct 301 */ 302 void fdls_schedule_oxid_free_retry_work(struct work_struct *work) 303 { 304 struct fnic_oxid_pool_s *oxid_pool = container_of(work, 305 struct fnic_oxid_pool_s, schedule_oxid_free_retry.work); 306 struct fnic_iport_s *iport = container_of(oxid_pool, 307 struct fnic_iport_s, oxid_pool); 308 struct fnic *fnic = iport->fnic; 309 struct reclaim_entry_s *reclaim_entry; 310 unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport)); 311 unsigned long flags; 312 int idx; 313 314 for_each_set_bit(idx, oxid_pool->pending_schedule_free, FNIC_OXID_POOL_SZ) { 315 316 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 317 "Schedule oxid free. oxid idx: %d\n", idx); 318 319 reclaim_entry = kzalloc(sizeof(*reclaim_entry), GFP_KERNEL); 320 if (!reclaim_entry) { 321 schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry, 322 msecs_to_jiffies(SCHEDULE_OXID_FREE_RETRY_TIME)); 323 return; 324 } 325 326 clear_bit(idx, oxid_pool->pending_schedule_free); 327 reclaim_entry->oxid_idx = idx; 328 reclaim_entry->expires = round_jiffies(jiffies + delay_j); 329 spin_lock_irqsave(&fnic->fnic_lock, flags); 330 list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list); 331 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 332 schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j); 333 } 334 } 335 336 static bool fdls_is_oxid_fabric_req(uint16_t oxid) 337 { 338 int oxid_frame_type = FNIC_FRAME_TYPE(oxid); 339 340 switch (oxid_frame_type) { 341 case FNIC_FRAME_TYPE_FABRIC_FLOGI: 342 case FNIC_FRAME_TYPE_FABRIC_PLOGI: 343 case FNIC_FRAME_TYPE_FABRIC_RPN: 344 case FNIC_FRAME_TYPE_FABRIC_RFT: 345 case FNIC_FRAME_TYPE_FABRIC_RFF: 346 case FNIC_FRAME_TYPE_FABRIC_GPN_FT: 347 case FNIC_FRAME_TYPE_FABRIC_LOGO: 348 break; 349 default: 350 return false; 351 } 352 return true; 353 } 354 355 static bool fdls_is_oxid_fdmi_req(uint16_t oxid) 356 { 357 int oxid_frame_type = FNIC_FRAME_TYPE(oxid); 358 359 switch (oxid_frame_type) { 360 case FNIC_FRAME_TYPE_FDMI_PLOGI: 361 case FNIC_FRAME_TYPE_FDMI_RHBA: 362 case FNIC_FRAME_TYPE_FDMI_RPA: 363 break; 364 default: 365 return false; 366 } 367 return true; 368 } 369 370 static bool fdls_is_oxid_tgt_req(uint16_t oxid) 371 { 372 int oxid_frame_type = FNIC_FRAME_TYPE(oxid); 373 374 switch (oxid_frame_type) { 375 case FNIC_FRAME_TYPE_TGT_PLOGI: 376 case FNIC_FRAME_TYPE_TGT_PRLI: 377 case FNIC_FRAME_TYPE_TGT_ADISC: 378 case FNIC_FRAME_TYPE_TGT_LOGO: 379 break; 380 default: 381 return false; 382 } 383 return true; 384 } 385 386 static void fdls_reset_oxid_pool(struct fnic_iport_s *iport) 387 { 388 struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool; 389 390 oxid_pool->next_idx = 0; 391 } 392 393 void fnic_del_fabric_timer_sync(struct fnic *fnic) 394 { 395 fnic->iport.fabric.del_timer_inprogress = 1; 396 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 397 timer_delete_sync(&fnic->iport.fabric.retry_timer); 398 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 399 fnic->iport.fabric.del_timer_inprogress = 0; 400 } 401 402 void fnic_del_tport_timer_sync(struct fnic *fnic, 403 struct fnic_tport_s *tport) 404 { 405 tport->del_timer_inprogress = 1; 406 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 407 timer_delete_sync(&tport->retry_timer); 408 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 409 tport->del_timer_inprogress = 0; 410 } 411 412 static void 413 fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout) 414 { 415 u64 fabric_tov; 416 struct fnic *fnic = iport->fnic; 417 418 if (iport->fabric.timer_pending) { 419 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 420 "iport fcid: 0x%x: Canceling fabric disc timer\n", 421 iport->fcid); 422 fnic_del_fabric_timer_sync(fnic); 423 iport->fabric.timer_pending = 0; 424 } 425 426 if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) 427 iport->fabric.retry_counter++; 428 429 fabric_tov = jiffies + msecs_to_jiffies(timeout); 430 mod_timer(&iport->fabric.retry_timer, round_jiffies(fabric_tov)); 431 iport->fabric.timer_pending = 1; 432 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 433 "fabric timer is %d ", timeout); 434 } 435 436 static void 437 fdls_start_tport_timer(struct fnic_iport_s *iport, 438 struct fnic_tport_s *tport, int timeout) 439 { 440 u64 fabric_tov; 441 struct fnic *fnic = iport->fnic; 442 443 if (tport->timer_pending) { 444 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 445 "tport fcid 0x%x: Canceling disc timer\n", 446 tport->fcid); 447 fnic_del_tport_timer_sync(fnic, tport); 448 tport->timer_pending = 0; 449 } 450 451 if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) 452 tport->retry_counter++; 453 454 fabric_tov = jiffies + msecs_to_jiffies(timeout); 455 mod_timer(&tport->retry_timer, round_jiffies(fabric_tov)); 456 tport->timer_pending = 1; 457 } 458 459 void fdls_init_plogi_frame(uint8_t *frame, 460 struct fnic_iport_s *iport) 461 { 462 struct fc_std_flogi *pplogi; 463 uint8_t s_id[3]; 464 465 pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 466 *pplogi = (struct fc_std_flogi) { 467 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFC}, 468 .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 469 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 470 .els = { 471 .fl_cmd = ELS_PLOGI, 472 .fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI, 473 .sp_lo_ver = FNIC_FC_PH_VER_LO, 474 .sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT), 475 .sp_features = cpu_to_be16(FC_SP_FT_CIRO), 476 .sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ), 477 .sp_tot_seq = cpu_to_be16(FNIC_FC_CONCUR_SEQS), 478 .sp_rel_off = cpu_to_be16(FNIC_FC_RO_INFO), 479 .sp_e_d_tov = cpu_to_be32(FC_DEF_E_D_TOV)}, 480 .fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ), 481 .fl_cssp[2].cp_rdfs = cpu_to_be16(0x800), 482 .fl_cssp[2].cp_con_seq = cpu_to_be16(0xFF), 483 .fl_cssp[2].cp_open_seq = 1} 484 }; 485 486 FNIC_STD_SET_NPORT_NAME(&pplogi->els.fl_wwpn, iport->wwpn); 487 FNIC_STD_SET_NODE_NAME(&pplogi->els.fl_wwnn, iport->wwnn); 488 FNIC_LOGI_SET_RDF_SIZE(pplogi->els, iport->max_payload_size); 489 490 hton24(s_id, iport->fcid); 491 FNIC_STD_SET_S_ID(pplogi->fchdr, s_id); 492 } 493 494 static void fdls_init_els_acc_frame(uint8_t *frame, 495 struct fnic_iport_s *iport) 496 { 497 struct fc_std_els_acc_rsp *pels_acc; 498 uint8_t s_id[3]; 499 500 pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 501 *pels_acc = (struct fc_std_els_acc_rsp) { 502 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP, 503 .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}}, 504 .acc.la_cmd = ELS_LS_ACC, 505 }; 506 507 hton24(s_id, iport->fcid); 508 FNIC_STD_SET_S_ID(pels_acc->fchdr, s_id); 509 FNIC_STD_SET_RX_ID(pels_acc->fchdr, FNIC_UNASSIGNED_RXID); 510 } 511 512 static void fdls_init_els_rjt_frame(uint8_t *frame, 513 struct fnic_iport_s *iport) 514 { 515 struct fc_std_els_rjt_rsp *pels_rjt; 516 517 pels_rjt = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 518 *pels_rjt = (struct fc_std_els_rjt_rsp) { 519 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP, .fh_type = FC_TYPE_ELS, 520 .fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}}, 521 .rej.er_cmd = ELS_LS_RJT, 522 }; 523 524 FNIC_STD_SET_RX_ID(pels_rjt->fchdr, FNIC_UNASSIGNED_RXID); 525 } 526 527 static void fdls_init_logo_frame(uint8_t *frame, 528 struct fnic_iport_s *iport) 529 { 530 struct fc_std_logo *plogo; 531 uint8_t s_id[3]; 532 533 plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 534 *plogo = (struct fc_std_logo) { 535 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS, 536 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}}, 537 .els.fl_cmd = ELS_LOGO, 538 }; 539 540 hton24(s_id, iport->fcid); 541 FNIC_STD_SET_S_ID(plogo->fchdr, s_id); 542 memcpy(plogo->els.fl_n_port_id, s_id, 3); 543 544 FNIC_STD_SET_NPORT_NAME(&plogo->els.fl_n_port_wwn, 545 iport->wwpn); 546 } 547 548 static void fdls_init_fabric_abts_frame(uint8_t *frame, 549 struct fnic_iport_s *iport) 550 { 551 struct fc_frame_header *pfabric_abts; 552 553 pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 554 *pfabric_abts = (struct fc_frame_header) { 555 .fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */ 556 .fh_s_id = {0x00, 0x00, 0x00}, 557 .fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS, 558 .fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00, 559 .fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000, 560 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID), 561 .fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */ 562 }; 563 } 564 565 static void 566 fdls_send_rscn_resp(struct fnic_iport_s *iport, 567 struct fc_frame_header *rscn_fchdr) 568 { 569 uint8_t *frame; 570 struct fc_std_els_acc_rsp *pels_acc; 571 struct fnic *fnic = iport->fnic; 572 uint16_t oxid; 573 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 574 sizeof(struct fc_std_els_acc_rsp); 575 576 frame = fdls_alloc_frame(iport); 577 if (frame == NULL) { 578 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 579 "Failed to allocate frame to send RSCN response"); 580 return; 581 } 582 583 pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 584 fdls_init_els_acc_frame(frame, iport); 585 586 FNIC_STD_SET_D_ID(pels_acc->fchdr, rscn_fchdr->fh_s_id); 587 588 oxid = FNIC_STD_GET_OX_ID(rscn_fchdr); 589 FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid); 590 591 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 592 "0x%x: FDLS send RSCN response with oxid: 0x%x", 593 iport->fcid, oxid); 594 595 fnic_send_fcoe_frame(iport, frame, frame_size); 596 } 597 598 static void 599 fdls_send_logo_resp(struct fnic_iport_s *iport, 600 struct fc_frame_header *req_fchdr) 601 { 602 uint8_t *frame; 603 struct fc_std_els_acc_rsp *plogo_resp; 604 struct fnic *fnic = iport->fnic; 605 uint16_t oxid; 606 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 607 sizeof(struct fc_std_els_acc_rsp); 608 609 frame = fdls_alloc_frame(iport); 610 if (frame == NULL) { 611 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 612 "Failed to allocate frame to send LOGO response"); 613 return; 614 } 615 616 plogo_resp = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 617 fdls_init_els_acc_frame(frame, iport); 618 619 FNIC_STD_SET_D_ID(plogo_resp->fchdr, req_fchdr->fh_s_id); 620 621 oxid = FNIC_STD_GET_OX_ID(req_fchdr); 622 FNIC_STD_SET_OX_ID(plogo_resp->fchdr, oxid); 623 624 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 625 "0x%x: FDLS send LOGO response with oxid: 0x%x", 626 iport->fcid, oxid); 627 628 fnic_send_fcoe_frame(iport, frame, frame_size); 629 } 630 631 void 632 fdls_send_tport_abts(struct fnic_iport_s *iport, 633 struct fnic_tport_s *tport) 634 { 635 uint8_t *frame; 636 uint8_t s_id[3]; 637 uint8_t d_id[3]; 638 struct fnic *fnic = iport->fnic; 639 struct fc_frame_header *ptport_abts; 640 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 641 sizeof(struct fc_frame_header); 642 643 frame = fdls_alloc_frame(iport); 644 if (frame == NULL) { 645 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 646 "Failed to allocate frame to send tport ABTS"); 647 return; 648 } 649 650 ptport_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 651 *ptport_abts = (struct fc_frame_header) { 652 .fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */ 653 .fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS, 654 .fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00, 655 .fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000, 656 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID), 657 .fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */ 658 }; 659 660 hton24(s_id, iport->fcid); 661 hton24(d_id, tport->fcid); 662 FNIC_STD_SET_S_ID(*ptport_abts, s_id); 663 FNIC_STD_SET_D_ID(*ptport_abts, d_id); 664 tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED; 665 666 FNIC_STD_SET_OX_ID(*ptport_abts, tport->active_oxid); 667 668 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 669 "0x%x: FDLS send tport abts: tport->state: %d ", 670 iport->fcid, tport->state); 671 672 fnic_send_fcoe_frame(iport, frame, frame_size); 673 674 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 675 fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov); 676 } 677 static void fdls_send_fabric_abts(struct fnic_iport_s *iport) 678 { 679 uint8_t *frame; 680 uint8_t s_id[3]; 681 uint8_t d_id[3]; 682 struct fnic *fnic = iport->fnic; 683 struct fc_frame_header *pfabric_abts; 684 uint16_t oxid; 685 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 686 sizeof(struct fc_frame_header); 687 688 frame = fdls_alloc_frame(iport); 689 if (frame == NULL) { 690 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 691 "Failed to allocate frame to send fabric ABTS"); 692 return; 693 } 694 695 pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 696 fdls_init_fabric_abts_frame(frame, iport); 697 698 hton24(s_id, iport->fcid); 699 700 switch (iport->fabric.state) { 701 case FDLS_STATE_FABRIC_LOGO: 702 hton24(d_id, FC_FID_FLOGI); 703 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 704 break; 705 706 case FDLS_STATE_FABRIC_FLOGI: 707 hton24(d_id, FC_FID_FLOGI); 708 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 709 break; 710 711 case FDLS_STATE_FABRIC_PLOGI: 712 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 713 hton24(d_id, FC_FID_DIR_SERV); 714 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 715 break; 716 717 case FDLS_STATE_RPN_ID: 718 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 719 hton24(d_id, FC_FID_DIR_SERV); 720 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 721 break; 722 723 case FDLS_STATE_SCR: 724 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 725 hton24(d_id, FC_FID_FCTRL); 726 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 727 break; 728 729 case FDLS_STATE_REGISTER_FC4_TYPES: 730 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 731 hton24(d_id, FC_FID_DIR_SERV); 732 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 733 break; 734 735 case FDLS_STATE_REGISTER_FC4_FEATURES: 736 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 737 hton24(d_id, FC_FID_DIR_SERV); 738 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 739 break; 740 741 case FDLS_STATE_GPN_FT: 742 FNIC_STD_SET_S_ID(*pfabric_abts, s_id); 743 hton24(d_id, FC_FID_DIR_SERV); 744 FNIC_STD_SET_D_ID(*pfabric_abts, d_id); 745 break; 746 default: 747 return; 748 } 749 750 oxid = iport->active_oxid_fabric_req; 751 FNIC_STD_SET_OX_ID(*pfabric_abts, oxid); 752 753 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 754 "0x%x: FDLS send fabric abts. iport->fabric.state: %d oxid: 0x%x", 755 iport->fcid, iport->fabric.state, oxid); 756 757 iport->fabric.flags |= FNIC_FDLS_FABRIC_ABORT_ISSUED; 758 759 fnic_send_fcoe_frame(iport, frame, frame_size); 760 761 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 762 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 763 iport->fabric.timer_pending = 1; 764 } 765 766 static uint8_t *fdls_alloc_init_fdmi_abts_frame(struct fnic_iport_s *iport, 767 uint16_t oxid) 768 { 769 struct fc_frame_header *pfdmi_abts; 770 uint8_t d_id[3]; 771 uint8_t *frame; 772 struct fnic *fnic = iport->fnic; 773 774 frame = fdls_alloc_frame(iport); 775 if (frame == NULL) { 776 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 777 "Failed to allocate frame to send FDMI ABTS"); 778 return NULL; 779 } 780 781 pfdmi_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 782 fdls_init_fabric_abts_frame(frame, iport); 783 784 hton24(d_id, FC_FID_MGMT_SERV); 785 FNIC_STD_SET_D_ID(*pfdmi_abts, d_id); 786 FNIC_STD_SET_OX_ID(*pfdmi_abts, oxid); 787 788 return frame; 789 } 790 791 static void fdls_send_fdmi_abts(struct fnic_iport_s *iport) 792 { 793 uint8_t *frame; 794 struct fnic *fnic = iport->fnic; 795 unsigned long fdmi_tov; 796 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 797 sizeof(struct fc_frame_header); 798 799 if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) { 800 frame = fdls_alloc_init_fdmi_abts_frame(iport, 801 iport->active_oxid_fdmi_plogi); 802 if (frame == NULL) 803 return; 804 805 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 806 "0x%x: FDLS send FDMI PLOGI abts. iport->fabric.state: %d oxid: 0x%x", 807 iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_plogi); 808 fnic_send_fcoe_frame(iport, frame, frame_size); 809 } else { 810 if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) { 811 frame = fdls_alloc_init_fdmi_abts_frame(iport, 812 iport->active_oxid_fdmi_rhba); 813 if (frame == NULL) 814 return; 815 816 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 817 "0x%x: FDLS send FDMI RHBA abts. iport->fabric.state: %d oxid: 0x%x", 818 iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_rhba); 819 fnic_send_fcoe_frame(iport, frame, frame_size); 820 } 821 if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING) { 822 frame = fdls_alloc_init_fdmi_abts_frame(iport, 823 iport->active_oxid_fdmi_rpa); 824 if (frame == NULL) { 825 if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) 826 goto arm_timer; 827 else 828 return; 829 } 830 831 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 832 "0x%x: FDLS send FDMI RPA abts. iport->fabric.state: %d oxid: 0x%x", 833 iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_rpa); 834 fnic_send_fcoe_frame(iport, frame, frame_size); 835 } 836 } 837 838 arm_timer: 839 fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov); 840 mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov)); 841 iport->fabric.fdmi_pending |= FDLS_FDMI_ABORT_PENDING; 842 843 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 844 "0x%x: iport->fabric.fdmi_pending: 0x%x", 845 iport->fcid, iport->fabric.fdmi_pending); 846 } 847 848 static void fdls_send_fabric_flogi(struct fnic_iport_s *iport) 849 { 850 uint8_t *frame; 851 struct fc_std_flogi *pflogi; 852 struct fnic *fnic = iport->fnic; 853 uint16_t oxid; 854 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 855 sizeof(struct fc_std_flogi); 856 857 frame = fdls_alloc_frame(iport); 858 if (frame == NULL) { 859 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 860 "Failed to allocate frame to send FLOGI"); 861 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 862 goto err_out; 863 } 864 865 pflogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 866 *pflogi = (struct fc_std_flogi) { 867 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFE}, 868 .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 869 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 870 .els.fl_cmd = ELS_FLOGI, 871 .els.fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI, 872 .sp_lo_ver = FNIC_FC_PH_VER_LO, 873 .sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT), 874 .sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ)}, 875 .els.fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ) 876 }; 877 878 FNIC_STD_SET_NPORT_NAME(&pflogi->els.fl_wwpn, iport->wwpn); 879 FNIC_STD_SET_NODE_NAME(&pflogi->els.fl_wwnn, iport->wwnn); 880 FNIC_LOGI_SET_RDF_SIZE(pflogi->els, iport->max_payload_size); 881 FNIC_LOGI_SET_R_A_TOV(pflogi->els, iport->r_a_tov); 882 FNIC_LOGI_SET_E_D_TOV(pflogi->els, iport->e_d_tov); 883 884 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_FLOGI, 885 &iport->active_oxid_fabric_req); 886 887 if (oxid == FNIC_UNASSIGNED_OXID) { 888 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 889 "0x%x: Failed to allocate OXID to send FLOGI", 890 iport->fcid); 891 mempool_free(frame, fnic->frame_pool); 892 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 893 goto err_out; 894 } 895 FNIC_STD_SET_OX_ID(pflogi->fchdr, oxid); 896 897 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 898 "0x%x: FDLS send fabric FLOGI with oxid: 0x%x", iport->fcid, 899 oxid); 900 901 fnic_send_fcoe_frame(iport, frame, frame_size); 902 atomic64_inc(&iport->iport_stats.fabric_flogi_sent); 903 err_out: 904 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 905 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 906 } 907 908 static void fdls_send_fabric_plogi(struct fnic_iport_s *iport) 909 { 910 uint8_t *frame; 911 struct fc_std_flogi *pplogi; 912 struct fnic *fnic = iport->fnic; 913 uint16_t oxid; 914 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 915 sizeof(struct fc_std_flogi); 916 917 frame = fdls_alloc_frame(iport); 918 if (frame == NULL) { 919 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 920 "Failed to allocate frame to send PLOGI"); 921 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 922 goto err_out; 923 } 924 925 pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 926 fdls_init_plogi_frame(frame, iport); 927 928 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_PLOGI, 929 &iport->active_oxid_fabric_req); 930 if (oxid == FNIC_UNASSIGNED_OXID) { 931 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 932 "0x%x: Failed to allocate OXID to send fabric PLOGI", 933 iport->fcid); 934 mempool_free(frame, fnic->frame_pool); 935 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 936 goto err_out; 937 } 938 FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid); 939 940 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 941 "0x%x: FDLS send fabric PLOGI with oxid: 0x%x", iport->fcid, 942 oxid); 943 944 fnic_send_fcoe_frame(iport, frame, frame_size); 945 atomic64_inc(&iport->iport_stats.fabric_plogi_sent); 946 947 err_out: 948 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 949 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 950 } 951 952 static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport) 953 { 954 uint8_t *frame; 955 struct fc_std_flogi *pplogi; 956 struct fnic *fnic = iport->fnic; 957 uint16_t oxid; 958 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 959 sizeof(struct fc_std_flogi); 960 uint8_t d_id[3]; 961 u64 fdmi_tov; 962 963 frame = fdls_alloc_frame(iport); 964 if (frame == NULL) { 965 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 966 "Failed to allocate frame to send FDMI PLOGI"); 967 goto err_out; 968 } 969 970 pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 971 fdls_init_plogi_frame(frame, iport); 972 973 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_PLOGI, 974 &iport->active_oxid_fdmi_plogi); 975 976 if (oxid == FNIC_UNASSIGNED_OXID) { 977 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 978 "0x%x: Failed to allocate OXID to send FDMI PLOGI", 979 iport->fcid); 980 mempool_free(frame, fnic->frame_pool); 981 goto err_out; 982 } 983 FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid); 984 985 hton24(d_id, FC_FID_MGMT_SERV); 986 FNIC_STD_SET_D_ID(pplogi->fchdr, d_id); 987 988 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 989 "0x%x: FDLS send FDMI PLOGI with oxid: 0x%x", 990 iport->fcid, oxid); 991 992 fnic_send_fcoe_frame(iport, frame, frame_size); 993 994 err_out: 995 fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov); 996 mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov)); 997 iport->fabric.fdmi_pending = FDLS_FDMI_PLOGI_PENDING; 998 } 999 1000 static void fdls_send_rpn_id(struct fnic_iport_s *iport) 1001 { 1002 uint8_t *frame; 1003 struct fc_std_rpn_id *prpn_id; 1004 struct fnic *fnic = iport->fnic; 1005 uint16_t oxid; 1006 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1007 sizeof(struct fc_std_rpn_id); 1008 uint8_t fcid[3]; 1009 1010 frame = fdls_alloc_frame(iport); 1011 if (frame == NULL) { 1012 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1013 "Failed to allocate frame to send RPN_ID"); 1014 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1015 goto err_out; 1016 } 1017 1018 prpn_id = (struct fc_std_rpn_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1019 *prpn_id = (struct fc_std_rpn_id) { 1020 .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 1021 .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT, 1022 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1023 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1024 .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR, 1025 .ct_fs_subtype = FC_NS_SUBTYPE, 1026 .ct_cmd = cpu_to_be16(FC_NS_RPN_ID)} 1027 }; 1028 1029 hton24(fcid, iport->fcid); 1030 FNIC_STD_SET_S_ID(prpn_id->fchdr, fcid); 1031 1032 FNIC_STD_SET_PORT_ID(prpn_id->rpn_id, fcid); 1033 FNIC_STD_SET_PORT_NAME(prpn_id->rpn_id, iport->wwpn); 1034 1035 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RPN, 1036 &iport->active_oxid_fabric_req); 1037 1038 if (oxid == FNIC_UNASSIGNED_OXID) { 1039 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1040 "0x%x: Failed to allocate OXID to send RPN_ID", 1041 iport->fcid); 1042 mempool_free(frame, fnic->frame_pool); 1043 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1044 goto err_out; 1045 } 1046 FNIC_STD_SET_OX_ID(prpn_id->fchdr, oxid); 1047 1048 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1049 "0x%x: FDLS send RPN ID with oxid: 0x%x", iport->fcid, 1050 oxid); 1051 1052 fnic_send_fcoe_frame(iport, frame, frame_size); 1053 1054 err_out: 1055 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1056 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1057 } 1058 1059 static void fdls_send_scr(struct fnic_iport_s *iport) 1060 { 1061 uint8_t *frame; 1062 struct fc_std_scr *pscr; 1063 struct fnic *fnic = iport->fnic; 1064 uint16_t oxid; 1065 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1066 sizeof(struct fc_std_scr); 1067 uint8_t fcid[3]; 1068 1069 frame = fdls_alloc_frame(iport); 1070 if (frame == NULL) { 1071 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1072 "Failed to allocate frame to send SCR"); 1073 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1074 goto err_out; 1075 } 1076 1077 pscr = (struct fc_std_scr *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1078 *pscr = (struct fc_std_scr) { 1079 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, 1080 .fh_d_id = {0xFF, 0xFF, 0xFD}, .fh_type = FC_TYPE_ELS, 1081 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1082 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1083 .scr = {.scr_cmd = ELS_SCR, 1084 .scr_reg_func = ELS_SCRF_FULL} 1085 }; 1086 1087 hton24(fcid, iport->fcid); 1088 FNIC_STD_SET_S_ID(pscr->fchdr, fcid); 1089 1090 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_SCR, 1091 &iport->active_oxid_fabric_req); 1092 if (oxid == FNIC_UNASSIGNED_OXID) { 1093 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1094 "0x%x: Failed to allocate OXID to send SCR", 1095 iport->fcid); 1096 mempool_free(frame, fnic->frame_pool); 1097 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1098 goto err_out; 1099 } 1100 FNIC_STD_SET_OX_ID(pscr->fchdr, oxid); 1101 1102 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1103 "0x%x: FDLS send SCR with oxid: 0x%x", iport->fcid, 1104 oxid); 1105 1106 fnic_send_fcoe_frame(iport, frame, frame_size); 1107 atomic64_inc(&iport->iport_stats.fabric_scr_sent); 1108 1109 err_out: 1110 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1111 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1112 } 1113 1114 static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state) 1115 { 1116 uint8_t *frame; 1117 struct fc_std_gpn_ft *pgpn_ft; 1118 struct fnic *fnic = iport->fnic; 1119 uint16_t oxid; 1120 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1121 sizeof(struct fc_std_gpn_ft); 1122 uint8_t fcid[3]; 1123 1124 frame = fdls_alloc_frame(iport); 1125 if (frame == NULL) { 1126 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1127 "Failed to allocate frame to send GPN FT"); 1128 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1129 goto err_out; 1130 } 1131 1132 pgpn_ft = (struct fc_std_gpn_ft *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1133 *pgpn_ft = (struct fc_std_gpn_ft) { 1134 .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 1135 .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT, 1136 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1137 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1138 .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR, 1139 .ct_fs_subtype = FC_NS_SUBTYPE, 1140 .ct_cmd = cpu_to_be16(FC_NS_GPN_FT)}, 1141 .gpn_ft.fn_fc4_type = 0x08 1142 }; 1143 1144 hton24(fcid, iport->fcid); 1145 FNIC_STD_SET_S_ID(pgpn_ft->fchdr, fcid); 1146 1147 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_GPN_FT, 1148 &iport->active_oxid_fabric_req); 1149 1150 if (oxid == FNIC_UNASSIGNED_OXID) { 1151 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1152 "0x%x: Failed to allocate OXID to send GPN FT", 1153 iport->fcid); 1154 mempool_free(frame, fnic->frame_pool); 1155 iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME; 1156 goto err_out; 1157 } 1158 FNIC_STD_SET_OX_ID(pgpn_ft->fchdr, oxid); 1159 1160 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1161 "0x%x: FDLS send GPN FT with oxid: 0x%x", iport->fcid, 1162 oxid); 1163 1164 fnic_send_fcoe_frame(iport, frame, frame_size); 1165 1166 err_out: 1167 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1168 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1169 fdls_set_state((&iport->fabric), fdls_state); 1170 } 1171 1172 static void 1173 fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport) 1174 { 1175 uint8_t *frame; 1176 struct fc_std_els_adisc *padisc; 1177 uint8_t s_id[3]; 1178 uint8_t d_id[3]; 1179 uint16_t oxid; 1180 struct fnic *fnic = iport->fnic; 1181 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1182 sizeof(struct fc_std_els_adisc); 1183 1184 frame = fdls_alloc_frame(iport); 1185 if (frame == NULL) { 1186 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1187 "Failed to allocate frame to send TGT ADISC"); 1188 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1189 goto err_out; 1190 } 1191 1192 padisc = (struct fc_std_els_adisc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1193 1194 hton24(s_id, iport->fcid); 1195 hton24(d_id, tport->fcid); 1196 memcpy(padisc->els.adisc_port_id, s_id, 3); 1197 FNIC_STD_SET_S_ID(padisc->fchdr, s_id); 1198 FNIC_STD_SET_D_ID(padisc->fchdr, d_id); 1199 1200 FNIC_STD_SET_F_CTL(padisc->fchdr, FNIC_ELS_REQ_FCTL << 16); 1201 FNIC_STD_SET_R_CTL(padisc->fchdr, FC_RCTL_ELS_REQ); 1202 FNIC_STD_SET_TYPE(padisc->fchdr, FC_TYPE_ELS); 1203 1204 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_ADISC, &tport->active_oxid); 1205 if (oxid == FNIC_UNASSIGNED_OXID) { 1206 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1207 "0x%x: Failed to allocate OXID to send TGT ADISC", 1208 iport->fcid); 1209 mempool_free(frame, fnic->frame_pool); 1210 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1211 goto err_out; 1212 } 1213 FNIC_STD_SET_OX_ID(padisc->fchdr, oxid); 1214 FNIC_STD_SET_RX_ID(padisc->fchdr, FNIC_UNASSIGNED_RXID); 1215 1216 tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED; 1217 1218 FNIC_STD_SET_NPORT_NAME(&padisc->els.adisc_wwpn, 1219 iport->wwpn); 1220 FNIC_STD_SET_NODE_NAME(&padisc->els.adisc_wwnn, 1221 iport->wwnn); 1222 1223 padisc->els.adisc_cmd = ELS_ADISC; 1224 1225 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1226 "0x%x: FDLS send ADISC to tgt fcid: 0x%x", 1227 iport->fcid, tport->fcid); 1228 1229 atomic64_inc(&iport->iport_stats.tport_adisc_sent); 1230 1231 fnic_send_fcoe_frame(iport, frame, frame_size); 1232 1233 err_out: 1234 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1235 fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov); 1236 } 1237 1238 bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport) 1239 { 1240 struct fnic_tport_event_s *tport_del_evt; 1241 struct fnic *fnic = iport->fnic; 1242 1243 if ((tport->state == FDLS_TGT_STATE_OFFLINING) 1244 || (tport->state == FDLS_TGT_STATE_OFFLINE)) { 1245 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1246 "tport fcid 0x%x: tport state is offlining/offline\n", 1247 tport->fcid); 1248 return false; 1249 } 1250 1251 fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINING); 1252 /* 1253 * By setting this flag, the tport will not be seen in a look-up 1254 * in an RSCN. Even if we move to multithreaded model, this tport 1255 * will be destroyed and a new RSCN will have to create a new one 1256 */ 1257 tport->flags |= FNIC_FDLS_TPORT_TERMINATING; 1258 1259 if (tport->timer_pending) { 1260 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1261 "tport fcid 0x%x: Canceling disc timer\n", 1262 tport->fcid); 1263 fnic_del_tport_timer_sync(fnic, tport); 1264 tport->timer_pending = 0; 1265 } 1266 1267 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 1268 fnic_rport_exch_reset(iport->fnic, tport->fcid); 1269 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 1270 1271 if (tport->flags & FNIC_FDLS_SCSI_REGISTERED) { 1272 tport_del_evt = 1273 kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC); 1274 if (!tport_del_evt) { 1275 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1276 "Failed to allocate memory for tport fcid: 0x%0x\n", 1277 tport->fcid); 1278 return false; 1279 } 1280 tport_del_evt->event = TGT_EV_RPORT_DEL; 1281 tport_del_evt->arg1 = (void *) tport; 1282 list_add_tail(&tport_del_evt->links, &fnic->tport_event_list); 1283 queue_work(fnic_event_queue, &fnic->tport_work); 1284 } else { 1285 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1286 "tport 0x%x not reg with scsi_transport. Freeing locally", 1287 tport->fcid); 1288 list_del(&tport->links); 1289 kfree(tport); 1290 } 1291 return true; 1292 } 1293 1294 static void 1295 fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport) 1296 { 1297 uint8_t *frame; 1298 struct fc_std_flogi *pplogi; 1299 struct fnic *fnic = iport->fnic; 1300 uint16_t oxid; 1301 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1302 sizeof(struct fc_std_flogi); 1303 uint8_t d_id[3]; 1304 uint32_t timeout; 1305 1306 frame = fdls_alloc_frame(iport); 1307 if (frame == NULL) { 1308 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1309 "Failed to allocate frame to send TGT PLOGI"); 1310 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1311 goto err_out; 1312 } 1313 1314 pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1315 fdls_init_plogi_frame(frame, iport); 1316 1317 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PLOGI, &tport->active_oxid); 1318 if (oxid == FNIC_UNASSIGNED_OXID) { 1319 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1320 "0x%x: Failed to allocate oxid to send PLOGI to fcid: 0x%x", 1321 iport->fcid, tport->fcid); 1322 mempool_free(frame, fnic->frame_pool); 1323 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1324 goto err_out; 1325 } 1326 FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid); 1327 1328 tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED; 1329 1330 hton24(d_id, tport->fcid); 1331 FNIC_STD_SET_D_ID(pplogi->fchdr, d_id); 1332 1333 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1334 "0x%x: FDLS send tgt PLOGI to tgt: 0x%x with oxid: 0x%x", 1335 iport->fcid, tport->fcid, oxid); 1336 1337 fnic_send_fcoe_frame(iport, frame, frame_size); 1338 atomic64_inc(&iport->iport_stats.tport_plogi_sent); 1339 1340 err_out: 1341 timeout = max(2 * iport->e_d_tov, iport->plogi_timeout); 1342 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1343 fdls_start_tport_timer(iport, tport, timeout); 1344 } 1345 1346 static uint16_t 1347 fnic_fc_plogi_rsp_rdf(struct fnic_iport_s *iport, 1348 struct fc_std_flogi *plogi_rsp) 1349 { 1350 uint16_t b2b_rdf_size = 1351 be16_to_cpu(FNIC_LOGI_RDF_SIZE(plogi_rsp->els)); 1352 uint16_t spc3_rdf_size = 1353 be16_to_cpu(plogi_rsp->els.fl_cssp[2].cp_rdfs) & FNIC_FC_C3_RDF; 1354 struct fnic *fnic = iport->fnic; 1355 1356 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1357 "MFS: b2b_rdf_size: 0x%x spc3_rdf_size: 0x%x", 1358 b2b_rdf_size, spc3_rdf_size); 1359 1360 return min(b2b_rdf_size, spc3_rdf_size); 1361 } 1362 1363 static void fdls_send_register_fc4_types(struct fnic_iport_s *iport) 1364 { 1365 uint8_t *frame; 1366 struct fc_std_rft_id *prft_id; 1367 struct fnic *fnic = iport->fnic; 1368 uint16_t oxid; 1369 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1370 sizeof(struct fc_std_rft_id); 1371 uint8_t fcid[3]; 1372 1373 frame = fdls_alloc_frame(iport); 1374 if (frame == NULL) { 1375 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1376 "Failed to allocate frame to send RFT"); 1377 return; 1378 } 1379 1380 prft_id = (struct fc_std_rft_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1381 *prft_id = (struct fc_std_rft_id) { 1382 .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 1383 .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT, 1384 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1385 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1386 .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR, 1387 .ct_fs_subtype = FC_NS_SUBTYPE, 1388 .ct_cmd = cpu_to_be16(FC_NS_RFT_ID)} 1389 }; 1390 1391 hton24(fcid, iport->fcid); 1392 FNIC_STD_SET_S_ID(prft_id->fchdr, fcid); 1393 FNIC_STD_SET_PORT_ID(prft_id->rft_id, fcid); 1394 1395 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFT, 1396 &iport->active_oxid_fabric_req); 1397 1398 if (oxid == FNIC_UNASSIGNED_OXID) { 1399 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1400 "0x%x: Failed to allocate OXID to send RFT", 1401 iport->fcid); 1402 mempool_free(frame, fnic->frame_pool); 1403 return; 1404 } 1405 FNIC_STD_SET_OX_ID(prft_id->fchdr, oxid); 1406 1407 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1408 "0x%x: FDLS send RFT with oxid: 0x%x", iport->fcid, 1409 oxid); 1410 1411 prft_id->rft_id.fr_fts.ff_type_map[0] = 1412 cpu_to_be32(1 << FC_TYPE_FCP); 1413 1414 prft_id->rft_id.fr_fts.ff_type_map[1] = 1415 cpu_to_be32(1 << (FC_TYPE_CT % FC_NS_BPW)); 1416 1417 fnic_send_fcoe_frame(iport, frame, frame_size); 1418 1419 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1420 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1421 } 1422 1423 static void fdls_send_register_fc4_features(struct fnic_iport_s *iport) 1424 { 1425 uint8_t *frame; 1426 struct fc_std_rff_id *prff_id; 1427 struct fnic *fnic = iport->fnic; 1428 uint16_t oxid; 1429 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1430 sizeof(struct fc_std_rff_id); 1431 uint8_t fcid[3]; 1432 1433 frame = fdls_alloc_frame(iport); 1434 if (frame == NULL) { 1435 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1436 "Failed to allocate frame to send RFF"); 1437 return; 1438 } 1439 1440 prff_id = (struct fc_std_rff_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1441 *prff_id = (struct fc_std_rff_id) { 1442 .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 1443 .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT, 1444 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1445 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1446 .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR, 1447 .ct_fs_subtype = FC_NS_SUBTYPE, 1448 .ct_cmd = cpu_to_be16(FC_NS_RFF_ID)}, 1449 .rff_id.fr_feat = 0x2, 1450 .rff_id.fr_type = FC_TYPE_FCP 1451 }; 1452 1453 hton24(fcid, iport->fcid); 1454 FNIC_STD_SET_S_ID(prff_id->fchdr, fcid); 1455 FNIC_STD_SET_PORT_ID(prff_id->rff_id, fcid); 1456 1457 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFF, 1458 &iport->active_oxid_fabric_req); 1459 1460 if (oxid == FNIC_UNASSIGNED_OXID) { 1461 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1462 "0x%x: Failed to allocate OXID to send RFF", 1463 iport->fcid); 1464 mempool_free(frame, fnic->frame_pool); 1465 return; 1466 } 1467 FNIC_STD_SET_OX_ID(prff_id->fchdr, oxid); 1468 1469 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1470 "0x%x: FDLS send RFF with oxid: 0x%x", iport->fcid, 1471 oxid); 1472 1473 prff_id->rff_id.fr_type = FC_TYPE_FCP; 1474 1475 fnic_send_fcoe_frame(iport, frame, frame_size); 1476 1477 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1478 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1479 } 1480 1481 static void 1482 fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport) 1483 { 1484 uint8_t *frame; 1485 struct fc_std_els_prli *pprli; 1486 struct fnic *fnic = iport->fnic; 1487 uint16_t oxid; 1488 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1489 sizeof(struct fc_std_els_prli); 1490 uint8_t s_id[3]; 1491 uint8_t d_id[3]; 1492 uint32_t timeout; 1493 1494 frame = fdls_alloc_frame(iport); 1495 if (frame == NULL) { 1496 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1497 "Failed to allocate frame to send TGT PRLI"); 1498 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1499 goto err_out; 1500 } 1501 1502 pprli = (struct fc_std_els_prli *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1503 *pprli = (struct fc_std_els_prli) { 1504 .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS, 1505 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1506 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)}, 1507 .els_prli = {.prli_cmd = ELS_PRLI, 1508 .prli_spp_len = 16, 1509 .prli_len = cpu_to_be16(0x14)}, 1510 .sp = {.spp_type = 0x08, .spp_flags = 0x0020, 1511 .spp_params = cpu_to_be32(0xA2)} 1512 }; 1513 1514 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PRLI, &tport->active_oxid); 1515 if (oxid == FNIC_UNASSIGNED_OXID) { 1516 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1517 "0x%x: Failed to allocate OXID to send TGT PRLI to 0x%x", 1518 iport->fcid, tport->fcid); 1519 mempool_free(frame, fnic->frame_pool); 1520 tport->flags |= FNIC_FDLS_RETRY_FRAME; 1521 goto err_out; 1522 } 1523 1524 tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED; 1525 1526 hton24(s_id, iport->fcid); 1527 hton24(d_id, tport->fcid); 1528 1529 FNIC_STD_SET_OX_ID(pprli->fchdr, oxid); 1530 FNIC_STD_SET_S_ID(pprli->fchdr, s_id); 1531 FNIC_STD_SET_D_ID(pprli->fchdr, d_id); 1532 1533 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1534 "0x%x: FDLS send PRLI to tgt: 0x%x with oxid: 0x%x", 1535 iport->fcid, tport->fcid, oxid); 1536 1537 fnic_send_fcoe_frame(iport, frame, frame_size); 1538 atomic64_inc(&iport->iport_stats.tport_prli_sent); 1539 1540 err_out: 1541 timeout = max(2 * iport->e_d_tov, iport->plogi_timeout); 1542 /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */ 1543 fdls_start_tport_timer(iport, tport, timeout); 1544 } 1545 1546 /** 1547 * fdls_send_fabric_logo - Send flogo to the fcf 1548 * @iport: Handle to fnic iport 1549 * 1550 * This function does not change or check the fabric state. 1551 * It the caller's responsibility to set the appropriate iport fabric 1552 * state when this is called. Normally it is FDLS_STATE_FABRIC_LOGO. 1553 * Currently this assumes to be called with fnic lock held. 1554 */ 1555 void fdls_send_fabric_logo(struct fnic_iport_s *iport) 1556 { 1557 uint8_t *frame; 1558 struct fc_std_logo *plogo; 1559 struct fnic *fnic = iport->fnic; 1560 uint8_t d_id[3]; 1561 uint16_t oxid; 1562 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1563 sizeof(struct fc_std_logo); 1564 1565 frame = fdls_alloc_frame(iport); 1566 if (frame == NULL) { 1567 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1568 "Failed to allocate frame to send fabric LOGO"); 1569 return; 1570 } 1571 1572 plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1573 fdls_init_logo_frame(frame, iport); 1574 1575 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_LOGO, 1576 &iport->active_oxid_fabric_req); 1577 1578 if (oxid == FNIC_UNASSIGNED_OXID) { 1579 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1580 "0x%x: Failed to allocate OXID to send fabric LOGO", 1581 iport->fcid); 1582 mempool_free(frame, fnic->frame_pool); 1583 return; 1584 } 1585 FNIC_STD_SET_OX_ID(plogo->fchdr, oxid); 1586 1587 hton24(d_id, FC_FID_FLOGI); 1588 FNIC_STD_SET_D_ID(plogo->fchdr, d_id); 1589 1590 iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED; 1591 1592 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1593 "0x%x: FDLS send fabric LOGO with oxid: 0x%x", 1594 iport->fcid, oxid); 1595 1596 fnic_send_fcoe_frame(iport, frame, frame_size); 1597 1598 fdls_start_fabric_timer(iport, 2 * iport->e_d_tov); 1599 } 1600 1601 /** 1602 * fdls_tgt_logout - Send plogo to the remote port 1603 * @iport: Handle to fnic iport 1604 * @tport: Handle to remote port 1605 * 1606 * This function does not change or check the fabric/tport state. 1607 * It the caller's responsibility to set the appropriate tport/fabric 1608 * state when this is called. Normally that is fdls_tgt_state_plogo. 1609 * This could be used to send plogo to nameserver process 1610 * also not just target processes 1611 */ 1612 void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport) 1613 { 1614 uint8_t *frame; 1615 struct fc_std_logo *plogo; 1616 struct fnic *fnic = iport->fnic; 1617 uint8_t d_id[3]; 1618 uint16_t oxid; 1619 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 1620 sizeof(struct fc_std_logo); 1621 1622 frame = fdls_alloc_frame(iport); 1623 if (frame == NULL) { 1624 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1625 "Failed to allocate frame to send fabric LOGO"); 1626 return; 1627 } 1628 1629 plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1630 fdls_init_logo_frame(frame, iport); 1631 1632 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_LOGO, &tport->active_oxid); 1633 if (oxid == FNIC_UNASSIGNED_OXID) { 1634 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1635 "0x%x: Failed to allocate OXID to send tgt LOGO", 1636 iport->fcid); 1637 mempool_free(frame, fnic->frame_pool); 1638 return; 1639 } 1640 FNIC_STD_SET_OX_ID(plogo->fchdr, oxid); 1641 1642 hton24(d_id, tport->fcid); 1643 FNIC_STD_SET_D_ID(plogo->fchdr, d_id); 1644 1645 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1646 "0x%x: FDLS send tgt LOGO with oxid: 0x%x", 1647 iport->fcid, oxid); 1648 1649 fnic_send_fcoe_frame(iport, frame, frame_size); 1650 1651 atomic64_inc(&iport->iport_stats.tport_logo_sent); 1652 } 1653 1654 static void fdls_tgt_discovery_start(struct fnic_iport_s *iport) 1655 { 1656 struct fnic_tport_s *tport, *next; 1657 u32 old_link_down_cnt = iport->fnic->link_down_cnt; 1658 struct fnic *fnic = iport->fnic; 1659 1660 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1661 "0x%x: Starting FDLS target discovery", iport->fcid); 1662 1663 list_for_each_entry_safe(tport, next, &iport->tport_list, links) { 1664 if ((old_link_down_cnt != iport->fnic->link_down_cnt) 1665 || (iport->state != FNIC_IPORT_STATE_READY)) { 1666 break; 1667 } 1668 /* if we marked the tport as deleted due to GPN_FT 1669 * We should not send ADISC anymore 1670 */ 1671 if ((tport->state == FDLS_TGT_STATE_OFFLINING) || 1672 (tport->state == FDLS_TGT_STATE_OFFLINE)) 1673 continue; 1674 1675 /* For tports which have received RSCN */ 1676 if (tport->flags & FNIC_FDLS_TPORT_SEND_ADISC) { 1677 tport->retry_counter = 0; 1678 fdls_set_tport_state(tport, FDLS_TGT_STATE_ADISC); 1679 tport->flags &= ~FNIC_FDLS_TPORT_SEND_ADISC; 1680 fdls_send_tgt_adisc(iport, tport); 1681 continue; 1682 } 1683 if (fdls_get_tport_state(tport) != FDLS_TGT_STATE_INIT) { 1684 /* Not a new port, skip */ 1685 continue; 1686 } 1687 tport->retry_counter = 0; 1688 fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI); 1689 fdls_send_tgt_plogi(iport, tport); 1690 } 1691 fdls_set_state((&iport->fabric), FDLS_STATE_TGT_DISCOVERY); 1692 } 1693 1694 /* 1695 * Function to restart the IT nexus if we received any out of 1696 * sequence PLOGI/PRLI response from the target. 1697 * The memory for the new tport structure is allocated 1698 * inside fdls_create_tport and added to the iport's tport list. 1699 * This will get freed later during tport_offline/linkdown 1700 * or module unload. The new_tport pointer will go out of scope 1701 * safely since the memory it is 1702 * pointing to it will be freed later 1703 */ 1704 static void fdls_target_restart_nexus(struct fnic_tport_s *tport) 1705 { 1706 struct fnic_iport_s *iport = tport->iport; 1707 struct fnic_tport_s *new_tport = NULL; 1708 uint32_t fcid; 1709 uint64_t wwpn; 1710 int nexus_restart_count; 1711 struct fnic *fnic = iport->fnic; 1712 bool retval = true; 1713 1714 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1715 "tport fcid: 0x%x state: %d restart_count: %d", 1716 tport->fcid, tport->state, tport->nexus_restart_count); 1717 1718 fcid = tport->fcid; 1719 wwpn = tport->wwpn; 1720 nexus_restart_count = tport->nexus_restart_count; 1721 1722 retval = fdls_delete_tport(iport, tport); 1723 if (retval != true) { 1724 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1725 "Error deleting tport: 0x%x", fcid); 1726 return; 1727 } 1728 1729 if (nexus_restart_count >= FNIC_TPORT_MAX_NEXUS_RESTART) { 1730 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1731 "Exceeded nexus restart retries tport: 0x%x", 1732 fcid); 1733 return; 1734 } 1735 1736 /* 1737 * Allocate memory for the new tport and add it to 1738 * iport's tport list. 1739 * This memory will be freed during tport_offline/linkdown 1740 * or module unload. The pointer new_tport is safe to go 1741 * out of scope when this function returns, since the memory 1742 * it is pointing to is guaranteed to be freed later 1743 * as mentioned above. 1744 */ 1745 new_tport = fdls_create_tport(iport, fcid, wwpn); 1746 if (!new_tport) { 1747 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1748 "Error creating new tport: 0x%x", fcid); 1749 return; 1750 } 1751 1752 new_tport->nexus_restart_count = nexus_restart_count + 1; 1753 fdls_send_tgt_plogi(iport, new_tport); 1754 fdls_set_tport_state(new_tport, FDLS_TGT_STATE_PLOGI); 1755 } 1756 1757 struct fnic_tport_s *fnic_find_tport_by_fcid(struct fnic_iport_s *iport, 1758 uint32_t fcid) 1759 { 1760 struct fnic_tport_s *tport, *next; 1761 1762 list_for_each_entry_safe(tport, next, &(iport->tport_list), links) { 1763 if ((tport->fcid == fcid) 1764 && !(tport->flags & FNIC_FDLS_TPORT_TERMINATING)) 1765 return tport; 1766 } 1767 return NULL; 1768 } 1769 1770 static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport, 1771 uint32_t fcid, uint64_t wwpn) 1772 { 1773 struct fnic_tport_s *tport; 1774 struct fnic *fnic = iport->fnic; 1775 1776 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1777 "FDLS create tport: fcid: 0x%x wwpn: 0x%llx", fcid, wwpn); 1778 1779 tport = kzalloc(sizeof(struct fnic_tport_s), GFP_ATOMIC); 1780 if (!tport) { 1781 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1782 "Memory allocation failure while creating tport: 0x%x\n", 1783 fcid); 1784 return NULL; 1785 } 1786 1787 tport->max_payload_size = FNIC_FCOE_MAX_FRAME_SZ; 1788 tport->r_a_tov = FC_DEF_R_A_TOV; 1789 tport->e_d_tov = FC_DEF_E_D_TOV; 1790 tport->fcid = fcid; 1791 tport->wwpn = wwpn; 1792 tport->iport = iport; 1793 1794 FNIC_FCS_DBG(KERN_DEBUG, fnic->host, fnic->fnic_num, 1795 "Need to setup tport timer callback"); 1796 1797 timer_setup(&tport->retry_timer, fdls_tport_timer_callback, 0); 1798 1799 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1800 "Added tport 0x%x", tport->fcid); 1801 fdls_set_tport_state(tport, FDLS_TGT_STATE_INIT); 1802 list_add_tail(&tport->links, &iport->tport_list); 1803 atomic_set(&tport->in_flight, 0); 1804 return tport; 1805 } 1806 1807 struct fnic_tport_s *fnic_find_tport_by_wwpn(struct fnic_iport_s *iport, 1808 uint64_t wwpn) 1809 { 1810 struct fnic_tport_s *tport, *next; 1811 1812 list_for_each_entry_safe(tport, next, &(iport->tport_list), links) { 1813 if ((tport->wwpn == wwpn) 1814 && !(tport->flags & FNIC_FDLS_TPORT_TERMINATING)) 1815 return tport; 1816 } 1817 return NULL; 1818 } 1819 1820 static void 1821 fnic_fdmi_attr_set(void *attr_start, u16 type, u16 len, 1822 void *data, u32 *off) 1823 { 1824 u16 size = len + FC_FDMI_ATTR_ENTRY_HEADER_LEN; 1825 struct fc_fdmi_attr_entry *fdmi_attr = (struct fc_fdmi_attr_entry *) 1826 ((u8 *)attr_start + *off); 1827 1828 put_unaligned_be16(type, &fdmi_attr->type); 1829 put_unaligned_be16(size, &fdmi_attr->len); 1830 memcpy(fdmi_attr->value, data, len); 1831 *off += size; 1832 } 1833 1834 static void fdls_fdmi_register_hba(struct fnic_iport_s *iport) 1835 { 1836 uint8_t *frame; 1837 struct fc_std_fdmi_rhba *prhba; 1838 struct fc_fdmi_attr_entry *fdmi_attr; 1839 uint8_t fcid[3]; 1840 int err; 1841 struct fnic *fnic = iport->fnic; 1842 struct vnic_devcmd_fw_info *fw_info = NULL; 1843 uint16_t oxid; 1844 u32 attr_off_bytes, len; 1845 u8 data[64]; 1846 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET; 1847 1848 frame = fdls_alloc_frame(iport); 1849 if (frame == NULL) { 1850 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1851 "Failed to allocate frame to send FDMI RHBA"); 1852 return; 1853 } 1854 1855 prhba = (struct fc_std_fdmi_rhba *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 1856 *prhba = (struct fc_std_fdmi_rhba) { 1857 .fchdr = { 1858 .fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 1859 .fh_d_id = {0xFF, 0XFF, 0XFA}, 1860 .fh_type = FC_TYPE_CT, 1861 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 1862 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID) 1863 }, 1864 .fc_std_ct_hdr = { 1865 .ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT, 1866 .ct_fs_subtype = FC_FDMI_SUBTYPE, 1867 .ct_cmd = cpu_to_be16(FC_FDMI_RHBA) 1868 }, 1869 }; 1870 1871 hton24(fcid, iport->fcid); 1872 FNIC_STD_SET_S_ID(prhba->fchdr, fcid); 1873 1874 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RHBA, 1875 &iport->active_oxid_fdmi_rhba); 1876 1877 if (oxid == FNIC_UNASSIGNED_OXID) { 1878 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1879 "0x%x: Failed to allocate OXID to send FDMI RHBA", 1880 iport->fcid); 1881 mempool_free(frame, fnic->frame_pool); 1882 return; 1883 } 1884 FNIC_STD_SET_OX_ID(prhba->fchdr, oxid); 1885 1886 put_unaligned_be64(iport->wwpn, &prhba->rhba.hbaid.id); 1887 put_unaligned_be32(FNIC_FDMI_NUM_PORTS, &prhba->rhba.port.numport); 1888 put_unaligned_be64(iport->wwpn, &prhba->rhba.port.port[0].portname); 1889 put_unaligned_be32(FNIC_FDMI_NUM_HBA_ATTRS, 1890 &prhba->rhba.hba_attrs.numattrs); 1891 1892 fdmi_attr = prhba->rhba.hba_attrs.attr; 1893 attr_off_bytes = 0; 1894 1895 put_unaligned_be64(iport->wwnn, data); 1896 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_NODE_NAME, 1897 FNIC_FDMI_NN_LEN, data, &attr_off_bytes); 1898 1899 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1900 "NN set, off=%d", attr_off_bytes); 1901 1902 strscpy_pad(data, FNIC_FDMI_MANUFACTURER, FNIC_FDMI_MANU_LEN); 1903 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MANUFACTURER, 1904 FNIC_FDMI_MANU_LEN, data, &attr_off_bytes); 1905 1906 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1907 "MFG set <%s>, off=%d", data, attr_off_bytes); 1908 1909 err = vnic_dev_fw_info(fnic->vdev, &fw_info); 1910 if (!err) { 1911 strscpy_pad(data, fw_info->hw_serial_number, 1912 FNIC_FDMI_SERIAL_LEN); 1913 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SERIAL_NUMBER, 1914 FNIC_FDMI_SERIAL_LEN, data, &attr_off_bytes); 1915 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1916 "SERIAL set <%s>, off=%d", data, attr_off_bytes); 1917 1918 } 1919 1920 if (fnic->subsys_desc_len >= FNIC_FDMI_MODEL_LEN) 1921 fnic->subsys_desc_len = FNIC_FDMI_MODEL_LEN - 1; 1922 strscpy_pad(data, fnic->subsys_desc, FNIC_FDMI_MODEL_LEN); 1923 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL, FNIC_FDMI_MODEL_LEN, 1924 data, &attr_off_bytes); 1925 1926 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1927 "MODEL set <%s>, off=%d", data, attr_off_bytes); 1928 1929 strscpy_pad(data, FNIC_FDMI_MODEL_DESCRIPTION, FNIC_FDMI_MODEL_DES_LEN); 1930 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL_DES, 1931 FNIC_FDMI_MODEL_DES_LEN, data, &attr_off_bytes); 1932 1933 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1934 "MODEL_DESC set <%s>, off=%d", data, attr_off_bytes); 1935 1936 if (!err) { 1937 strscpy_pad(data, fw_info->hw_version, FNIC_FDMI_HW_VER_LEN); 1938 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HARDWARE_VERSION, 1939 FNIC_FDMI_HW_VER_LEN, data, &attr_off_bytes); 1940 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1941 "HW_VER set <%s>, off=%d", data, attr_off_bytes); 1942 1943 } 1944 1945 strscpy_pad(data, DRV_VERSION, FNIC_FDMI_DR_VER_LEN); 1946 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_DRIVER_VERSION, 1947 FNIC_FDMI_DR_VER_LEN, data, &attr_off_bytes); 1948 1949 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1950 "DRV_VER set <%s>, off=%d", data, attr_off_bytes); 1951 1952 strscpy_pad(data, "N/A", FNIC_FDMI_ROM_VER_LEN); 1953 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_ROM_VERSION, 1954 FNIC_FDMI_ROM_VER_LEN, data, &attr_off_bytes); 1955 1956 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1957 "ROM_VER set <%s>, off=%d", data, attr_off_bytes); 1958 1959 if (!err) { 1960 strscpy_pad(data, fw_info->fw_version, FNIC_FDMI_FW_VER_LEN); 1961 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FIRMWARE_VERSION, 1962 FNIC_FDMI_FW_VER_LEN, data, &attr_off_bytes); 1963 1964 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1965 "FW_VER set <%s>, off=%d", data, attr_off_bytes); 1966 } 1967 1968 len = sizeof(struct fc_std_fdmi_rhba) + attr_off_bytes; 1969 frame_size += len; 1970 1971 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 1972 "0x%x: FDLS send FDMI RHBA with oxid: 0x%x fs: %d", iport->fcid, 1973 oxid, frame_size); 1974 1975 fnic_send_fcoe_frame(iport, frame, frame_size); 1976 iport->fabric.fdmi_pending |= FDLS_FDMI_REG_HBA_PENDING; 1977 } 1978 1979 static void fdls_fdmi_register_pa(struct fnic_iport_s *iport) 1980 { 1981 uint8_t *frame; 1982 struct fc_std_fdmi_rpa *prpa; 1983 struct fc_fdmi_attr_entry *fdmi_attr; 1984 uint8_t fcid[3]; 1985 struct fnic *fnic = iport->fnic; 1986 u32 port_speed_bm; 1987 u32 port_speed = vnic_dev_port_speed(fnic->vdev); 1988 uint16_t oxid; 1989 u32 attr_off_bytes, len; 1990 u8 tmp_data[16], data[64]; 1991 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET; 1992 1993 frame = fdls_alloc_frame(iport); 1994 if (frame == NULL) { 1995 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 1996 "Failed to allocate frame to send FDMI RPA"); 1997 return; 1998 } 1999 2000 prpa = (struct fc_std_fdmi_rpa *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 2001 *prpa = (struct fc_std_fdmi_rpa) { 2002 .fchdr = { 2003 .fh_r_ctl = FC_RCTL_DD_UNSOL_CTL, 2004 .fh_d_id = {0xFF, 0xFF, 0xFA}, 2005 .fh_type = FC_TYPE_CT, 2006 .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}, 2007 .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID) 2008 }, 2009 .fc_std_ct_hdr = { 2010 .ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT, 2011 .ct_fs_subtype = FC_FDMI_SUBTYPE, 2012 .ct_cmd = cpu_to_be16(FC_FDMI_RPA) 2013 }, 2014 }; 2015 2016 hton24(fcid, iport->fcid); 2017 FNIC_STD_SET_S_ID(prpa->fchdr, fcid); 2018 2019 oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RPA, 2020 &iport->active_oxid_fdmi_rpa); 2021 2022 if (oxid == FNIC_UNASSIGNED_OXID) { 2023 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2024 "0x%x: Failed to allocate OXID to send FDMI RPA", 2025 iport->fcid); 2026 mempool_free(frame, fnic->frame_pool); 2027 return; 2028 } 2029 FNIC_STD_SET_OX_ID(prpa->fchdr, oxid); 2030 2031 put_unaligned_be64(iport->wwpn, &prpa->rpa.port.portname); 2032 put_unaligned_be32(FNIC_FDMI_NUM_PORT_ATTRS, 2033 &prpa->rpa.hba_attrs.numattrs); 2034 2035 /* MDS does not support GIGE speed. 2036 * Bit shift standard definitions from scsi_transport_fc.h to 2037 * match FC spec. 2038 */ 2039 switch (port_speed) { 2040 case DCEM_PORTSPEED_10G: 2041 case DCEM_PORTSPEED_20G: 2042 /* There is no bit for 20G */ 2043 port_speed_bm = FC_PORTSPEED_10GBIT << PORT_SPEED_BIT_14; 2044 break; 2045 case DCEM_PORTSPEED_25G: 2046 port_speed_bm = FC_PORTSPEED_25GBIT << PORT_SPEED_BIT_8; 2047 break; 2048 case DCEM_PORTSPEED_40G: 2049 case DCEM_PORTSPEED_4x10G: 2050 port_speed_bm = FC_PORTSPEED_40GBIT << PORT_SPEED_BIT_9; 2051 break; 2052 case DCEM_PORTSPEED_100G: 2053 port_speed_bm = FC_PORTSPEED_100GBIT << PORT_SPEED_BIT_8; 2054 break; 2055 default: 2056 port_speed_bm = FC_PORTSPEED_1GBIT << PORT_SPEED_BIT_15; 2057 break; 2058 } 2059 attr_off_bytes = 0; 2060 2061 fdmi_attr = prpa->rpa.hba_attrs.attr; 2062 2063 put_unaligned_be64(iport->wwnn, data); 2064 2065 memset(data, 0, FNIC_FDMI_FC4_LEN); 2066 data[2] = 1; 2067 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FC4_TYPES, 2068 FNIC_FDMI_FC4_LEN, data, &attr_off_bytes); 2069 2070 put_unaligned_be32(port_speed_bm, data); 2071 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SUPPORTED_SPEEDS, 2072 FNIC_FDMI_SUPP_SPEED_LEN, data, &attr_off_bytes); 2073 2074 put_unaligned_be32(port_speed_bm, data); 2075 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_CURRENT_SPEED, 2076 FNIC_FDMI_CUR_SPEED_LEN, data, &attr_off_bytes); 2077 2078 put_unaligned_be32(FNIC_FDMI_MFS, data); 2079 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MAX_FRAME_SIZE, 2080 FNIC_FDMI_MFS_LEN, data, &attr_off_bytes); 2081 2082 snprintf(tmp_data, FNIC_FDMI_OS_NAME_LEN - 1, "host%d", 2083 fnic->host->host_no); 2084 strscpy_pad(data, tmp_data, FNIC_FDMI_OS_NAME_LEN); 2085 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_OS_NAME, 2086 FNIC_FDMI_OS_NAME_LEN, data, &attr_off_bytes); 2087 2088 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2089 "OS name set <%s>, off=%d", data, attr_off_bytes); 2090 2091 sprintf(fc_host_system_hostname(fnic->host), "%s", utsname()->nodename); 2092 strscpy_pad(data, fc_host_system_hostname(fnic->host), 2093 FNIC_FDMI_HN_LEN); 2094 fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HOST_NAME, 2095 FNIC_FDMI_HN_LEN, data, &attr_off_bytes); 2096 2097 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2098 "Host name set <%s>, off=%d", data, attr_off_bytes); 2099 2100 len = sizeof(struct fc_std_fdmi_rpa) + attr_off_bytes; 2101 frame_size += len; 2102 2103 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2104 "0x%x: FDLS send FDMI RPA with oxid: 0x%x fs: %d", iport->fcid, 2105 oxid, frame_size); 2106 2107 fnic_send_fcoe_frame(iport, frame, frame_size); 2108 iport->fabric.fdmi_pending |= FDLS_FDMI_RPA_PENDING; 2109 } 2110 2111 void fdls_fabric_timer_callback(struct timer_list *t) 2112 { 2113 struct fnic_fdls_fabric_s *fabric = timer_container_of(fabric, t, 2114 retry_timer); 2115 struct fnic_iport_s *iport = 2116 container_of(fabric, struct fnic_iport_s, fabric); 2117 struct fnic *fnic = iport->fnic; 2118 unsigned long flags; 2119 2120 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2121 "tp: %d fab state: %d fab retry counter: %d max_flogi_retries: %d", 2122 iport->fabric.timer_pending, iport->fabric.state, 2123 iport->fabric.retry_counter, iport->max_flogi_retries); 2124 2125 spin_lock_irqsave(&fnic->fnic_lock, flags); 2126 2127 if (!iport->fabric.timer_pending) { 2128 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2129 return; 2130 } 2131 2132 if (iport->fabric.del_timer_inprogress) { 2133 iport->fabric.del_timer_inprogress = 0; 2134 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2135 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2136 "fabric_del_timer inprogress(%d). Skip timer cb", 2137 iport->fabric.del_timer_inprogress); 2138 return; 2139 } 2140 2141 iport->fabric.timer_pending = 0; 2142 2143 /* The fabric state indicates which frames have time out, and we retry */ 2144 switch (iport->fabric.state) { 2145 case FDLS_STATE_FABRIC_FLOGI: 2146 /* Flogi received a LS_RJT with busy we retry from here */ 2147 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2148 && (iport->fabric.retry_counter < iport->max_flogi_retries)) { 2149 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2150 fdls_send_fabric_flogi(iport); 2151 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) { 2152 /* Flogi has time out 2*ed_tov send abts */ 2153 fdls_send_fabric_abts(iport); 2154 } else { 2155 /* ABTS has timed out 2156 * Mark the OXID to be freed after 2 * r_a_tov and retry the req 2157 */ 2158 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2159 if (iport->fabric.retry_counter < iport->max_flogi_retries) { 2160 iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED; 2161 fdls_send_fabric_flogi(iport); 2162 } else 2163 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2164 "Exceeded max FLOGI retries"); 2165 } 2166 break; 2167 case FDLS_STATE_FABRIC_PLOGI: 2168 /* Plogi received a LS_RJT with busy we retry from here */ 2169 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2170 && (iport->fabric.retry_counter < iport->max_plogi_retries)) { 2171 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2172 fdls_send_fabric_plogi(iport); 2173 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) { 2174 /* Plogi has timed out 2*ed_tov send abts */ 2175 fdls_send_fabric_abts(iport); 2176 } else { 2177 /* ABTS has timed out 2178 * Mark the OXID to be freed after 2 * r_a_tov and retry the req 2179 */ 2180 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2181 if (iport->fabric.retry_counter < iport->max_plogi_retries) { 2182 iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED; 2183 fdls_send_fabric_plogi(iport); 2184 } else 2185 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2186 "Exceeded max PLOGI retries"); 2187 } 2188 break; 2189 case FDLS_STATE_RPN_ID: 2190 /* Rpn_id received a LS_RJT with busy we retry from here */ 2191 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2192 && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) { 2193 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2194 fdls_send_rpn_id(iport); 2195 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) 2196 /* RPN has timed out. Send abts */ 2197 fdls_send_fabric_abts(iport); 2198 else { 2199 /* ABTS has timed out */ 2200 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2201 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 2202 } 2203 break; 2204 case FDLS_STATE_SCR: 2205 /* scr received a LS_RJT with busy we retry from here */ 2206 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2207 && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) { 2208 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2209 fdls_send_scr(iport); 2210 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) 2211 /* scr has timed out. Send abts */ 2212 fdls_send_fabric_abts(iport); 2213 else { 2214 /* ABTS has timed out */ 2215 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2216 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2217 "ABTS timed out. Starting PLOGI: %p", iport); 2218 fnic_fdls_start_plogi(iport); 2219 } 2220 break; 2221 case FDLS_STATE_REGISTER_FC4_TYPES: 2222 /* scr received a LS_RJT with busy we retry from here */ 2223 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2224 && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) { 2225 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2226 fdls_send_register_fc4_types(iport); 2227 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) { 2228 /* RFT_ID timed out send abts */ 2229 fdls_send_fabric_abts(iport); 2230 } else { 2231 /* ABTS has timed out */ 2232 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2233 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2234 "ABTS timed out. Starting PLOGI: %p", iport); 2235 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 2236 } 2237 break; 2238 case FDLS_STATE_REGISTER_FC4_FEATURES: 2239 /* scr received a LS_RJT with busy we retry from here */ 2240 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2241 && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) { 2242 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2243 fdls_send_register_fc4_features(iport); 2244 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) 2245 /* SCR has timed out. Send abts */ 2246 fdls_send_fabric_abts(iport); 2247 else { 2248 /* ABTS has timed out */ 2249 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2250 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2251 "ABTS timed out. Starting PLOGI %p", iport); 2252 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 2253 } 2254 break; 2255 case FDLS_STATE_RSCN_GPN_FT: 2256 case FDLS_STATE_SEND_GPNFT: 2257 case FDLS_STATE_GPN_FT: 2258 /* GPN_FT received a LS_RJT with busy we retry from here */ 2259 if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME) 2260 && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) { 2261 iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME; 2262 fdls_send_gpn_ft(iport, iport->fabric.state); 2263 } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) { 2264 /* gpn_ft has timed out. Send abts */ 2265 fdls_send_fabric_abts(iport); 2266 } else { 2267 /* ABTS has timed out */ 2268 fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req); 2269 if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) { 2270 fdls_send_gpn_ft(iport, iport->fabric.state); 2271 } else { 2272 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2273 "ABTS timeout for fabric GPN_FT. Check name server: %p", 2274 iport); 2275 } 2276 } 2277 break; 2278 default: 2279 break; 2280 } 2281 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2282 } 2283 2284 void fdls_fdmi_retry_plogi(struct fnic_iport_s *iport) 2285 { 2286 struct fnic *fnic = iport->fnic; 2287 2288 iport->fabric.fdmi_pending = 0; 2289 /* If max retries not exhausted, start over from fdmi plogi */ 2290 if (iport->fabric.fdmi_retry < FDLS_FDMI_MAX_RETRY) { 2291 iport->fabric.fdmi_retry++; 2292 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2293 "Retry FDMI PLOGI. FDMI retry: %d", 2294 iport->fabric.fdmi_retry); 2295 fdls_send_fdmi_plogi(iport); 2296 } 2297 } 2298 2299 void fdls_fdmi_timer_callback(struct timer_list *t) 2300 { 2301 struct fnic_fdls_fabric_s *fabric = timer_container_of(fabric, t, 2302 fdmi_timer); 2303 struct fnic_iport_s *iport = 2304 container_of(fabric, struct fnic_iport_s, fabric); 2305 struct fnic *fnic = iport->fnic; 2306 unsigned long flags; 2307 2308 spin_lock_irqsave(&fnic->fnic_lock, flags); 2309 2310 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2311 "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending); 2312 2313 if (!iport->fabric.fdmi_pending) { 2314 /* timer expired after fdmi responses received. */ 2315 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2316 return; 2317 } 2318 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2319 "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending); 2320 2321 /* if not abort pending, send an abort */ 2322 if (!(iport->fabric.fdmi_pending & FDLS_FDMI_ABORT_PENDING)) { 2323 fdls_send_fdmi_abts(iport); 2324 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2325 return; 2326 } 2327 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2328 "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending); 2329 2330 /* ABTS pending for an active fdmi request that is pending. 2331 * That means FDMI ABTS timed out 2332 * Schedule to free the OXID after 2*r_a_tov and proceed 2333 */ 2334 if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) { 2335 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2336 "FDMI PLOGI ABTS timed out. Schedule oxid free: 0x%x\n", 2337 iport->active_oxid_fdmi_plogi); 2338 fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_plogi); 2339 } else { 2340 if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) { 2341 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2342 "FDMI RHBA ABTS timed out. Schedule oxid free: 0x%x\n", 2343 iport->active_oxid_fdmi_rhba); 2344 fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rhba); 2345 } 2346 if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING) { 2347 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2348 "FDMI RPA ABTS timed out. Schedule oxid free: 0x%x\n", 2349 iport->active_oxid_fdmi_rpa); 2350 fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rpa); 2351 } 2352 } 2353 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2354 "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending); 2355 2356 fdls_fdmi_retry_plogi(iport); 2357 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2358 "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending); 2359 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2360 } 2361 2362 static void fdls_send_delete_tport_msg(struct fnic_tport_s *tport) 2363 { 2364 struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport; 2365 struct fnic *fnic = iport->fnic; 2366 struct fnic_tport_event_s *tport_del_evt; 2367 2368 tport_del_evt = kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC); 2369 if (!tport_del_evt) { 2370 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2371 "Failed to allocate memory for tport event fcid: 0x%x", 2372 tport->fcid); 2373 return; 2374 } 2375 tport_del_evt->event = TGT_EV_TPORT_DELETE; 2376 tport_del_evt->arg1 = (void *) tport; 2377 list_add_tail(&tport_del_evt->links, &fnic->tport_event_list); 2378 queue_work(fnic_event_queue, &fnic->tport_work); 2379 } 2380 2381 static void fdls_tport_timer_callback(struct timer_list *t) 2382 { 2383 struct fnic_tport_s *tport = timer_container_of(tport, t, retry_timer); 2384 struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport; 2385 struct fnic *fnic = iport->fnic; 2386 uint16_t oxid; 2387 unsigned long flags; 2388 2389 spin_lock_irqsave(&fnic->fnic_lock, flags); 2390 if (!tport->timer_pending) { 2391 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2392 return; 2393 } 2394 2395 if (iport->state != FNIC_IPORT_STATE_READY) { 2396 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2397 return; 2398 } 2399 2400 if (tport->del_timer_inprogress) { 2401 tport->del_timer_inprogress = 0; 2402 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2403 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2404 "tport_del_timer inprogress. Skip timer cb tport fcid: 0x%x\n", 2405 tport->fcid); 2406 return; 2407 } 2408 2409 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2410 "tport fcid: 0x%x timer pending: %d state: %d retry counter: %d", 2411 tport->fcid, tport->timer_pending, tport->state, 2412 tport->retry_counter); 2413 2414 tport->timer_pending = 0; 2415 oxid = tport->active_oxid; 2416 2417 /* We retry plogi/prli/adisc frames depending on the tport state */ 2418 switch (tport->state) { 2419 case FDLS_TGT_STATE_PLOGI: 2420 /* PLOGI frame received a LS_RJT with busy, we retry from here */ 2421 if ((tport->flags & FNIC_FDLS_RETRY_FRAME) 2422 && (tport->retry_counter < iport->max_plogi_retries)) { 2423 tport->flags &= ~FNIC_FDLS_RETRY_FRAME; 2424 fdls_send_tgt_plogi(iport, tport); 2425 } else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2426 /* Plogi frame has timed out, send abts */ 2427 fdls_send_tport_abts(iport, tport); 2428 } else if (tport->retry_counter < iport->max_plogi_retries) { 2429 /* 2430 * ABTS has timed out 2431 */ 2432 fdls_schedule_oxid_free(iport, &tport->active_oxid); 2433 fdls_send_tgt_plogi(iport, tport); 2434 } else { 2435 /* exceeded plogi retry count */ 2436 fdls_schedule_oxid_free(iport, &tport->active_oxid); 2437 fdls_send_delete_tport_msg(tport); 2438 } 2439 break; 2440 case FDLS_TGT_STATE_PRLI: 2441 /* PRLI received a LS_RJT with busy , hence we retry from here */ 2442 if ((tport->flags & FNIC_FDLS_RETRY_FRAME) 2443 && (tport->retry_counter < FDLS_RETRY_COUNT)) { 2444 tport->flags &= ~FNIC_FDLS_RETRY_FRAME; 2445 fdls_send_tgt_prli(iport, tport); 2446 } else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2447 /* PRLI has time out, send abts */ 2448 fdls_send_tport_abts(iport, tport); 2449 } else { 2450 /* ABTS has timed out for prli, we go back to PLOGI */ 2451 fdls_schedule_oxid_free(iport, &tport->active_oxid); 2452 fdls_send_tgt_plogi(iport, tport); 2453 fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI); 2454 } 2455 break; 2456 case FDLS_TGT_STATE_ADISC: 2457 /* ADISC timed out send an ABTS */ 2458 if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2459 fdls_send_tport_abts(iport, tport); 2460 } else if ((tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED) 2461 && (tport->retry_counter < FDLS_RETRY_COUNT)) { 2462 /* 2463 * ABTS has timed out 2464 */ 2465 fdls_schedule_oxid_free(iport, &tport->active_oxid); 2466 fdls_send_tgt_adisc(iport, tport); 2467 } else { 2468 /* exceeded retry count */ 2469 fdls_schedule_oxid_free(iport, &tport->active_oxid); 2470 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2471 "ADISC not responding. Deleting target port: 0x%x", 2472 tport->fcid); 2473 fdls_send_delete_tport_msg(tport); 2474 } 2475 break; 2476 default: 2477 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2478 "oxid: 0x%x Unknown tport state: 0x%x", oxid, tport->state); 2479 break; 2480 } 2481 spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2482 } 2483 2484 static void fnic_fdls_start_flogi(struct fnic_iport_s *iport) 2485 { 2486 iport->fabric.retry_counter = 0; 2487 fdls_send_fabric_flogi(iport); 2488 fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_FLOGI); 2489 iport->fabric.flags = 0; 2490 } 2491 2492 static void fnic_fdls_start_plogi(struct fnic_iport_s *iport) 2493 { 2494 iport->fabric.retry_counter = 0; 2495 fdls_send_fabric_plogi(iport); 2496 fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_PLOGI); 2497 iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED; 2498 2499 if ((fnic_fdmi_support == 1) && (!(iport->flags & FNIC_FDMI_ACTIVE))) { 2500 /* we can do FDMI at the same time */ 2501 iport->fabric.fdmi_retry = 0; 2502 timer_setup(&iport->fabric.fdmi_timer, fdls_fdmi_timer_callback, 2503 0); 2504 fdls_send_fdmi_plogi(iport); 2505 iport->flags |= FNIC_FDMI_ACTIVE; 2506 } 2507 } 2508 static void 2509 fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport, 2510 struct fc_frame_header *fchdr) 2511 { 2512 uint32_t tgt_fcid; 2513 struct fnic_tport_s *tport; 2514 uint8_t *fcid; 2515 uint64_t frame_wwnn; 2516 uint64_t frame_wwpn; 2517 uint16_t oxid; 2518 struct fc_std_els_adisc *adisc_rsp = (struct fc_std_els_adisc *)fchdr; 2519 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr; 2520 struct fnic *fnic = iport->fnic; 2521 2522 fcid = FNIC_STD_GET_S_ID(fchdr); 2523 tgt_fcid = ntoh24(fcid); 2524 tport = fnic_find_tport_by_fcid(iport, tgt_fcid); 2525 2526 if (!tport) { 2527 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2528 "Tgt ADISC response tport not found: 0x%x", tgt_fcid); 2529 return; 2530 } 2531 if ((iport->state != FNIC_IPORT_STATE_READY) 2532 || (tport->state != FDLS_TGT_STATE_ADISC) 2533 || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2534 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2535 "Dropping this ADISC response"); 2536 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2537 "iport state: %d tport state: %d Is abort issued on PRLI? %d", 2538 iport->state, tport->state, 2539 (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)); 2540 return; 2541 } 2542 if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) { 2543 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2544 "Dropping frame from target: 0x%x", 2545 tgt_fcid); 2546 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2547 "Reason: Stale ADISC/Aborted ADISC/OOO frame delivery"); 2548 return; 2549 } 2550 2551 oxid = FNIC_STD_GET_OX_ID(fchdr); 2552 fdls_free_oxid(iport, oxid, &tport->active_oxid); 2553 2554 switch (adisc_rsp->els.adisc_cmd) { 2555 case ELS_LS_ACC: 2556 atomic64_inc(&iport->iport_stats.tport_adisc_ls_accepts); 2557 if (tport->timer_pending) { 2558 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2559 "tport 0x%p Canceling fabric disc timer\n", 2560 tport); 2561 fnic_del_tport_timer_sync(fnic, tport); 2562 } 2563 tport->timer_pending = 0; 2564 tport->retry_counter = 0; 2565 frame_wwnn = get_unaligned_be64(&adisc_rsp->els.adisc_wwnn); 2566 frame_wwpn = get_unaligned_be64(&adisc_rsp->els.adisc_wwpn); 2567 if ((frame_wwnn == tport->wwnn) && (frame_wwpn == tport->wwpn)) { 2568 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2569 "ADISC accepted from target: 0x%x. Target logged in", 2570 tgt_fcid); 2571 fdls_set_tport_state(tport, FDLS_TGT_STATE_READY); 2572 } else { 2573 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2574 "Error mismatch frame: ADISC"); 2575 } 2576 break; 2577 2578 case ELS_LS_RJT: 2579 atomic64_inc(&iport->iport_stats.tport_adisc_ls_rejects); 2580 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 2581 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 2582 && (tport->retry_counter < FDLS_RETRY_COUNT)) { 2583 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2584 "ADISC ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x", 2585 tgt_fcid); 2586 2587 /* Retry ADISC again from the timer routine. */ 2588 tport->flags |= FNIC_FDLS_RETRY_FRAME; 2589 } else { 2590 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2591 "ADISC returned ELS_LS_RJT from target: 0x%x", 2592 tgt_fcid); 2593 fdls_delete_tport(iport, tport); 2594 } 2595 break; 2596 } 2597 } 2598 static void 2599 fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport, 2600 struct fc_frame_header *fchdr) 2601 { 2602 uint32_t tgt_fcid; 2603 struct fnic_tport_s *tport; 2604 uint8_t *fcid; 2605 uint16_t oxid; 2606 struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr; 2607 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr; 2608 uint16_t max_payload_size; 2609 struct fnic *fnic = iport->fnic; 2610 2611 fcid = FNIC_STD_GET_S_ID(fchdr); 2612 tgt_fcid = ntoh24(fcid); 2613 2614 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2615 "FDLS processing target PLOGI response: tgt_fcid: 0x%x", 2616 tgt_fcid); 2617 2618 tport = fnic_find_tport_by_fcid(iport, tgt_fcid); 2619 if (!tport) { 2620 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2621 "tport not found: 0x%x", tgt_fcid); 2622 return; 2623 } 2624 if ((iport->state != FNIC_IPORT_STATE_READY) 2625 || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2626 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2627 "Dropping frame! iport state: %d tport state: %d", 2628 iport->state, tport->state); 2629 return; 2630 } 2631 2632 if (tport->state != FDLS_TGT_STATE_PLOGI) { 2633 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2634 "PLOGI rsp recvd in wrong state. Drop the frame and restart nexus"); 2635 fdls_target_restart_nexus(tport); 2636 return; 2637 } 2638 2639 if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) { 2640 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2641 "PLOGI response from target: 0x%x. Dropping frame", 2642 tgt_fcid); 2643 return; 2644 } 2645 2646 oxid = FNIC_STD_GET_OX_ID(fchdr); 2647 fdls_free_oxid(iport, oxid, &tport->active_oxid); 2648 2649 switch (plogi_rsp->els.fl_cmd) { 2650 case ELS_LS_ACC: 2651 atomic64_inc(&iport->iport_stats.tport_plogi_ls_accepts); 2652 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2653 "PLOGI accepted by target: 0x%x", tgt_fcid); 2654 break; 2655 2656 case ELS_LS_RJT: 2657 atomic64_inc(&iport->iport_stats.tport_plogi_ls_rejects); 2658 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 2659 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 2660 && (tport->retry_counter < iport->max_plogi_retries)) { 2661 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2662 "PLOGI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x", 2663 tgt_fcid); 2664 /* Retry plogi again from the timer routine. */ 2665 tport->flags |= FNIC_FDLS_RETRY_FRAME; 2666 return; 2667 } 2668 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2669 "PLOGI returned ELS_LS_RJT from target: 0x%x", 2670 tgt_fcid); 2671 fdls_delete_tport(iport, tport); 2672 return; 2673 2674 default: 2675 atomic64_inc(&iport->iport_stats.tport_plogi_misc_rejects); 2676 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2677 "PLOGI not accepted from target fcid: 0x%x", 2678 tgt_fcid); 2679 return; 2680 } 2681 2682 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2683 "Found the PLOGI target: 0x%x and state: %d", 2684 (unsigned int) tgt_fcid, tport->state); 2685 2686 if (tport->timer_pending) { 2687 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2688 "tport fcid 0x%x: Canceling disc timer\n", 2689 tport->fcid); 2690 fnic_del_tport_timer_sync(fnic, tport); 2691 } 2692 2693 tport->timer_pending = 0; 2694 tport->wwpn = get_unaligned_be64(&FNIC_LOGI_PORT_NAME(plogi_rsp->els)); 2695 tport->wwnn = get_unaligned_be64(&FNIC_LOGI_NODE_NAME(plogi_rsp->els)); 2696 2697 /* Learn the Service Params */ 2698 2699 /* Max frame size - choose the lowest */ 2700 max_payload_size = fnic_fc_plogi_rsp_rdf(iport, plogi_rsp); 2701 tport->max_payload_size = 2702 min(max_payload_size, iport->max_payload_size); 2703 2704 if (tport->max_payload_size < FNIC_MIN_DATA_FIELD_SIZE) { 2705 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2706 "MFS: tport max frame size below spec bounds: %d", 2707 tport->max_payload_size); 2708 tport->max_payload_size = FNIC_MIN_DATA_FIELD_SIZE; 2709 } 2710 2711 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2712 "MAX frame size: %u iport max_payload_size: %d tport mfs: %d", 2713 max_payload_size, iport->max_payload_size, 2714 tport->max_payload_size); 2715 2716 tport->max_concur_seqs = FNIC_FC_PLOGI_RSP_CONCUR_SEQ(plogi_rsp); 2717 2718 tport->retry_counter = 0; 2719 fdls_set_tport_state(tport, FDLS_TGT_STATE_PRLI); 2720 fdls_send_tgt_prli(iport, tport); 2721 } 2722 static void 2723 fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport, 2724 struct fc_frame_header *fchdr) 2725 { 2726 uint32_t tgt_fcid; 2727 struct fnic_tport_s *tport; 2728 uint8_t *fcid; 2729 uint16_t oxid; 2730 struct fc_std_els_prli *prli_rsp = (struct fc_std_els_prli *)fchdr; 2731 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr; 2732 struct fnic_tport_event_s *tport_add_evt; 2733 struct fnic *fnic = iport->fnic; 2734 bool mismatched_tgt = false; 2735 2736 fcid = FNIC_STD_GET_S_ID(fchdr); 2737 tgt_fcid = ntoh24(fcid); 2738 2739 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2740 "FDLS process tgt PRLI response: 0x%x", tgt_fcid); 2741 2742 tport = fnic_find_tport_by_fcid(iport, tgt_fcid); 2743 if (!tport) { 2744 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2745 "tport not found: 0x%x", tgt_fcid); 2746 /* Handle or just drop? */ 2747 return; 2748 } 2749 2750 if ((iport->state != FNIC_IPORT_STATE_READY) 2751 || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) { 2752 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2753 "Dropping frame! iport st: %d tport st: %d tport fcid: 0x%x", 2754 iport->state, tport->state, tport->fcid); 2755 return; 2756 } 2757 2758 if (tport->state != FDLS_TGT_STATE_PRLI) { 2759 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2760 "PRLI rsp recvd in wrong state. Drop frame. Restarting nexus"); 2761 fdls_target_restart_nexus(tport); 2762 return; 2763 } 2764 2765 if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) { 2766 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2767 "Dropping PRLI response from target: 0x%x ", 2768 tgt_fcid); 2769 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2770 "Reason: Stale PRLI response/Aborted PDISC/OOO frame delivery"); 2771 return; 2772 } 2773 2774 oxid = FNIC_STD_GET_OX_ID(fchdr); 2775 fdls_free_oxid(iport, oxid, &tport->active_oxid); 2776 2777 switch (prli_rsp->els_prli.prli_cmd) { 2778 case ELS_LS_ACC: 2779 atomic64_inc(&iport->iport_stats.tport_prli_ls_accepts); 2780 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2781 "PRLI accepted from target: 0x%x", tgt_fcid); 2782 2783 if (prli_rsp->sp.spp_type != FC_FC4_TYPE_SCSI) { 2784 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2785 "mismatched target zoned with FC SCSI initiator: 0x%x", 2786 tgt_fcid); 2787 mismatched_tgt = true; 2788 } 2789 if (mismatched_tgt) { 2790 fdls_tgt_logout(iport, tport); 2791 fdls_delete_tport(iport, tport); 2792 return; 2793 } 2794 break; 2795 case ELS_LS_RJT: 2796 atomic64_inc(&iport->iport_stats.tport_prli_ls_rejects); 2797 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 2798 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 2799 && (tport->retry_counter < FDLS_RETRY_COUNT)) { 2800 2801 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2802 "PRLI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x", 2803 tgt_fcid); 2804 2805 /*Retry Plogi again from the timer routine. */ 2806 tport->flags |= FNIC_FDLS_RETRY_FRAME; 2807 return; 2808 } 2809 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2810 "PRLI returned ELS_LS_RJT from target: 0x%x", 2811 tgt_fcid); 2812 2813 fdls_tgt_logout(iport, tport); 2814 fdls_delete_tport(iport, tport); 2815 return; 2816 default: 2817 atomic64_inc(&iport->iport_stats.tport_prli_misc_rejects); 2818 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2819 "PRLI not accepted from target: 0x%x", tgt_fcid); 2820 return; 2821 } 2822 2823 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2824 "Found the PRLI target: 0x%x and state: %d", 2825 (unsigned int) tgt_fcid, tport->state); 2826 2827 if (tport->timer_pending) { 2828 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2829 "tport fcid 0x%x: Canceling disc timer\n", 2830 tport->fcid); 2831 fnic_del_tport_timer_sync(fnic, tport); 2832 } 2833 tport->timer_pending = 0; 2834 2835 /* Learn Service Params */ 2836 tport->fcp_csp = be32_to_cpu(prli_rsp->sp.spp_params); 2837 tport->retry_counter = 0; 2838 2839 if (tport->fcp_csp & FCP_SPPF_RETRY) 2840 tport->tgt_flags |= FNIC_FC_RP_FLAGS_RETRY; 2841 2842 /* Check if the device plays Target Mode Function */ 2843 if (!(tport->fcp_csp & FCP_PRLI_FUNC_TARGET)) { 2844 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2845 "Remote port(0x%x): no target support. Deleting it\n", 2846 tgt_fcid); 2847 fdls_tgt_logout(iport, tport); 2848 fdls_delete_tport(iport, tport); 2849 return; 2850 } 2851 2852 fdls_set_tport_state(tport, FDLS_TGT_STATE_READY); 2853 2854 /* Inform the driver about new target added */ 2855 tport_add_evt = kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC); 2856 if (!tport_add_evt) { 2857 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2858 "tport event memory allocation failure: 0x%0x\n", 2859 tport->fcid); 2860 return; 2861 } 2862 tport_add_evt->event = TGT_EV_RPORT_ADD; 2863 tport_add_evt->arg1 = (void *) tport; 2864 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2865 "iport fcid: 0x%x add tport event fcid: 0x%x\n", 2866 tport->fcid, iport->fcid); 2867 list_add_tail(&tport_add_evt->links, &fnic->tport_event_list); 2868 queue_work(fnic_event_queue, &fnic->tport_work); 2869 } 2870 2871 2872 static void 2873 fdls_process_rff_id_rsp(struct fnic_iport_s *iport, 2874 struct fc_frame_header *fchdr) 2875 { 2876 struct fnic *fnic = iport->fnic; 2877 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 2878 struct fc_std_rff_id *rff_rsp = (struct fc_std_rff_id *) fchdr; 2879 uint16_t rsp; 2880 uint8_t reason_code; 2881 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 2882 2883 if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_FEATURES) { 2884 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2885 "RFF_ID resp recvd in state(%d). Dropping.", 2886 fdls_get_state(fdls)); 2887 return; 2888 } 2889 2890 if (iport->active_oxid_fabric_req != oxid) { 2891 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2892 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 2893 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 2894 return; 2895 } 2896 2897 rsp = FNIC_STD_GET_FC_CT_CMD((&rff_rsp->fc_std_ct_hdr)); 2898 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2899 "0x%x: FDLS process RFF ID response: 0x%04x", iport->fcid, 2900 (uint32_t) rsp); 2901 2902 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 2903 2904 switch (rsp) { 2905 case FC_FS_ACC: 2906 if (iport->fabric.timer_pending) { 2907 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2908 "Canceling fabric disc timer %p\n", iport); 2909 fnic_del_fabric_timer_sync(fnic); 2910 } 2911 iport->fabric.timer_pending = 0; 2912 fdls->retry_counter = 0; 2913 fdls_set_state((&iport->fabric), FDLS_STATE_SCR); 2914 fdls_send_scr(iport); 2915 break; 2916 case FC_FS_RJT: 2917 reason_code = rff_rsp->fc_std_ct_hdr.ct_reason; 2918 if (((reason_code == FC_FS_RJT_BSY) 2919 || (reason_code == FC_FS_RJT_UNABL)) 2920 && (fdls->retry_counter < FDLS_RETRY_COUNT)) { 2921 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2922 "RFF_ID ret ELS_LS_RJT BUSY. Retry from timer routine %p", 2923 iport); 2924 2925 /* Retry again from the timer routine */ 2926 fdls->flags |= FNIC_FDLS_RETRY_FRAME; 2927 } else { 2928 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2929 "RFF_ID returned ELS_LS_RJT. Halting discovery %p", 2930 iport); 2931 if (iport->fabric.timer_pending) { 2932 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2933 "Canceling fabric disc timer %p\n", iport); 2934 fnic_del_fabric_timer_sync(fnic); 2935 } 2936 fdls->timer_pending = 0; 2937 fdls->retry_counter = 0; 2938 } 2939 break; 2940 default: 2941 break; 2942 } 2943 } 2944 2945 static void 2946 fdls_process_rft_id_rsp(struct fnic_iport_s *iport, 2947 struct fc_frame_header *fchdr) 2948 { 2949 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 2950 struct fc_std_rft_id *rft_rsp = (struct fc_std_rft_id *) fchdr; 2951 uint16_t rsp; 2952 uint8_t reason_code; 2953 struct fnic *fnic = iport->fnic; 2954 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 2955 2956 if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_TYPES) { 2957 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2958 "RFT_ID resp recvd in state(%d). Dropping.", 2959 fdls_get_state(fdls)); 2960 return; 2961 } 2962 2963 if (iport->active_oxid_fabric_req != oxid) { 2964 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2965 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 2966 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 2967 return; 2968 } 2969 2970 2971 rsp = FNIC_STD_GET_FC_CT_CMD((&rft_rsp->fc_std_ct_hdr)); 2972 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2973 "0x%x: FDLS process RFT ID response: 0x%04x", iport->fcid, 2974 (uint32_t) rsp); 2975 2976 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 2977 2978 switch (rsp) { 2979 case FC_FS_ACC: 2980 if (iport->fabric.timer_pending) { 2981 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2982 "Canceling fabric disc timer %p\n", iport); 2983 fnic_del_fabric_timer_sync(fnic); 2984 } 2985 iport->fabric.timer_pending = 0; 2986 fdls->retry_counter = 0; 2987 fdls_send_register_fc4_features(iport); 2988 fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_FEATURES); 2989 break; 2990 case FC_FS_RJT: 2991 reason_code = rft_rsp->fc_std_ct_hdr.ct_reason; 2992 if (((reason_code == FC_FS_RJT_BSY) 2993 || (reason_code == FC_FS_RJT_UNABL)) 2994 && (fdls->retry_counter < FDLS_RETRY_COUNT)) { 2995 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 2996 "0x%x: RFT_ID ret ELS_LS_RJT BUSY. Retry from timer routine", 2997 iport->fcid); 2998 2999 /* Retry again from the timer routine */ 3000 fdls->flags |= FNIC_FDLS_RETRY_FRAME; 3001 } else { 3002 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3003 "0x%x: RFT_ID REJ. Halting discovery reason %d expl %d", 3004 iport->fcid, reason_code, 3005 rft_rsp->fc_std_ct_hdr.ct_explan); 3006 if (iport->fabric.timer_pending) { 3007 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3008 "Canceling fabric disc timer %p\n", iport); 3009 fnic_del_fabric_timer_sync(fnic); 3010 } 3011 fdls->timer_pending = 0; 3012 fdls->retry_counter = 0; 3013 } 3014 break; 3015 default: 3016 break; 3017 } 3018 } 3019 3020 static void 3021 fdls_process_rpn_id_rsp(struct fnic_iport_s *iport, 3022 struct fc_frame_header *fchdr) 3023 { 3024 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3025 struct fc_std_rpn_id *rpn_rsp = (struct fc_std_rpn_id *) fchdr; 3026 uint16_t rsp; 3027 uint8_t reason_code; 3028 struct fnic *fnic = iport->fnic; 3029 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3030 3031 if (fdls_get_state(fdls) != FDLS_STATE_RPN_ID) { 3032 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3033 "RPN_ID resp recvd in state(%d). Dropping.", 3034 fdls_get_state(fdls)); 3035 return; 3036 } 3037 if (iport->active_oxid_fabric_req != oxid) { 3038 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3039 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3040 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 3041 return; 3042 } 3043 3044 rsp = FNIC_STD_GET_FC_CT_CMD((&rpn_rsp->fc_std_ct_hdr)); 3045 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3046 "0x%x: FDLS process RPN ID response: 0x%04x", iport->fcid, 3047 (uint32_t) rsp); 3048 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3049 3050 switch (rsp) { 3051 case FC_FS_ACC: 3052 if (iport->fabric.timer_pending) { 3053 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3054 "Canceling fabric disc timer %p\n", iport); 3055 fnic_del_fabric_timer_sync(fnic); 3056 } 3057 iport->fabric.timer_pending = 0; 3058 fdls->retry_counter = 0; 3059 fdls_send_register_fc4_types(iport); 3060 fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_TYPES); 3061 break; 3062 case FC_FS_RJT: 3063 reason_code = rpn_rsp->fc_std_ct_hdr.ct_reason; 3064 if (((reason_code == FC_FS_RJT_BSY) 3065 || (reason_code == FC_FS_RJT_UNABL)) 3066 && (fdls->retry_counter < FDLS_RETRY_COUNT)) { 3067 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3068 "RPN_ID returned REJ BUSY. Retry from timer routine %p", 3069 iport); 3070 3071 /* Retry again from the timer routine */ 3072 fdls->flags |= FNIC_FDLS_RETRY_FRAME; 3073 } else { 3074 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3075 "RPN_ID ELS_LS_RJT. Halting discovery %p", iport); 3076 if (iport->fabric.timer_pending) { 3077 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3078 "Canceling fabric disc timer %p\n", iport); 3079 fnic_del_fabric_timer_sync(fnic); 3080 } 3081 fdls->timer_pending = 0; 3082 fdls->retry_counter = 0; 3083 } 3084 break; 3085 default: 3086 break; 3087 } 3088 } 3089 3090 static void 3091 fdls_process_scr_rsp(struct fnic_iport_s *iport, 3092 struct fc_frame_header *fchdr) 3093 { 3094 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3095 struct fc_std_scr *scr_rsp = (struct fc_std_scr *) fchdr; 3096 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr; 3097 struct fnic *fnic = iport->fnic; 3098 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3099 3100 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3101 "FDLS process SCR response: 0x%04x", 3102 (uint32_t) scr_rsp->scr.scr_cmd); 3103 3104 if (fdls_get_state(fdls) != FDLS_STATE_SCR) { 3105 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3106 "SCR resp recvd in state(%d). Dropping.", 3107 fdls_get_state(fdls)); 3108 return; 3109 } 3110 if (iport->active_oxid_fabric_req != oxid) { 3111 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3112 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3113 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 3114 } 3115 3116 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3117 3118 switch (scr_rsp->scr.scr_cmd) { 3119 case ELS_LS_ACC: 3120 atomic64_inc(&iport->iport_stats.fabric_scr_ls_accepts); 3121 if (iport->fabric.timer_pending) { 3122 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3123 "Canceling fabric disc timer %p\n", iport); 3124 fnic_del_fabric_timer_sync(fnic); 3125 } 3126 iport->fabric.timer_pending = 0; 3127 iport->fabric.retry_counter = 0; 3128 fdls_send_gpn_ft(iport, FDLS_STATE_GPN_FT); 3129 break; 3130 3131 case ELS_LS_RJT: 3132 atomic64_inc(&iport->iport_stats.fabric_scr_ls_rejects); 3133 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 3134 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 3135 && (fdls->retry_counter < FDLS_RETRY_COUNT)) { 3136 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3137 "SCR ELS_LS_RJT BUSY. Retry from timer routine %p", 3138 iport); 3139 /* Retry again from the timer routine */ 3140 fdls->flags |= FNIC_FDLS_RETRY_FRAME; 3141 } else { 3142 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3143 "SCR returned ELS_LS_RJT. Halting discovery %p", 3144 iport); 3145 if (iport->fabric.timer_pending) { 3146 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3147 "Canceling fabric disc timer %p\n", 3148 iport); 3149 fnic_del_fabric_timer_sync(fnic); 3150 } 3151 fdls->timer_pending = 0; 3152 fdls->retry_counter = 0; 3153 } 3154 break; 3155 3156 default: 3157 atomic64_inc(&iport->iport_stats.fabric_scr_misc_rejects); 3158 break; 3159 } 3160 } 3161 3162 static void 3163 fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport, 3164 struct fc_frame_header *fchdr, int len) 3165 { 3166 struct fc_gpn_ft_rsp_iu *gpn_ft_tgt; 3167 struct fnic_tport_s *tport, *next; 3168 uint32_t fcid; 3169 uint64_t wwpn; 3170 int rem_len = len; 3171 u32 old_link_down_cnt = iport->fnic->link_down_cnt; 3172 struct fnic *fnic = iport->fnic; 3173 3174 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3175 "0x%x: FDLS process GPN_FT tgt list", iport->fcid); 3176 3177 gpn_ft_tgt = 3178 (struct fc_gpn_ft_rsp_iu *)((uint8_t *) fchdr + 3179 sizeof(struct fc_frame_header) 3180 + sizeof(struct fc_ct_hdr)); 3181 len -= sizeof(struct fc_frame_header) + sizeof(struct fc_ct_hdr); 3182 3183 while (rem_len > 0) { 3184 3185 fcid = ntoh24(gpn_ft_tgt->fcid); 3186 wwpn = be64_to_cpu(gpn_ft_tgt->wwpn); 3187 3188 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3189 "tport: 0x%x: ctrl:0x%x", fcid, gpn_ft_tgt->ctrl); 3190 3191 if (fcid == iport->fcid) { 3192 if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST) 3193 break; 3194 gpn_ft_tgt++; 3195 rem_len -= sizeof(struct fc_gpn_ft_rsp_iu); 3196 continue; 3197 } 3198 3199 tport = fnic_find_tport_by_wwpn(iport, wwpn); 3200 if (!tport) { 3201 /* 3202 * New port registered with the switch or first time query 3203 */ 3204 tport = fdls_create_tport(iport, fcid, wwpn); 3205 if (!tport) 3206 return; 3207 } 3208 /* 3209 * check if this was an existing tport with same fcid 3210 * but whose wwpn has changed now ,then remove it and 3211 * create a new one 3212 */ 3213 if (tport->fcid != fcid) { 3214 fdls_delete_tport(iport, tport); 3215 tport = fdls_create_tport(iport, fcid, wwpn); 3216 if (!tport) 3217 return; 3218 } 3219 3220 /* 3221 * If this GPN_FT rsp is after RSCN then mark the tports which 3222 * matches with the new GPN_FT list, if some tport is not 3223 * found in GPN_FT we went to delete that tport later. 3224 */ 3225 if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT) 3226 tport->flags |= FNIC_FDLS_TPORT_IN_GPN_FT_LIST; 3227 3228 if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST) 3229 break; 3230 3231 gpn_ft_tgt++; 3232 rem_len -= sizeof(struct fc_gpn_ft_rsp_iu); 3233 } 3234 if (rem_len <= 0) { 3235 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3236 "GPN_FT response: malformed/corrupt frame rxlen: %d remlen: %d", 3237 len, rem_len); 3238 } 3239 3240 /*remove those ports which was not listed in GPN_FT */ 3241 if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT) { 3242 list_for_each_entry_safe(tport, next, &iport->tport_list, links) { 3243 3244 if (!(tport->flags & FNIC_FDLS_TPORT_IN_GPN_FT_LIST)) { 3245 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3246 "Remove port: 0x%x not found in GPN_FT list", 3247 tport->fcid); 3248 fdls_delete_tport(iport, tport); 3249 } else { 3250 tport->flags &= ~FNIC_FDLS_TPORT_IN_GPN_FT_LIST; 3251 } 3252 if ((old_link_down_cnt != iport->fnic->link_down_cnt) 3253 || (iport->state != FNIC_IPORT_STATE_READY)) { 3254 return; 3255 } 3256 } 3257 } 3258 } 3259 3260 static void 3261 fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport, 3262 struct fc_frame_header *fchdr, int len) 3263 { 3264 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3265 struct fc_std_gpn_ft *gpn_ft_rsp = (struct fc_std_gpn_ft *) fchdr; 3266 uint16_t rsp; 3267 uint8_t reason_code; 3268 int count = 0; 3269 struct fnic_tport_s *tport, *next; 3270 u32 old_link_down_cnt = iport->fnic->link_down_cnt; 3271 struct fnic *fnic = iport->fnic; 3272 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3273 3274 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3275 "FDLS process GPN_FT response: iport state: %d len: %d", 3276 iport->state, len); 3277 3278 /* 3279 * GPNFT response :- 3280 * FDLS_STATE_GPN_FT : GPNFT send after SCR state 3281 * during fabric discovery(FNIC_IPORT_STATE_FABRIC_DISC) 3282 * FDLS_STATE_RSCN_GPN_FT : GPNFT send in response to RSCN 3283 * FDLS_STATE_SEND_GPNFT : GPNFT send after deleting a Target, 3284 * e.g. after receiving Target LOGO 3285 * FDLS_STATE_TGT_DISCOVERY :Target discovery is currently in progress 3286 * from previous GPNFT response,a new GPNFT response has come. 3287 */ 3288 if (!(((iport->state == FNIC_IPORT_STATE_FABRIC_DISC) 3289 && (fdls_get_state(fdls) == FDLS_STATE_GPN_FT)) 3290 || ((iport->state == FNIC_IPORT_STATE_READY) 3291 && ((fdls_get_state(fdls) == FDLS_STATE_RSCN_GPN_FT) 3292 || (fdls_get_state(fdls) == FDLS_STATE_SEND_GPNFT) 3293 || (fdls_get_state(fdls) == FDLS_STATE_TGT_DISCOVERY))))) { 3294 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3295 "GPNFT resp recvd in fab state(%d) iport_state(%d). Dropping.", 3296 fdls_get_state(fdls), iport->state); 3297 return; 3298 } 3299 3300 if (iport->active_oxid_fabric_req != oxid) { 3301 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3302 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3303 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 3304 } 3305 3306 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3307 3308 iport->state = FNIC_IPORT_STATE_READY; 3309 rsp = FNIC_STD_GET_FC_CT_CMD((&gpn_ft_rsp->fc_std_ct_hdr)); 3310 3311 switch (rsp) { 3312 3313 case FC_FS_ACC: 3314 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3315 "0x%x: GPNFT_RSP accept", iport->fcid); 3316 if (iport->fabric.timer_pending) { 3317 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3318 "0x%x: Canceling fabric disc timer\n", 3319 iport->fcid); 3320 fnic_del_fabric_timer_sync(fnic); 3321 } 3322 iport->fabric.timer_pending = 0; 3323 iport->fabric.retry_counter = 0; 3324 fdls_process_gpn_ft_tgt_list(iport, fchdr, len); 3325 3326 /* 3327 * iport state can change only if link down event happened 3328 * We don't need to undo fdls_process_gpn_ft_tgt_list, 3329 * that will be taken care in next link up event 3330 */ 3331 if (iport->state != FNIC_IPORT_STATE_READY) { 3332 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3333 "Halting target discovery: fab st: %d iport st: %d ", 3334 fdls_get_state(fdls), iport->state); 3335 break; 3336 } 3337 fdls_tgt_discovery_start(iport); 3338 break; 3339 3340 case FC_FS_RJT: 3341 reason_code = gpn_ft_rsp->fc_std_ct_hdr.ct_reason; 3342 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3343 "0x%x: GPNFT_RSP Reject reason: %d", iport->fcid, reason_code); 3344 3345 if (((reason_code == FC_FS_RJT_BSY) 3346 || (reason_code == FC_FS_RJT_UNABL)) 3347 && (fdls->retry_counter < FDLS_RETRY_COUNT)) { 3348 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3349 "0x%x: GPNFT_RSP ret REJ/BSY. Retry from timer routine", 3350 iport->fcid); 3351 /* Retry again from the timer routine */ 3352 fdls->flags |= FNIC_FDLS_RETRY_FRAME; 3353 } else { 3354 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3355 "0x%x: GPNFT_RSP reject", iport->fcid); 3356 if (iport->fabric.timer_pending) { 3357 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3358 "0x%x: Canceling fabric disc timer\n", 3359 iport->fcid); 3360 fnic_del_fabric_timer_sync(fnic); 3361 } 3362 iport->fabric.timer_pending = 0; 3363 iport->fabric.retry_counter = 0; 3364 /* 3365 * If GPN_FT ls_rjt then we should delete 3366 * all existing tports 3367 */ 3368 count = 0; 3369 list_for_each_entry_safe(tport, next, &iport->tport_list, 3370 links) { 3371 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3372 "GPN_FT_REJECT: Remove port: 0x%x", 3373 tport->fcid); 3374 fdls_delete_tport(iport, tport); 3375 if ((old_link_down_cnt != iport->fnic->link_down_cnt) 3376 || (iport->state != FNIC_IPORT_STATE_READY)) { 3377 return; 3378 } 3379 count++; 3380 } 3381 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3382 "GPN_FT_REJECT: Removed (0x%x) ports", count); 3383 } 3384 break; 3385 3386 default: 3387 break; 3388 } 3389 } 3390 3391 /** 3392 * fdls_process_fabric_logo_rsp - Handle an flogo response from the fcf 3393 * @iport: Handle to fnic iport 3394 * @fchdr: Incoming frame 3395 */ 3396 static void 3397 fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport, 3398 struct fc_frame_header *fchdr) 3399 { 3400 struct fc_std_flogi *flogo_rsp = (struct fc_std_flogi *) fchdr; 3401 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3402 struct fnic *fnic = iport->fnic; 3403 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3404 3405 if (iport->active_oxid_fabric_req != oxid) { 3406 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3407 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3408 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 3409 } 3410 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3411 3412 switch (flogo_rsp->els.fl_cmd) { 3413 case ELS_LS_ACC: 3414 if (iport->fabric.state != FDLS_STATE_FABRIC_LOGO) { 3415 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3416 "Flogo response. Fabric not in LOGO state. Dropping! %p", 3417 iport); 3418 return; 3419 } 3420 3421 iport->fabric.state = FDLS_STATE_FLOGO_DONE; 3422 iport->state = FNIC_IPORT_STATE_LINK_WAIT; 3423 3424 if (iport->fabric.timer_pending) { 3425 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3426 "iport 0x%p Canceling fabric disc timer\n", 3427 iport); 3428 fnic_del_fabric_timer_sync(fnic); 3429 } 3430 iport->fabric.timer_pending = 0; 3431 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3432 "Flogo response from Fabric for did: 0x%x", 3433 ntoh24(fchdr->fh_d_id)); 3434 return; 3435 3436 case ELS_LS_RJT: 3437 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3438 "Flogo response from Fabric for did: 0x%x returned ELS_LS_RJT", 3439 ntoh24(fchdr->fh_d_id)); 3440 return; 3441 3442 default: 3443 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3444 "FLOGO response not accepted or rejected: 0x%x", 3445 flogo_rsp->els.fl_cmd); 3446 } 3447 } 3448 3449 static void 3450 fdls_process_flogi_rsp(struct fnic_iport_s *iport, 3451 struct fc_frame_header *fchdr, void *rx_frame) 3452 { 3453 struct fnic_fdls_fabric_s *fabric = &iport->fabric; 3454 struct fc_std_flogi *flogi_rsp = (struct fc_std_flogi *) fchdr; 3455 uint8_t *fcid; 3456 uint16_t rdf_size; 3457 uint8_t fcmac[6] = { 0x0E, 0XFC, 0x00, 0x00, 0x00, 0x00 }; 3458 struct fnic *fnic = iport->fnic; 3459 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3460 3461 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3462 "0x%x: FDLS processing FLOGI response", iport->fcid); 3463 3464 if (fdls_get_state(fabric) != FDLS_STATE_FABRIC_FLOGI) { 3465 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3466 "FLOGI response received in state (%d). Dropping frame", 3467 fdls_get_state(fabric)); 3468 return; 3469 } 3470 if (iport->active_oxid_fabric_req != oxid) { 3471 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3472 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3473 fdls_get_state(fabric), oxid, iport->active_oxid_fabric_req); 3474 return; 3475 } 3476 3477 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3478 3479 switch (flogi_rsp->els.fl_cmd) { 3480 case ELS_LS_ACC: 3481 atomic64_inc(&iport->iport_stats.fabric_flogi_ls_accepts); 3482 if (iport->fabric.timer_pending) { 3483 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3484 "iport fcid: 0x%x Canceling fabric disc timer\n", 3485 iport->fcid); 3486 fnic_del_fabric_timer_sync(fnic); 3487 } 3488 3489 iport->fabric.timer_pending = 0; 3490 iport->fabric.retry_counter = 0; 3491 fcid = FNIC_STD_GET_D_ID(fchdr); 3492 iport->fcid = ntoh24(fcid); 3493 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3494 "0x%x: FLOGI response accepted", iport->fcid); 3495 3496 /* Learn the Service Params */ 3497 rdf_size = be16_to_cpu(FNIC_LOGI_RDF_SIZE(flogi_rsp->els)); 3498 if ((rdf_size >= FNIC_MIN_DATA_FIELD_SIZE) 3499 && (rdf_size < FNIC_FC_MAX_PAYLOAD_LEN)) 3500 iport->max_payload_size = min(rdf_size, 3501 iport->max_payload_size); 3502 3503 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3504 "max_payload_size from fabric: %u set: %d", rdf_size, 3505 iport->max_payload_size); 3506 3507 iport->r_a_tov = be32_to_cpu(FNIC_LOGI_R_A_TOV(flogi_rsp->els)); 3508 iport->e_d_tov = be32_to_cpu(FNIC_LOGI_E_D_TOV(flogi_rsp->els)); 3509 3510 if (FNIC_LOGI_FEATURES(flogi_rsp->els) & FNIC_FC_EDTOV_NSEC) 3511 iport->e_d_tov = iport->e_d_tov / FNIC_NSEC_TO_MSEC; 3512 3513 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3514 "From fabric: R_A_TOV: %d E_D_TOV: %d", 3515 iport->r_a_tov, iport->e_d_tov); 3516 3517 fc_host_fabric_name(iport->fnic->host) = 3518 get_unaligned_be64(&FNIC_LOGI_NODE_NAME(flogi_rsp->els)); 3519 fc_host_port_id(iport->fnic->host) = iport->fcid; 3520 3521 fnic_fdls_learn_fcoe_macs(iport, rx_frame, fcid); 3522 3523 if (fnic_fdls_register_portid(iport, iport->fcid, rx_frame) != 0) { 3524 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3525 "0x%x: FLOGI registration failed", iport->fcid); 3526 break; 3527 } 3528 3529 memcpy(&fcmac[3], fcid, 3); 3530 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3531 "Adding vNIC device MAC addr: %02x:%02x:%02x:%02x:%02x:%02x", 3532 fcmac[0], fcmac[1], fcmac[2], fcmac[3], fcmac[4], 3533 fcmac[5]); 3534 vnic_dev_add_addr(iport->fnic->vdev, fcmac); 3535 3536 if (fdls_get_state(fabric) == FDLS_STATE_FABRIC_FLOGI) { 3537 fnic_fdls_start_plogi(iport); 3538 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3539 "FLOGI response received. Starting PLOGI"); 3540 } else { 3541 /* From FDLS_STATE_FABRIC_FLOGI state fabric can only go to 3542 * FDLS_STATE_LINKDOWN 3543 * state, hence we don't have to worry about undoing: 3544 * the fnic_fdls_register_portid and vnic_dev_add_addr 3545 */ 3546 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3547 "FLOGI response received in state (%d). Dropping frame", 3548 fdls_get_state(fabric)); 3549 } 3550 break; 3551 3552 case ELS_LS_RJT: 3553 atomic64_inc(&iport->iport_stats.fabric_flogi_ls_rejects); 3554 if (fabric->retry_counter < iport->max_flogi_retries) { 3555 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3556 "FLOGI returned ELS_LS_RJT BUSY. Retry from timer routine %p", 3557 iport); 3558 3559 /* Retry Flogi again from the timer routine. */ 3560 fabric->flags |= FNIC_FDLS_RETRY_FRAME; 3561 3562 } else { 3563 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3564 "FLOGI returned ELS_LS_RJT. Halting discovery %p", 3565 iport); 3566 if (iport->fabric.timer_pending) { 3567 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3568 "iport 0x%p Canceling fabric disc timer\n", 3569 iport); 3570 fnic_del_fabric_timer_sync(fnic); 3571 } 3572 fabric->timer_pending = 0; 3573 fabric->retry_counter = 0; 3574 } 3575 break; 3576 3577 default: 3578 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3579 "FLOGI response not accepted: 0x%x", 3580 flogi_rsp->els.fl_cmd); 3581 atomic64_inc(&iport->iport_stats.fabric_flogi_misc_rejects); 3582 break; 3583 } 3584 } 3585 3586 static void 3587 fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport, 3588 struct fc_frame_header *fchdr) 3589 { 3590 struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *) fchdr; 3591 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr; 3592 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3593 struct fnic *fnic = iport->fnic; 3594 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3595 3596 if (fdls_get_state((&iport->fabric)) != FDLS_STATE_FABRIC_PLOGI) { 3597 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3598 "Fabric PLOGI response received in state (%d). Dropping frame", 3599 fdls_get_state(&iport->fabric)); 3600 return; 3601 } 3602 if (iport->active_oxid_fabric_req != oxid) { 3603 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3604 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3605 fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req); 3606 return; 3607 } 3608 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3609 3610 switch (plogi_rsp->els.fl_cmd) { 3611 case ELS_LS_ACC: 3612 atomic64_inc(&iport->iport_stats.fabric_plogi_ls_accepts); 3613 if (iport->fabric.timer_pending) { 3614 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3615 "iport fcid: 0x%x fabric PLOGI response: Accepted\n", 3616 iport->fcid); 3617 fnic_del_fabric_timer_sync(fnic); 3618 } 3619 iport->fabric.timer_pending = 0; 3620 iport->fabric.retry_counter = 0; 3621 fdls_set_state(&iport->fabric, FDLS_STATE_RPN_ID); 3622 fdls_send_rpn_id(iport); 3623 break; 3624 case ELS_LS_RJT: 3625 atomic64_inc(&iport->iport_stats.fabric_plogi_ls_rejects); 3626 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 3627 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 3628 && (iport->fabric.retry_counter < iport->max_plogi_retries)) { 3629 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3630 "0x%x: Fabric PLOGI ELS_LS_RJT BUSY. Retry from timer routine", 3631 iport->fcid); 3632 } else { 3633 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3634 "0x%x: Fabric PLOGI ELS_LS_RJT. Halting discovery", 3635 iport->fcid); 3636 if (iport->fabric.timer_pending) { 3637 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3638 "iport fcid: 0x%x Canceling fabric disc timer\n", 3639 iport->fcid); 3640 fnic_del_fabric_timer_sync(fnic); 3641 } 3642 iport->fabric.timer_pending = 0; 3643 iport->fabric.retry_counter = 0; 3644 return; 3645 } 3646 break; 3647 default: 3648 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3649 "PLOGI response not accepted: 0x%x", 3650 plogi_rsp->els.fl_cmd); 3651 atomic64_inc(&iport->iport_stats.fabric_plogi_misc_rejects); 3652 break; 3653 } 3654 } 3655 3656 static void fdls_process_fdmi_plogi_rsp(struct fnic_iport_s *iport, 3657 struct fc_frame_header *fchdr) 3658 { 3659 struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr; 3660 struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr; 3661 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 3662 struct fnic *fnic = iport->fnic; 3663 u64 fdmi_tov; 3664 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3665 3666 if (iport->active_oxid_fdmi_plogi != oxid) { 3667 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3668 "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n", 3669 fdls_get_state(fdls), oxid, iport->active_oxid_fdmi_plogi); 3670 return; 3671 } 3672 3673 iport->fabric.fdmi_pending &= ~FDLS_FDMI_PLOGI_PENDING; 3674 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi); 3675 3676 if (ntoh24(fchdr->fh_s_id) == FC_FID_MGMT_SERV) { 3677 timer_delete_sync(&iport->fabric.fdmi_timer); 3678 iport->fabric.fdmi_pending = 0; 3679 switch (plogi_rsp->els.fl_cmd) { 3680 case ELS_LS_ACC: 3681 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3682 "FDLS process fdmi PLOGI response status: ELS_LS_ACC\n"); 3683 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3684 "Sending fdmi registration for port 0x%x\n", 3685 iport->fcid); 3686 3687 fdls_fdmi_register_hba(iport); 3688 fdls_fdmi_register_pa(iport); 3689 fdmi_tov = jiffies + msecs_to_jiffies(5000); 3690 mod_timer(&iport->fabric.fdmi_timer, 3691 round_jiffies(fdmi_tov)); 3692 break; 3693 case ELS_LS_RJT: 3694 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3695 "Fabric FDMI PLOGI returned ELS_LS_RJT reason: 0x%x", 3696 els_rjt->rej.er_reason); 3697 3698 if (((els_rjt->rej.er_reason == ELS_RJT_BUSY) 3699 || (els_rjt->rej.er_reason == ELS_RJT_UNAB)) 3700 && (iport->fabric.fdmi_retry < 7)) { 3701 iport->fabric.fdmi_retry++; 3702 fdls_send_fdmi_plogi(iport); 3703 } 3704 break; 3705 default: 3706 break; 3707 } 3708 } 3709 } 3710 static void fdls_process_fdmi_reg_ack(struct fnic_iport_s *iport, 3711 struct fc_frame_header *fchdr, 3712 int rsp_type) 3713 { 3714 struct fnic *fnic = iport->fnic; 3715 uint16_t oxid; 3716 3717 if (!iport->fabric.fdmi_pending) { 3718 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 3719 "Received FDMI ack while not waiting: 0x%x\n", 3720 FNIC_STD_GET_OX_ID(fchdr)); 3721 return; 3722 } 3723 3724 oxid = FNIC_STD_GET_OX_ID(fchdr); 3725 3726 if ((iport->active_oxid_fdmi_rhba != oxid) && 3727 (iport->active_oxid_fdmi_rpa != oxid)) { 3728 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3729 "Incorrect OXID in response. oxid recvd: 0x%x, active oxids(rhba,rpa): 0x%x, 0x%x\n", 3730 oxid, iport->active_oxid_fdmi_rhba, iport->active_oxid_fdmi_rpa); 3731 return; 3732 } 3733 if (FNIC_FRAME_TYPE(oxid) == FNIC_FRAME_TYPE_FDMI_RHBA) { 3734 iport->fabric.fdmi_pending &= ~FDLS_FDMI_REG_HBA_PENDING; 3735 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba); 3736 } else { 3737 iport->fabric.fdmi_pending &= ~FDLS_FDMI_RPA_PENDING; 3738 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa); 3739 } 3740 3741 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3742 "iport fcid: 0x%x: Received FDMI registration ack\n", 3743 iport->fcid); 3744 3745 if (!iport->fabric.fdmi_pending) { 3746 timer_delete_sync(&iport->fabric.fdmi_timer); 3747 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3748 "iport fcid: 0x%x: Canceling FDMI timer\n", 3749 iport->fcid); 3750 } 3751 } 3752 3753 static void fdls_process_fdmi_abts_rsp(struct fnic_iport_s *iport, 3754 struct fc_frame_header *fchdr) 3755 { 3756 uint32_t s_id; 3757 struct fnic *fnic = iport->fnic; 3758 uint16_t oxid; 3759 3760 s_id = ntoh24(FNIC_STD_GET_S_ID(fchdr)); 3761 3762 if (!(s_id != FC_FID_MGMT_SERV)) { 3763 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3764 "Received abts rsp with invalid SID: 0x%x. Dropping frame", 3765 s_id); 3766 return; 3767 } 3768 3769 oxid = FNIC_STD_GET_OX_ID(fchdr); 3770 3771 switch (FNIC_FRAME_TYPE(oxid)) { 3772 case FNIC_FRAME_TYPE_FDMI_PLOGI: 3773 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3774 "Received FDMI PLOGI ABTS rsp with oxid: 0x%x", oxid); 3775 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3776 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3777 iport->fcid, iport->fabric.fdmi_pending); 3778 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi); 3779 3780 iport->fabric.fdmi_pending &= ~FDLS_FDMI_PLOGI_PENDING; 3781 iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING; 3782 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3783 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3784 iport->fcid, iport->fabric.fdmi_pending); 3785 break; 3786 case FNIC_FRAME_TYPE_FDMI_RHBA: 3787 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3788 "Received FDMI RHBA ABTS rsp with oxid: 0x%x", oxid); 3789 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3790 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3791 iport->fcid, iport->fabric.fdmi_pending); 3792 3793 iport->fabric.fdmi_pending &= ~FDLS_FDMI_REG_HBA_PENDING; 3794 3795 /* If RPA is still pending, don't turn off ABORT PENDING. 3796 * We count on the timer to detect the ABTS timeout and take 3797 * corrective action. 3798 */ 3799 if (!(iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING)) 3800 iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING; 3801 3802 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba); 3803 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3804 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3805 iport->fcid, iport->fabric.fdmi_pending); 3806 break; 3807 case FNIC_FRAME_TYPE_FDMI_RPA: 3808 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3809 "Received FDMI RPA ABTS rsp with oxid: 0x%x", oxid); 3810 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3811 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3812 iport->fcid, iport->fabric.fdmi_pending); 3813 3814 iport->fabric.fdmi_pending &= ~FDLS_FDMI_RPA_PENDING; 3815 3816 /* If RHBA is still pending, don't turn off ABORT PENDING. 3817 * We count on the timer to detect the ABTS timeout and take 3818 * corrective action. 3819 */ 3820 if (!(iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING)) 3821 iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING; 3822 3823 fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa); 3824 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3825 "0x%x: iport->fabric.fdmi_pending: 0x%x", 3826 iport->fcid, iport->fabric.fdmi_pending); 3827 break; 3828 default: 3829 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3830 "Received abts rsp with invalid oxid: 0x%x. Dropping frame", 3831 oxid); 3832 break; 3833 } 3834 3835 /* 3836 * Only if ABORT PENDING is off, delete the timer, and if no other 3837 * operations are pending, retry FDMI. 3838 * Otherwise, let the timer pop and take the appropriate action. 3839 */ 3840 if (!(iport->fabric.fdmi_pending & FDLS_FDMI_ABORT_PENDING)) { 3841 timer_delete_sync(&iport->fabric.fdmi_timer); 3842 if (!iport->fabric.fdmi_pending) 3843 fdls_fdmi_retry_plogi(iport); 3844 } 3845 } 3846 3847 static void 3848 fdls_process_fabric_abts_rsp(struct fnic_iport_s *iport, 3849 struct fc_frame_header *fchdr) 3850 { 3851 uint32_t s_id; 3852 struct fc_std_abts_ba_acc *ba_acc = (struct fc_std_abts_ba_acc *)fchdr; 3853 struct fc_std_abts_ba_rjt *ba_rjt; 3854 uint32_t fabric_state = iport->fabric.state; 3855 struct fnic *fnic = iport->fnic; 3856 int frame_type; 3857 uint16_t oxid; 3858 3859 s_id = ntoh24(fchdr->fh_s_id); 3860 ba_rjt = (struct fc_std_abts_ba_rjt *) fchdr; 3861 3862 if (!((s_id == FC_FID_DIR_SERV) || (s_id == FC_FID_FLOGI) 3863 || (s_id == FC_FID_FCTRL))) { 3864 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3865 "Received abts rsp with invalid SID: 0x%x. Dropping frame", 3866 s_id); 3867 return; 3868 } 3869 3870 oxid = FNIC_STD_GET_OX_ID(fchdr); 3871 if (iport->active_oxid_fabric_req != oxid) { 3872 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3873 "Received abts rsp with invalid oxid: 0x%x. Dropping frame", 3874 oxid); 3875 return; 3876 } 3877 3878 if (iport->fabric.timer_pending) { 3879 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3880 "Canceling fabric disc timer %p\n", iport); 3881 fnic_del_fabric_timer_sync(fnic); 3882 } 3883 iport->fabric.timer_pending = 0; 3884 iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED; 3885 3886 if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) { 3887 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3888 "Received abts rsp BA_ACC for fabric_state: %d OX_ID: 0x%x", 3889 fabric_state, be16_to_cpu(ba_acc->acc.ba_ox_id)); 3890 } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) { 3891 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3892 "BA_RJT fs: %d OX_ID: 0x%x rc: 0x%x rce: 0x%x", 3893 fabric_state, FNIC_STD_GET_OX_ID(&ba_rjt->fchdr), 3894 ba_rjt->rjt.br_reason, ba_rjt->rjt.br_explan); 3895 } 3896 3897 frame_type = FNIC_FRAME_TYPE(oxid); 3898 fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req); 3899 3900 /* currently error handling/retry logic is same for ABTS BA_ACC & BA_RJT */ 3901 switch (frame_type) { 3902 case FNIC_FRAME_TYPE_FABRIC_FLOGI: 3903 if (iport->fabric.retry_counter < iport->max_flogi_retries) 3904 fdls_send_fabric_flogi(iport); 3905 else 3906 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3907 "Exceeded max FLOGI retries"); 3908 break; 3909 case FNIC_FRAME_TYPE_FABRIC_LOGO: 3910 if (iport->fabric.retry_counter < FABRIC_LOGO_MAX_RETRY) 3911 fdls_send_fabric_logo(iport); 3912 break; 3913 case FNIC_FRAME_TYPE_FABRIC_PLOGI: 3914 if (iport->fabric.retry_counter < iport->max_plogi_retries) 3915 fdls_send_fabric_plogi(iport); 3916 else 3917 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3918 "Exceeded max PLOGI retries"); 3919 break; 3920 case FNIC_FRAME_TYPE_FABRIC_RPN: 3921 if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) 3922 fdls_send_rpn_id(iport); 3923 else 3924 /* go back to fabric Plogi */ 3925 fnic_fdls_start_plogi(iport); 3926 break; 3927 case FNIC_FRAME_TYPE_FABRIC_SCR: 3928 if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) 3929 fdls_send_scr(iport); 3930 else { 3931 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3932 "SCR exhausted retries. Start fabric PLOGI %p", 3933 iport); 3934 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 3935 } 3936 break; 3937 case FNIC_FRAME_TYPE_FABRIC_RFT: 3938 if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) 3939 fdls_send_register_fc4_types(iport); 3940 else { 3941 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3942 "RFT exhausted retries. Start fabric PLOGI %p", 3943 iport); 3944 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 3945 } 3946 break; 3947 case FNIC_FRAME_TYPE_FABRIC_RFF: 3948 if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) 3949 fdls_send_register_fc4_features(iport); 3950 else { 3951 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3952 "RFF exhausted retries. Start fabric PLOGI %p", 3953 iport); 3954 fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */ 3955 } 3956 break; 3957 case FNIC_FRAME_TYPE_FABRIC_GPN_FT: 3958 if (iport->fabric.retry_counter <= FDLS_RETRY_COUNT) 3959 fdls_send_gpn_ft(iport, fabric_state); 3960 else 3961 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3962 "GPN FT exhausted retries. Start fabric PLOGI %p", 3963 iport); 3964 break; 3965 default: 3966 /* 3967 * We should not be here since we already validated rx oxid with 3968 * our active_oxid_fabric_req 3969 */ 3970 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3971 "Invalid OXID/active oxid 0x%x\n", oxid); 3972 WARN_ON(true); 3973 return; 3974 } 3975 } 3976 3977 static void 3978 fdls_process_abts_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr) 3979 { 3980 uint8_t *frame; 3981 struct fc_std_abts_ba_acc *pba_acc; 3982 uint32_t nport_id; 3983 uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr); 3984 struct fnic_tport_s *tport; 3985 struct fnic *fnic = iport->fnic; 3986 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 3987 sizeof(struct fc_std_abts_ba_acc); 3988 3989 nport_id = ntoh24(fchdr->fh_s_id); 3990 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 3991 "Received abort from SID 0x%8x", nport_id); 3992 3993 tport = fnic_find_tport_by_fcid(iport, nport_id); 3994 if (tport) { 3995 if (tport->active_oxid == oxid) { 3996 tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED; 3997 fdls_free_oxid(iport, oxid, &tport->active_oxid); 3998 } 3999 } 4000 4001 frame = fdls_alloc_frame(iport); 4002 if (frame == NULL) { 4003 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4004 "0x%x: Failed to allocate frame to send response for ABTS req", 4005 iport->fcid); 4006 return; 4007 } 4008 4009 pba_acc = (struct fc_std_abts_ba_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4010 *pba_acc = (struct fc_std_abts_ba_acc) { 4011 .fchdr = {.fh_r_ctl = FC_RCTL_BA_ACC, 4012 .fh_f_ctl = {FNIC_FCP_RSP_FCTL, 0, 0}}, 4013 .acc = {.ba_low_seq_cnt = 0, .ba_high_seq_cnt = cpu_to_be16(0xFFFF)} 4014 }; 4015 4016 FNIC_STD_SET_S_ID(pba_acc->fchdr, fchdr->fh_d_id); 4017 FNIC_STD_SET_D_ID(pba_acc->fchdr, fchdr->fh_s_id); 4018 FNIC_STD_SET_OX_ID(pba_acc->fchdr, FNIC_STD_GET_OX_ID(fchdr)); 4019 FNIC_STD_SET_RX_ID(pba_acc->fchdr, FNIC_STD_GET_RX_ID(fchdr)); 4020 4021 pba_acc->acc.ba_rx_id = cpu_to_be16(FNIC_STD_GET_RX_ID(fchdr)); 4022 pba_acc->acc.ba_ox_id = cpu_to_be16(FNIC_STD_GET_OX_ID(fchdr)); 4023 4024 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4025 "0x%x: FDLS send BA ACC with oxid: 0x%x", 4026 iport->fcid, oxid); 4027 4028 fnic_send_fcoe_frame(iport, frame, frame_size); 4029 } 4030 4031 static void 4032 fdls_process_unsupported_els_req(struct fnic_iport_s *iport, 4033 struct fc_frame_header *fchdr) 4034 { 4035 uint8_t *frame; 4036 struct fc_std_els_rjt_rsp *pls_rsp; 4037 uint16_t oxid; 4038 uint32_t d_id = ntoh24(fchdr->fh_d_id); 4039 struct fnic *fnic = iport->fnic; 4040 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 4041 sizeof(struct fc_std_els_rjt_rsp); 4042 4043 if (iport->fcid != d_id) { 4044 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4045 "Dropping unsupported ELS with illegal frame bits 0x%x\n", 4046 d_id); 4047 atomic64_inc(&iport->iport_stats.unsupported_frames_dropped); 4048 return; 4049 } 4050 4051 if ((iport->state != FNIC_IPORT_STATE_READY) 4052 && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) { 4053 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4054 "Dropping unsupported ELS request in iport state: %d", 4055 iport->state); 4056 atomic64_inc(&iport->iport_stats.unsupported_frames_dropped); 4057 return; 4058 } 4059 4060 frame = fdls_alloc_frame(iport); 4061 if (frame == NULL) { 4062 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4063 "Failed to allocate frame to send response to unsupported ELS request"); 4064 return; 4065 } 4066 4067 pls_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4068 fdls_init_els_rjt_frame(frame, iport); 4069 4070 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4071 "0x%x: Process unsupported ELS request from SID: 0x%x", 4072 iport->fcid, ntoh24(fchdr->fh_s_id)); 4073 4074 /* We don't support this ELS request, send a reject */ 4075 pls_rsp->rej.er_reason = 0x0B; 4076 pls_rsp->rej.er_explan = 0x0; 4077 pls_rsp->rej.er_vendor = 0x0; 4078 4079 FNIC_STD_SET_S_ID(pls_rsp->fchdr, fchdr->fh_d_id); 4080 FNIC_STD_SET_D_ID(pls_rsp->fchdr, fchdr->fh_s_id); 4081 oxid = FNIC_STD_GET_OX_ID(fchdr); 4082 FNIC_STD_SET_OX_ID(pls_rsp->fchdr, oxid); 4083 4084 fnic_send_fcoe_frame(iport, frame, frame_size); 4085 } 4086 4087 static void 4088 fdls_process_rls_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr) 4089 { 4090 uint8_t *frame; 4091 struct fc_std_rls_acc *prls_acc_rsp; 4092 uint16_t oxid; 4093 struct fnic *fnic = iport->fnic; 4094 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 4095 sizeof(struct fc_std_rls_acc); 4096 4097 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4098 "Process RLS request %d", iport->fnic->fnic_num); 4099 4100 if ((iport->state != FNIC_IPORT_STATE_READY) 4101 && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) { 4102 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4103 "Received RLS req in iport state: %d. Dropping the frame.", 4104 iport->state); 4105 return; 4106 } 4107 4108 frame = fdls_alloc_frame(iport); 4109 if (frame == NULL) { 4110 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4111 "Failed to allocate frame to send RLS accept"); 4112 return; 4113 } 4114 prls_acc_rsp = (struct fc_std_rls_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4115 4116 FNIC_STD_SET_S_ID(prls_acc_rsp->fchdr, fchdr->fh_d_id); 4117 FNIC_STD_SET_D_ID(prls_acc_rsp->fchdr, fchdr->fh_s_id); 4118 4119 oxid = FNIC_STD_GET_OX_ID(fchdr); 4120 FNIC_STD_SET_OX_ID(prls_acc_rsp->fchdr, oxid); 4121 FNIC_STD_SET_RX_ID(prls_acc_rsp->fchdr, FNIC_UNASSIGNED_RXID); 4122 4123 FNIC_STD_SET_F_CTL(prls_acc_rsp->fchdr, FNIC_ELS_REP_FCTL << 16); 4124 FNIC_STD_SET_R_CTL(prls_acc_rsp->fchdr, FC_RCTL_ELS_REP); 4125 FNIC_STD_SET_TYPE(prls_acc_rsp->fchdr, FC_TYPE_ELS); 4126 4127 prls_acc_rsp->els.rls_cmd = ELS_LS_ACC; 4128 prls_acc_rsp->els.rls_lesb.lesb_link_fail = 4129 cpu_to_be32(iport->fnic->link_down_cnt); 4130 4131 fnic_send_fcoe_frame(iport, frame, frame_size); 4132 } 4133 4134 static void 4135 fdls_process_els_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr, 4136 uint32_t len) 4137 { 4138 uint8_t *frame; 4139 struct fc_std_els_acc_rsp *pels_acc; 4140 uint16_t oxid; 4141 uint8_t *fc_payload; 4142 uint8_t type; 4143 struct fnic *fnic = iport->fnic; 4144 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET; 4145 4146 fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header); 4147 type = *fc_payload; 4148 4149 if ((iport->state != FNIC_IPORT_STATE_READY) 4150 && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) { 4151 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4152 "Dropping ELS frame type: 0x%x in iport state: %d", 4153 type, iport->state); 4154 return; 4155 } 4156 switch (type) { 4157 case ELS_ECHO: 4158 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4159 "sending LS_ACC for ECHO request %d\n", 4160 iport->fnic->fnic_num); 4161 break; 4162 4163 case ELS_RRQ: 4164 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4165 "sending LS_ACC for RRQ request %d\n", 4166 iport->fnic->fnic_num); 4167 break; 4168 4169 default: 4170 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4171 "sending LS_ACC for 0x%x ELS frame\n", type); 4172 break; 4173 } 4174 4175 frame = fdls_alloc_frame(iport); 4176 if (frame == NULL) { 4177 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4178 "Failed to allocate frame to send ELS response for 0x%x", 4179 type); 4180 return; 4181 } 4182 4183 if (type == ELS_ECHO) { 4184 /* Brocade sends a longer payload, copy all frame back */ 4185 memcpy(frame, fchdr, len); 4186 } 4187 4188 pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4189 fdls_init_els_acc_frame(frame, iport); 4190 4191 FNIC_STD_SET_D_ID(pels_acc->fchdr, fchdr->fh_s_id); 4192 4193 oxid = FNIC_STD_GET_OX_ID(fchdr); 4194 FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid); 4195 4196 if (type == ELS_ECHO) 4197 frame_size += len; 4198 else 4199 frame_size += sizeof(struct fc_std_els_acc_rsp); 4200 4201 fnic_send_fcoe_frame(iport, frame, frame_size); 4202 } 4203 4204 static void 4205 fdls_process_tgt_abts_rsp(struct fnic_iport_s *iport, 4206 struct fc_frame_header *fchdr) 4207 { 4208 uint32_t s_id; 4209 struct fnic_tport_s *tport; 4210 uint32_t tport_state; 4211 struct fc_std_abts_ba_acc *ba_acc; 4212 struct fc_std_abts_ba_rjt *ba_rjt; 4213 uint16_t oxid; 4214 struct fnic *fnic = iport->fnic; 4215 int frame_type; 4216 4217 s_id = ntoh24(fchdr->fh_s_id); 4218 ba_acc = (struct fc_std_abts_ba_acc *)fchdr; 4219 ba_rjt = (struct fc_std_abts_ba_rjt *)fchdr; 4220 4221 tport = fnic_find_tport_by_fcid(iport, s_id); 4222 if (!tport) { 4223 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4224 "Received tgt abts rsp with invalid SID: 0x%x", s_id); 4225 return; 4226 } 4227 if (tport->timer_pending) { 4228 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4229 "tport 0x%p Canceling fabric disc timer\n", tport); 4230 fnic_del_tport_timer_sync(fnic, tport); 4231 } 4232 if (iport->state != FNIC_IPORT_STATE_READY) { 4233 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4234 "Received tgt abts rsp in iport state(%d). Dropping.", 4235 iport->state); 4236 return; 4237 } 4238 tport->timer_pending = 0; 4239 tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED; 4240 tport_state = tport->state; 4241 oxid = FNIC_STD_GET_OX_ID(fchdr); 4242 4243 /*This abort rsp is for ADISC */ 4244 frame_type = FNIC_FRAME_TYPE(oxid); 4245 switch (frame_type) { 4246 case FNIC_FRAME_TYPE_TGT_ADISC: 4247 if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) { 4248 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4249 "OX_ID: 0x%x tgt_fcid: 0x%x rcvd tgt adisc abts resp BA_ACC", 4250 be16_to_cpu(ba_acc->acc.ba_ox_id), 4251 tport->fcid); 4252 } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) { 4253 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4254 "ADISC BA_RJT rcvd tport_fcid: 0x%x tport_state: %d ", 4255 tport->fcid, tport_state); 4256 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4257 "reason code: 0x%x reason code explanation:0x%x ", 4258 ba_rjt->rjt.br_reason, 4259 ba_rjt->rjt.br_explan); 4260 } 4261 if ((tport->retry_counter < FDLS_RETRY_COUNT) 4262 && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) { 4263 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4264 fdls_send_tgt_adisc(iport, tport); 4265 return; 4266 } 4267 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4268 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4269 "ADISC not responding. Deleting target port: 0x%x", 4270 tport->fcid); 4271 fdls_delete_tport(iport, tport); 4272 /* Restart discovery of targets */ 4273 if ((iport->state == FNIC_IPORT_STATE_READY) 4274 && (iport->fabric.state != FDLS_STATE_SEND_GPNFT) 4275 && (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) { 4276 fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT); 4277 } 4278 break; 4279 case FNIC_FRAME_TYPE_TGT_PLOGI: 4280 if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) { 4281 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4282 "Received tgt PLOGI abts response BA_ACC tgt_fcid: 0x%x", 4283 tport->fcid); 4284 } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) { 4285 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4286 "PLOGI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x", 4287 tport->fcid, FNIC_STD_GET_OX_ID(fchdr)); 4288 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4289 "reason code: 0x%x reason code explanation: 0x%x", 4290 ba_rjt->rjt.br_reason, 4291 ba_rjt->rjt.br_explan); 4292 } 4293 if ((tport->retry_counter < iport->max_plogi_retries) 4294 && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) { 4295 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4296 fdls_send_tgt_plogi(iport, tport); 4297 return; 4298 } 4299 4300 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4301 fdls_delete_tport(iport, tport); 4302 /* Restart discovery of targets */ 4303 if ((iport->state == FNIC_IPORT_STATE_READY) 4304 && (iport->fabric.state != FDLS_STATE_SEND_GPNFT) 4305 && (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) { 4306 fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT); 4307 } 4308 break; 4309 case FNIC_FRAME_TYPE_TGT_PRLI: 4310 if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) { 4311 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4312 "0x%x: Received tgt PRLI abts response BA_ACC", 4313 tport->fcid); 4314 } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) { 4315 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4316 "PRLI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x ", 4317 tport->fcid, FNIC_STD_GET_OX_ID(fchdr)); 4318 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4319 "reason code: 0x%x reason code explanation: 0x%x", 4320 ba_rjt->rjt.br_reason, 4321 ba_rjt->rjt.br_explan); 4322 } 4323 if ((tport->retry_counter < FDLS_RETRY_COUNT) 4324 && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) { 4325 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4326 fdls_send_tgt_prli(iport, tport); 4327 return; 4328 } 4329 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4330 fdls_send_tgt_plogi(iport, tport); /* go back to plogi */ 4331 fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI); 4332 break; 4333 default: 4334 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4335 "Received ABTS response for unknown frame %p", iport); 4336 break; 4337 } 4338 4339 } 4340 4341 static void 4342 fdls_process_plogi_req(struct fnic_iport_s *iport, 4343 struct fc_frame_header *fchdr) 4344 { 4345 uint8_t *frame; 4346 struct fc_std_els_rjt_rsp *pplogi_rsp; 4347 uint16_t oxid; 4348 uint32_t d_id = ntoh24(fchdr->fh_d_id); 4349 struct fnic *fnic = iport->fnic; 4350 uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 4351 sizeof(struct fc_std_els_rjt_rsp); 4352 4353 if (iport->fcid != d_id) { 4354 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4355 "Received PLOGI with illegal frame bits. Dropping frame from 0x%x", 4356 d_id); 4357 return; 4358 } 4359 4360 if (iport->state != FNIC_IPORT_STATE_READY) { 4361 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4362 "Received PLOGI request in iport state: %d Dropping frame", 4363 iport->state); 4364 return; 4365 } 4366 4367 frame = fdls_alloc_frame(iport); 4368 if (frame == NULL) { 4369 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4370 "Failed to allocate frame to send response to PLOGI request"); 4371 return; 4372 } 4373 4374 pplogi_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4375 fdls_init_els_rjt_frame(frame, iport); 4376 4377 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4378 "0x%x: Process PLOGI request from SID: 0x%x", 4379 iport->fcid, ntoh24(fchdr->fh_s_id)); 4380 4381 /* We don't support PLOGI request, send a reject */ 4382 pplogi_rsp->rej.er_reason = 0x0B; 4383 pplogi_rsp->rej.er_explan = 0x0; 4384 pplogi_rsp->rej.er_vendor = 0x0; 4385 4386 FNIC_STD_SET_S_ID(pplogi_rsp->fchdr, fchdr->fh_d_id); 4387 FNIC_STD_SET_D_ID(pplogi_rsp->fchdr, fchdr->fh_s_id); 4388 oxid = FNIC_STD_GET_OX_ID(fchdr); 4389 FNIC_STD_SET_OX_ID(pplogi_rsp->fchdr, oxid); 4390 4391 fnic_send_fcoe_frame(iport, frame, frame_size); 4392 } 4393 4394 static void 4395 fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr) 4396 { 4397 struct fc_std_logo *logo = (struct fc_std_logo *)fchdr; 4398 uint32_t nport_id; 4399 uint64_t nport_name; 4400 struct fnic_tport_s *tport; 4401 struct fnic *fnic = iport->fnic; 4402 uint16_t oxid; 4403 4404 nport_id = ntoh24(logo->els.fl_n_port_id); 4405 nport_name = be64_to_cpu(logo->els.fl_n_port_wwn); 4406 4407 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4408 "Process LOGO request from fcid: 0x%x", nport_id); 4409 4410 if (iport->state != FNIC_IPORT_STATE_READY) { 4411 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4412 "Dropping LOGO req from 0x%x in iport state: %d", 4413 nport_id, iport->state); 4414 return; 4415 } 4416 4417 tport = fnic_find_tport_by_fcid(iport, nport_id); 4418 4419 if (!tport) { 4420 /* We are not logged in with the nport, log and drop... */ 4421 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4422 "Received LOGO from an nport not logged in: 0x%x(0x%llx)", 4423 nport_id, nport_name); 4424 return; 4425 } 4426 if (tport->fcid != nport_id) { 4427 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4428 "Received LOGO with invalid target port fcid: 0x%x(0x%llx)", 4429 nport_id, nport_name); 4430 return; 4431 } 4432 if (tport->timer_pending) { 4433 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4434 "tport fcid 0x%x: Canceling disc timer\n", 4435 tport->fcid); 4436 fnic_del_tport_timer_sync(fnic, tport); 4437 tport->timer_pending = 0; 4438 } 4439 4440 /* got a logo in response to adisc to a target which has logged out */ 4441 if (tport->state == FDLS_TGT_STATE_ADISC) { 4442 tport->retry_counter = 0; 4443 oxid = tport->active_oxid; 4444 fdls_free_oxid(iport, oxid, &tport->active_oxid); 4445 fdls_delete_tport(iport, tport); 4446 fdls_send_logo_resp(iport, &logo->fchdr); 4447 if ((iport->state == FNIC_IPORT_STATE_READY) 4448 && (fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT) 4449 && (fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) { 4450 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4451 "Sending GPNFT in response to LOGO from Target:0x%x", 4452 nport_id); 4453 fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT); 4454 return; 4455 } 4456 } else { 4457 fdls_delete_tport(iport, tport); 4458 } 4459 if (iport->state == FNIC_IPORT_STATE_READY) { 4460 fdls_send_logo_resp(iport, &logo->fchdr); 4461 if ((fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT) && 4462 (fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) { 4463 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4464 "Sending GPNFT in response to LOGO from Target:0x%x", 4465 nport_id); 4466 fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT); 4467 } 4468 } 4469 } 4470 4471 static void 4472 fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr) 4473 { 4474 struct fc_std_rscn *rscn; 4475 struct fc_els_rscn_page *rscn_port = NULL; 4476 int num_ports; 4477 struct fnic_tport_s *tport, *next; 4478 uint32_t nport_id; 4479 uint8_t fcid[3]; 4480 int newports = 0; 4481 struct fnic_fdls_fabric_s *fdls = &iport->fabric; 4482 struct fnic *fnic = iport->fnic; 4483 int rscn_type = NOT_PC_RSCN; 4484 uint32_t sid = ntoh24(fchdr->fh_s_id); 4485 unsigned long reset_fnic_list_lock_flags = 0; 4486 uint16_t rscn_payload_len; 4487 4488 atomic64_inc(&iport->iport_stats.num_rscns); 4489 4490 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4491 "FDLS process RSCN %p", iport); 4492 4493 if (iport->state != FNIC_IPORT_STATE_READY) { 4494 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4495 "FDLS RSCN received in state(%d). Dropping", 4496 fdls_get_state(fdls)); 4497 return; 4498 } 4499 4500 rscn = (struct fc_std_rscn *)fchdr; 4501 rscn_payload_len = be16_to_cpu(rscn->els.rscn_plen); 4502 4503 /* frame validation */ 4504 if ((rscn_payload_len % 4 != 0) || (rscn_payload_len < 8) 4505 || (rscn_payload_len > 1024) 4506 || (rscn->els.rscn_page_len != 4)) { 4507 num_ports = 0; 4508 if ((rscn_payload_len == 0xFFFF) 4509 && (sid == FC_FID_FCTRL)) { 4510 rscn_type = PC_RSCN; 4511 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4512 "pcrscn: PCRSCN received. sid: 0x%x payload len: 0x%x", 4513 sid, rscn_payload_len); 4514 } else { 4515 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4516 "RSCN payload_len: 0x%x page_len: 0x%x", 4517 rscn_payload_len, rscn->els.rscn_page_len); 4518 /* if this happens then we need to send ADISC to all the tports. */ 4519 list_for_each_entry_safe(tport, next, &iport->tport_list, links) { 4520 if (tport->state == FDLS_TGT_STATE_READY) 4521 tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC; 4522 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4523 "RSCN for port id: 0x%x", tport->fcid); 4524 } 4525 } /* end else */ 4526 } else { 4527 num_ports = (rscn_payload_len - 4) / rscn->els.rscn_page_len; 4528 rscn_port = (struct fc_els_rscn_page *)(rscn + 1); 4529 } 4530 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4531 "RSCN received for num_ports: %d payload_len: %d page_len: %d ", 4532 num_ports, rscn_payload_len, rscn->els.rscn_page_len); 4533 4534 /* 4535 * RSCN have at least one Port_ID page , but may not have any port_id 4536 * in it. If no port_id is specified in the Port_ID page , we send 4537 * ADISC to all the tports 4538 */ 4539 4540 while (num_ports) { 4541 4542 memcpy(fcid, rscn_port->rscn_fid, 3); 4543 4544 nport_id = ntoh24(fcid); 4545 rscn_port++; 4546 num_ports--; 4547 /* if this happens then we need to send ADISC to all the tports. */ 4548 if (nport_id == 0) { 4549 list_for_each_entry_safe(tport, next, &iport->tport_list, 4550 links) { 4551 if (tport->state == FDLS_TGT_STATE_READY) 4552 tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC; 4553 4554 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4555 "RSCN for port id: 0x%x", tport->fcid); 4556 } 4557 break; 4558 } 4559 tport = fnic_find_tport_by_fcid(iport, nport_id); 4560 4561 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4562 "RSCN port id list: 0x%x", nport_id); 4563 4564 if (!tport) { 4565 newports++; 4566 continue; 4567 } 4568 if (tport->state == FDLS_TGT_STATE_READY) 4569 tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC; 4570 } 4571 4572 if (pc_rscn_handling_feature_flag == PC_RSCN_HANDLING_FEATURE_ON && 4573 rscn_type == PC_RSCN && fnic->role == FNIC_ROLE_FCP_INITIATOR) { 4574 4575 if (fnic->pc_rscn_handling_status == PC_RSCN_HANDLING_IN_PROGRESS) { 4576 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4577 "PCRSCN handling already in progress. Skip host reset: %d", 4578 iport->fnic->fnic_num); 4579 return; 4580 } 4581 4582 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4583 "Processing PCRSCN. Queuing fnic for host reset: %d", 4584 iport->fnic->fnic_num); 4585 fnic->pc_rscn_handling_status = PC_RSCN_HANDLING_IN_PROGRESS; 4586 4587 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 4588 4589 spin_lock_irqsave(&reset_fnic_list_lock, 4590 reset_fnic_list_lock_flags); 4591 list_add_tail(&fnic->links, &reset_fnic_list); 4592 spin_unlock_irqrestore(&reset_fnic_list_lock, 4593 reset_fnic_list_lock_flags); 4594 4595 queue_work(reset_fnic_work_queue, &reset_fnic_work); 4596 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 4597 } else { 4598 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4599 "FDLS process RSCN sending GPN_FT: newports: %d", newports); 4600 fdls_send_gpn_ft(iport, FDLS_STATE_RSCN_GPN_FT); 4601 fdls_send_rscn_resp(iport, fchdr); 4602 } 4603 } 4604 4605 void fnic_fdls_disc_start(struct fnic_iport_s *iport) 4606 { 4607 struct fnic *fnic = iport->fnic; 4608 4609 fc_host_fabric_name(iport->fnic->host) = 0; 4610 fc_host_post_event(iport->fnic->host, fc_get_event_number(), 4611 FCH_EVT_LIPRESET, 0); 4612 4613 if (!iport->usefip) { 4614 if (iport->flags & FNIC_FIRST_LINK_UP) { 4615 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 4616 fnic_scsi_fcpio_reset(iport->fnic); 4617 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 4618 4619 iport->flags &= ~FNIC_FIRST_LINK_UP; 4620 } 4621 fnic_fdls_start_flogi(iport); 4622 } else 4623 fnic_fdls_start_plogi(iport); 4624 } 4625 4626 static void 4627 fdls_process_adisc_req(struct fnic_iport_s *iport, 4628 struct fc_frame_header *fchdr) 4629 { 4630 struct fc_std_els_adisc *padisc_acc; 4631 struct fc_std_els_adisc *adisc_req = (struct fc_std_els_adisc *)fchdr; 4632 uint64_t frame_wwnn; 4633 uint64_t frame_wwpn; 4634 uint32_t tgt_fcid; 4635 struct fnic_tport_s *tport; 4636 uint8_t *fcid; 4637 uint8_t *rjt_frame; 4638 uint8_t *acc_frame; 4639 struct fc_std_els_rjt_rsp *prjts_rsp; 4640 uint16_t oxid; 4641 struct fnic *fnic = iport->fnic; 4642 uint16_t rjt_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 4643 sizeof(struct fc_std_els_rjt_rsp); 4644 uint16_t acc_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET + 4645 sizeof(struct fc_std_els_adisc); 4646 4647 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4648 "Process ADISC request %d", iport->fnic->fnic_num); 4649 4650 fcid = FNIC_STD_GET_S_ID(fchdr); 4651 tgt_fcid = ntoh24(fcid); 4652 tport = fnic_find_tport_by_fcid(iport, tgt_fcid); 4653 if (!tport) { 4654 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4655 "tport for fcid: 0x%x not found. Dropping ADISC req.", 4656 tgt_fcid); 4657 return; 4658 } 4659 if (iport->state != FNIC_IPORT_STATE_READY) { 4660 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4661 "Dropping ADISC req from fcid: 0x%x in iport state: %d", 4662 tgt_fcid, iport->state); 4663 return; 4664 } 4665 4666 frame_wwnn = be64_to_cpu(adisc_req->els.adisc_wwnn); 4667 frame_wwpn = be64_to_cpu(adisc_req->els.adisc_wwpn); 4668 4669 if ((frame_wwnn != tport->wwnn) || (frame_wwpn != tport->wwpn)) { 4670 /* send reject */ 4671 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4672 "ADISC req from fcid: 0x%x mismatch wwpn: 0x%llx wwnn: 0x%llx", 4673 tgt_fcid, frame_wwpn, frame_wwnn); 4674 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4675 "local tport wwpn: 0x%llx wwnn: 0x%llx. Sending RJT", 4676 tport->wwpn, tport->wwnn); 4677 4678 rjt_frame = fdls_alloc_frame(iport); 4679 if (rjt_frame == NULL) { 4680 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4681 "Failed to allocate rjt_frame to send response to ADISC request"); 4682 return; 4683 } 4684 4685 prjts_rsp = (struct fc_std_els_rjt_rsp *) (rjt_frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4686 fdls_init_els_rjt_frame(rjt_frame, iport); 4687 4688 prjts_rsp->rej.er_reason = 0x03; /* logical error */ 4689 prjts_rsp->rej.er_explan = 0x1E; /* N_port login required */ 4690 prjts_rsp->rej.er_vendor = 0x0; 4691 4692 FNIC_STD_SET_S_ID(prjts_rsp->fchdr, fchdr->fh_d_id); 4693 FNIC_STD_SET_D_ID(prjts_rsp->fchdr, fchdr->fh_s_id); 4694 oxid = FNIC_STD_GET_OX_ID(fchdr); 4695 FNIC_STD_SET_OX_ID(prjts_rsp->fchdr, oxid); 4696 4697 fnic_send_fcoe_frame(iport, rjt_frame, rjt_frame_size); 4698 return; 4699 } 4700 4701 acc_frame = fdls_alloc_frame(iport); 4702 if (acc_frame == NULL) { 4703 FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num, 4704 "Failed to allocate frame to send ADISC accept"); 4705 return; 4706 } 4707 4708 padisc_acc = (struct fc_std_els_adisc *) (acc_frame + FNIC_ETH_FCOE_HDRS_OFFSET); 4709 4710 FNIC_STD_SET_S_ID(padisc_acc->fchdr, fchdr->fh_d_id); 4711 FNIC_STD_SET_D_ID(padisc_acc->fchdr, fchdr->fh_s_id); 4712 4713 FNIC_STD_SET_F_CTL(padisc_acc->fchdr, FNIC_ELS_REP_FCTL << 16); 4714 FNIC_STD_SET_R_CTL(padisc_acc->fchdr, FC_RCTL_ELS_REP); 4715 FNIC_STD_SET_TYPE(padisc_acc->fchdr, FC_TYPE_ELS); 4716 4717 oxid = FNIC_STD_GET_OX_ID(fchdr); 4718 FNIC_STD_SET_OX_ID(padisc_acc->fchdr, oxid); 4719 FNIC_STD_SET_RX_ID(padisc_acc->fchdr, FNIC_UNASSIGNED_RXID); 4720 4721 padisc_acc->els.adisc_cmd = ELS_LS_ACC; 4722 4723 FNIC_STD_SET_NPORT_NAME(&padisc_acc->els.adisc_wwpn, 4724 iport->wwpn); 4725 FNIC_STD_SET_NODE_NAME(&padisc_acc->els.adisc_wwnn, 4726 iport->wwnn); 4727 memcpy(padisc_acc->els.adisc_port_id, fchdr->fh_d_id, 3); 4728 4729 fnic_send_fcoe_frame(iport, acc_frame, acc_frame_size); 4730 } 4731 4732 /* 4733 * Performs a validation for all FCOE frames and return the frame type 4734 */ 4735 int 4736 fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport, 4737 struct fc_frame_header *fchdr) 4738 { 4739 uint8_t type; 4740 uint8_t *fc_payload; 4741 uint16_t oxid; 4742 uint32_t s_id; 4743 uint32_t d_id; 4744 struct fnic *fnic = iport->fnic; 4745 struct fnic_fdls_fabric_s *fabric = &iport->fabric; 4746 int oxid_frame_type; 4747 4748 oxid = FNIC_STD_GET_OX_ID(fchdr); 4749 fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header); 4750 type = *fc_payload; 4751 s_id = ntoh24(fchdr->fh_s_id); 4752 d_id = ntoh24(fchdr->fh_d_id); 4753 4754 /* some common validation */ 4755 if (fdls_get_state(fabric) > FDLS_STATE_FABRIC_FLOGI) { 4756 if (iport->fcid != d_id || (!FNIC_FC_FRAME_CS_CTL(fchdr))) { 4757 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4758 "invalid frame received. Dropping frame"); 4759 return -1; 4760 } 4761 } 4762 4763 /* BLS ABTS response */ 4764 if ((fchdr->fh_r_ctl == FC_RCTL_BA_ACC) 4765 || (fchdr->fh_r_ctl == FC_RCTL_BA_RJT)) { 4766 if (!(FNIC_FC_FRAME_TYPE_BLS(fchdr))) { 4767 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4768 "Received ABTS invalid frame. Dropping frame"); 4769 return -1; 4770 4771 } 4772 if (fdls_is_oxid_fabric_req(oxid)) { 4773 if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) { 4774 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4775 "Received unexpected ABTS RSP(oxid:0x%x) from 0x%x. Dropping frame", 4776 oxid, s_id); 4777 return -1; 4778 } 4779 return FNIC_FABRIC_BLS_ABTS_RSP; 4780 } else if (fdls_is_oxid_fdmi_req(oxid)) { 4781 return FNIC_FDMI_BLS_ABTS_RSP; 4782 } else if (fdls_is_oxid_tgt_req(oxid)) { 4783 return FNIC_TPORT_BLS_ABTS_RSP; 4784 } 4785 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4786 "Received ABTS rsp with unknown oxid(0x%x) from 0x%x. Dropping frame", 4787 oxid, s_id); 4788 return -1; 4789 } 4790 4791 /* BLS ABTS Req */ 4792 if ((fchdr->fh_r_ctl == FC_RCTL_BA_ABTS) 4793 && (FNIC_FC_FRAME_TYPE_BLS(fchdr))) { 4794 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4795 "Receiving Abort Request from s_id: 0x%x", s_id); 4796 return FNIC_BLS_ABTS_REQ; 4797 } 4798 4799 /* unsolicited requests frames */ 4800 if (FNIC_FC_FRAME_UNSOLICITED(fchdr)) { 4801 switch (type) { 4802 case ELS_LOGO: 4803 if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr)) 4804 || (!FNIC_FC_FRAME_UNSOLICITED(fchdr)) 4805 || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) { 4806 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4807 "Received LOGO invalid frame. Dropping frame"); 4808 return -1; 4809 } 4810 return FNIC_ELS_LOGO_REQ; 4811 case ELS_RSCN: 4812 if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr)) 4813 || (!FNIC_FC_FRAME_TYPE_ELS(fchdr)) 4814 || (!FNIC_FC_FRAME_UNSOLICITED(fchdr))) { 4815 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4816 "Received RSCN invalid FCTL. Dropping frame"); 4817 return -1; 4818 } 4819 if (s_id != FC_FID_FCTRL) 4820 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4821 "Received RSCN from target FCTL: 0x%x type: 0x%x s_id: 0x%x.", 4822 fchdr->fh_f_ctl[0], fchdr->fh_type, s_id); 4823 return FNIC_ELS_RSCN_REQ; 4824 case ELS_PLOGI: 4825 return FNIC_ELS_PLOGI_REQ; 4826 case ELS_ECHO: 4827 return FNIC_ELS_ECHO_REQ; 4828 case ELS_ADISC: 4829 return FNIC_ELS_ADISC; 4830 case ELS_RLS: 4831 return FNIC_ELS_RLS; 4832 case ELS_RRQ: 4833 return FNIC_ELS_RRQ; 4834 default: 4835 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4836 "Unsupported frame (type:0x%02x) from fcid: 0x%x", 4837 type, s_id); 4838 return FNIC_ELS_UNSUPPORTED_REQ; 4839 } 4840 } 4841 4842 /* solicited response from fabric or target */ 4843 oxid_frame_type = FNIC_FRAME_TYPE(oxid); 4844 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4845 "oxid frame code: 0x%x, oxid: 0x%x\n", oxid_frame_type, oxid); 4846 switch (oxid_frame_type) { 4847 case FNIC_FRAME_TYPE_FABRIC_FLOGI: 4848 if (type == ELS_LS_ACC) { 4849 if ((s_id != FC_FID_FLOGI) 4850 || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) { 4851 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4852 "Received unknown frame. Dropping frame"); 4853 return -1; 4854 } 4855 } 4856 return FNIC_FABRIC_FLOGI_RSP; 4857 4858 case FNIC_FRAME_TYPE_FABRIC_PLOGI: 4859 if (type == ELS_LS_ACC) { 4860 if ((s_id != FC_FID_DIR_SERV) 4861 || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) { 4862 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4863 "Received unknown frame. Dropping frame"); 4864 return -1; 4865 } 4866 } 4867 return FNIC_FABRIC_PLOGI_RSP; 4868 4869 case FNIC_FRAME_TYPE_FABRIC_SCR: 4870 if (type == ELS_LS_ACC) { 4871 if ((s_id != FC_FID_FCTRL) 4872 || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) { 4873 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4874 "Received unknown frame. Dropping frame"); 4875 return -1; 4876 } 4877 } 4878 return FNIC_FABRIC_SCR_RSP; 4879 4880 case FNIC_FRAME_TYPE_FABRIC_RPN: 4881 if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) { 4882 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4883 "Received unknown frame. Dropping frame"); 4884 return -1; 4885 } 4886 return FNIC_FABRIC_RPN_RSP; 4887 4888 case FNIC_FRAME_TYPE_FABRIC_RFT: 4889 if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) { 4890 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4891 "Received unknown frame. Dropping frame"); 4892 return -1; 4893 } 4894 return FNIC_FABRIC_RFT_RSP; 4895 4896 case FNIC_FRAME_TYPE_FABRIC_RFF: 4897 if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) { 4898 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4899 "Received unknown frame. Dropping frame"); 4900 return -1; 4901 } 4902 return FNIC_FABRIC_RFF_RSP; 4903 4904 case FNIC_FRAME_TYPE_FABRIC_GPN_FT: 4905 if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) { 4906 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4907 "Received unknown frame. Dropping frame"); 4908 return -1; 4909 } 4910 return FNIC_FABRIC_GPN_FT_RSP; 4911 4912 case FNIC_FRAME_TYPE_FABRIC_LOGO: 4913 return FNIC_FABRIC_LOGO_RSP; 4914 case FNIC_FRAME_TYPE_FDMI_PLOGI: 4915 return FNIC_FDMI_PLOGI_RSP; 4916 case FNIC_FRAME_TYPE_FDMI_RHBA: 4917 return FNIC_FDMI_REG_HBA_RSP; 4918 case FNIC_FRAME_TYPE_FDMI_RPA: 4919 return FNIC_FDMI_RPA_RSP; 4920 case FNIC_FRAME_TYPE_TGT_PLOGI: 4921 return FNIC_TPORT_PLOGI_RSP; 4922 case FNIC_FRAME_TYPE_TGT_PRLI: 4923 return FNIC_TPORT_PRLI_RSP; 4924 case FNIC_FRAME_TYPE_TGT_ADISC: 4925 return FNIC_TPORT_ADISC_RSP; 4926 case FNIC_FRAME_TYPE_TGT_LOGO: 4927 if (!FNIC_FC_FRAME_TYPE_ELS(fchdr)) { 4928 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4929 "Dropping Unknown frame in tport solicited exchange range type: 0x%x.", 4930 fchdr->fh_type); 4931 return -1; 4932 } 4933 return FNIC_TPORT_LOGO_RSP; 4934 default: 4935 /* Drop the Rx frame and log/stats it */ 4936 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 4937 "Solicited response: unknown OXID: 0x%x", oxid); 4938 return -1; 4939 } 4940 4941 return -1; 4942 } 4943 4944 void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame, 4945 int len, int fchdr_offset) 4946 { 4947 struct fc_frame_header *fchdr; 4948 uint32_t s_id = 0; 4949 uint32_t d_id = 0; 4950 struct fnic *fnic = iport->fnic; 4951 int frame_type; 4952 4953 fchdr = (struct fc_frame_header *) ((uint8_t *) rx_frame + fchdr_offset); 4954 s_id = ntoh24(fchdr->fh_s_id); 4955 d_id = ntoh24(fchdr->fh_d_id); 4956 4957 fnic_debug_dump_fc_frame(fnic, fchdr, len, "Incoming"); 4958 4959 frame_type = 4960 fnic_fdls_validate_and_get_frame_type(iport, fchdr); 4961 4962 /*if we are in flogo drop everything else */ 4963 if (iport->fabric.state == FDLS_STATE_FABRIC_LOGO && 4964 frame_type != FNIC_FABRIC_LOGO_RSP) 4965 return; 4966 4967 switch (frame_type) { 4968 case FNIC_FABRIC_FLOGI_RSP: 4969 fdls_process_flogi_rsp(iport, fchdr, rx_frame); 4970 break; 4971 case FNIC_FABRIC_PLOGI_RSP: 4972 fdls_process_fabric_plogi_rsp(iport, fchdr); 4973 break; 4974 case FNIC_FDMI_PLOGI_RSP: 4975 fdls_process_fdmi_plogi_rsp(iport, fchdr); 4976 break; 4977 case FNIC_FABRIC_RPN_RSP: 4978 fdls_process_rpn_id_rsp(iport, fchdr); 4979 break; 4980 case FNIC_FABRIC_RFT_RSP: 4981 fdls_process_rft_id_rsp(iport, fchdr); 4982 break; 4983 case FNIC_FABRIC_RFF_RSP: 4984 fdls_process_rff_id_rsp(iport, fchdr); 4985 break; 4986 case FNIC_FABRIC_SCR_RSP: 4987 fdls_process_scr_rsp(iport, fchdr); 4988 break; 4989 case FNIC_FABRIC_GPN_FT_RSP: 4990 fdls_process_gpn_ft_rsp(iport, fchdr, len); 4991 break; 4992 case FNIC_TPORT_PLOGI_RSP: 4993 fdls_process_tgt_plogi_rsp(iport, fchdr); 4994 break; 4995 case FNIC_TPORT_PRLI_RSP: 4996 fdls_process_tgt_prli_rsp(iport, fchdr); 4997 break; 4998 case FNIC_TPORT_ADISC_RSP: 4999 fdls_process_tgt_adisc_rsp(iport, fchdr); 5000 break; 5001 case FNIC_TPORT_BLS_ABTS_RSP: 5002 fdls_process_tgt_abts_rsp(iport, fchdr); 5003 break; 5004 case FNIC_TPORT_LOGO_RSP: 5005 /* Logo response from tgt which we have deleted */ 5006 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5007 "Logo response from tgt: 0x%x", 5008 ntoh24(fchdr->fh_s_id)); 5009 break; 5010 case FNIC_FABRIC_LOGO_RSP: 5011 fdls_process_fabric_logo_rsp(iport, fchdr); 5012 break; 5013 case FNIC_FABRIC_BLS_ABTS_RSP: 5014 fdls_process_fabric_abts_rsp(iport, fchdr); 5015 break; 5016 case FNIC_FDMI_BLS_ABTS_RSP: 5017 fdls_process_fdmi_abts_rsp(iport, fchdr); 5018 break; 5019 case FNIC_BLS_ABTS_REQ: 5020 fdls_process_abts_req(iport, fchdr); 5021 break; 5022 case FNIC_ELS_UNSUPPORTED_REQ: 5023 fdls_process_unsupported_els_req(iport, fchdr); 5024 break; 5025 case FNIC_ELS_PLOGI_REQ: 5026 fdls_process_plogi_req(iport, fchdr); 5027 break; 5028 case FNIC_ELS_RSCN_REQ: 5029 fdls_process_rscn(iport, fchdr); 5030 break; 5031 case FNIC_ELS_LOGO_REQ: 5032 fdls_process_logo_req(iport, fchdr); 5033 break; 5034 case FNIC_ELS_RRQ: 5035 case FNIC_ELS_ECHO_REQ: 5036 fdls_process_els_req(iport, fchdr, len); 5037 break; 5038 case FNIC_ELS_ADISC: 5039 fdls_process_adisc_req(iport, fchdr); 5040 break; 5041 case FNIC_ELS_RLS: 5042 fdls_process_rls_req(iport, fchdr); 5043 break; 5044 case FNIC_FDMI_REG_HBA_RSP: 5045 case FNIC_FDMI_RPA_RSP: 5046 fdls_process_fdmi_reg_ack(iport, fchdr, frame_type); 5047 break; 5048 default: 5049 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5050 "s_id: 0x%x d_did: 0x%x", s_id, d_id); 5051 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5052 "Received unknown FCoE frame of len: %d. Dropping frame", len); 5053 break; 5054 } 5055 } 5056 5057 void fnic_fdls_disc_init(struct fnic_iport_s *iport) 5058 { 5059 fdls_reset_oxid_pool(iport); 5060 fdls_set_state((&iport->fabric), FDLS_STATE_INIT); 5061 } 5062 5063 void fnic_fdls_link_down(struct fnic_iport_s *iport) 5064 { 5065 struct fnic_tport_s *tport, *next; 5066 struct fnic *fnic = iport->fnic; 5067 5068 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5069 "0x%x: FDLS processing link down", iport->fcid); 5070 5071 fdls_set_state((&iport->fabric), FDLS_STATE_LINKDOWN); 5072 iport->fabric.flags = 0; 5073 5074 spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags); 5075 fnic_scsi_fcpio_reset(iport->fnic); 5076 spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags); 5077 list_for_each_entry_safe(tport, next, &iport->tport_list, links) { 5078 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5079 "removing rport: 0x%x", tport->fcid); 5080 fdls_delete_tport(iport, tport); 5081 } 5082 5083 if (fnic_fdmi_support == 1) { 5084 if (iport->fabric.fdmi_pending > 0) { 5085 timer_delete_sync(&iport->fabric.fdmi_timer); 5086 iport->fabric.fdmi_pending = 0; 5087 } 5088 iport->flags &= ~FNIC_FDMI_ACTIVE; 5089 } 5090 5091 FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num, 5092 "0x%x: FDLS finish processing link down", iport->fcid); 5093 } 5094