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 #ifndef _FNIC_FDLS_H_ 8 #define _FNIC_FDLS_H_ 9 10 #include "fnic_stats.h" 11 #include "fdls_fc.h" 12 13 /* FDLS - Fabric discovery and login services 14 * -> VLAN discovery 15 * -> retry every retry delay seconds until it succeeds. 16 * <- List of VLANs 17 * 18 * -> Solicitation 19 * <- Solicitation response (Advertisement) 20 * 21 * -> FCF selection & FLOGI ( FLOGI timeout - 2 * E_D_TOV) 22 * <- FLOGI response 23 * 24 * -> FCF keep alive 25 * <- FCF keep alive 26 * 27 * -> PLOGI to FFFFFC (DNS) (PLOGI timeout - 2 * R_A_TOV) 28 * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV) 29 * <- PLOGI response 30 * -> Retry PLOGI to FFFFFC (DNS) - Number of retries from vnic.cfg 31 * 32 * -> SCR to FFFFFC (DNS) (SCR timeout - 2 * R_A_TOV) 33 * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV) 34 * <- SCR response 35 * -> Retry SCR - Number of retries 2 36 * 37 * -> GPN_FT to FFFFFC (GPN_FT timeout - 2 * R_A_TOV)a 38 * -> Retry on BUSY until it succeeds 39 * -> Retry on BUSY until it succeeds 40 * -> 2 retries on timeout 41 * 42 * -> RFT_ID to FFFFFC (DNS) (RFT_ID timeout - 3 * R_A_TOV) 43 * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV) 44 * -> Retry RFT_ID to FFFFFC (DNS) (Number of retries 2 ) 45 * -> Ignore if both retires fail. 46 * 47 * Session establishment with targets 48 * For each PWWN 49 * -> PLOGI to FCID of that PWWN (PLOGI timeout 2 * R_A_TOV) 50 * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV) 51 * <- PLOGI response 52 * -> Retry PLOGI. Num retries using vnic.cfg 53 * 54 * -> PRLI to FCID of that PWWN (PRLI timeout 2 * R_A_TOV) 55 * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV) 56 * <- PRLI response 57 * -> Retry PRLI. Num retries using vnic.cfg 58 * 59 */ 60 61 #define FDLS_RETRY_COUNT 2 62 63 /* 64 * OXID encoding: 65 * bits 0-8: oxid idx - allocated from poool 66 * bits 9-13: oxid frame code from fnic_oxid_frame_type_e 67 * bits 14-15: all zeros 68 */ 69 #define FNIC_OXID_POOL_SZ (512) /* always power of 2 */ 70 #define FNIC_OXID_ENCODE(idx, frame_type) (frame_type | idx) 71 #define FNIC_FRAME_MASK 0xFE00 72 #define FNIC_FRAME_TYPE(oxid) (oxid & FNIC_FRAME_MASK) 73 #define FNIC_OXID_IDX(oxid) ((oxid) & (FNIC_OXID_POOL_SZ - 1)) 74 75 #define OXID_RECLAIM_TOV(iport) (2 * iport->r_a_tov) /* in milliseconds */ 76 77 #define FNIC_FDLS_FABRIC_ABORT_ISSUED 0x1 78 #define FNIC_FDLS_FPMA_LEARNT 0x2 79 80 /* tport flags */ 81 #define FNIC_FDLS_TPORT_IN_GPN_FT_LIST 0x1 82 #define FNIC_FDLS_TGT_ABORT_ISSUED 0x2 83 #define FNIC_FDLS_TPORT_SEND_ADISC 0x4 84 #define FNIC_FDLS_RETRY_FRAME 0x8 85 #define FNIC_FDLS_TPORT_BUSY 0x10 86 #define FNIC_FDLS_TPORT_TERMINATING 0x20 87 #define FNIC_FDLS_TPORT_DELETED 0x40 88 #define FNIC_FDLS_SCSI_REGISTERED 0x200 89 90 /* Retry supported by rport(returned by prli service parameters) */ 91 #define FDLS_FC_RP_FLAGS_RETRY 0x1 92 93 #define fdls_set_state(_fdls_fabric, _state) ((_fdls_fabric)->state = _state) 94 #define fdls_get_state(_fdls_fabric) ((_fdls_fabric)->state) 95 96 #define FNIC_FDMI_ACTIVE 0x8 97 #define FNIC_FIRST_LINK_UP 0x2 98 99 #define fdls_set_tport_state(_tport, _state) (_tport->state = _state) 100 #define fdls_get_tport_state(_tport) (_tport->state) 101 102 #define FNIC_PORTSPEED_10GBIT 1 103 #define FNIC_FRAME_HT_ROOM (2148) 104 #define FNIC_FCOE_FRAME_MAXSZ (2112) 105 106 107 #define FNIC_FRAME_TYPE_FABRIC_FLOGI 0x1000 108 #define FNIC_FRAME_TYPE_FABRIC_PLOGI 0x1200 109 #define FNIC_FRAME_TYPE_FABRIC_RPN 0x1400 110 #define FNIC_FRAME_TYPE_FABRIC_RFT 0x1600 111 #define FNIC_FRAME_TYPE_FABRIC_RFF 0x1800 112 #define FNIC_FRAME_TYPE_FABRIC_SCR 0x1A00 113 #define FNIC_FRAME_TYPE_FABRIC_GPN_FT 0x1C00 114 #define FNIC_FRAME_TYPE_FABRIC_LOGO 0x1E00 115 #define FNIC_FRAME_TYPE_FDMI_PLOGI 0x2000 116 #define FNIC_FRAME_TYPE_FDMI_RHBA 0x2200 117 #define FNIC_FRAME_TYPE_FDMI_RPA 0x2400 118 #define FNIC_FRAME_TYPE_TGT_PLOGI 0x2600 119 #define FNIC_FRAME_TYPE_TGT_PRLI 0x2800 120 #define FNIC_FRAME_TYPE_TGT_ADISC 0x2A00 121 #define FNIC_FRAME_TYPE_TGT_LOGO 0x2C00 122 123 struct fnic_fip_fcf_s { 124 uint16_t vlan_id; 125 uint8_t fcf_mac[6]; 126 uint8_t fcf_priority; 127 uint32_t fka_adv_period; 128 uint8_t ka_disabled; 129 }; 130 131 enum fnic_fdls_state_e { 132 FDLS_STATE_INIT = 0, 133 FDLS_STATE_LINKDOWN, 134 FDLS_STATE_FABRIC_LOGO, 135 FDLS_STATE_FLOGO_DONE, 136 FDLS_STATE_FABRIC_FLOGI, 137 FDLS_STATE_FABRIC_PLOGI, 138 FDLS_STATE_RPN_ID, 139 FDLS_STATE_REGISTER_FC4_TYPES, 140 FDLS_STATE_REGISTER_FC4_FEATURES, 141 FDLS_STATE_SCR, 142 FDLS_STATE_GPN_FT, 143 FDLS_STATE_TGT_DISCOVERY, 144 FDLS_STATE_RSCN_GPN_FT, 145 FDLS_STATE_SEND_GPNFT 146 }; 147 148 struct fnic_fdls_fabric_s { 149 enum fnic_fdls_state_e state; 150 uint32_t flags; 151 struct list_head tport_list; /* List of discovered tports */ 152 struct timer_list retry_timer; 153 int del_timer_inprogress; 154 int del_fdmi_timer_inprogress; 155 int retry_counter; 156 int timer_pending; 157 int fdmi_retry; 158 struct timer_list fdmi_timer; 159 int fdmi_pending; 160 }; 161 162 struct fnic_fdls_fip_s { 163 uint32_t state; 164 uint32_t flogi_retry; 165 }; 166 167 /* Message to tport_event_handler */ 168 enum fnic_tgt_msg_id { 169 TGT_EV_NONE = 0, 170 TGT_EV_RPORT_ADD, 171 TGT_EV_RPORT_DEL, 172 TGT_EV_TPORT_DELETE, 173 TGT_EV_REMOVE 174 }; 175 176 struct fnic_tport_event_s { 177 struct list_head links; 178 enum fnic_tgt_msg_id event; 179 void *arg1; 180 }; 181 182 enum fdls_tgt_state_e { 183 FDLS_TGT_STATE_INIT = 0, 184 FDLS_TGT_STATE_PLOGI, 185 FDLS_TGT_STATE_PRLI, 186 FDLS_TGT_STATE_READY, 187 FDLS_TGT_STATE_LOGO_RECEIVED, 188 FDLS_TGT_STATE_ADISC, 189 FDL_TGT_STATE_PLOGO, 190 FDLS_TGT_STATE_OFFLINING, 191 FDLS_TGT_STATE_OFFLINE 192 }; 193 194 struct fnic_tport_s { 195 struct list_head links; /* To link the tports */ 196 enum fdls_tgt_state_e state; 197 uint32_t flags; 198 uint32_t fcid; 199 uint64_t wwpn; 200 uint64_t wwnn; 201 uint16_t active_oxid; 202 uint16_t tgt_flags; 203 atomic_t in_flight; /* io counter */ 204 uint16_t max_payload_size; 205 uint16_t r_a_tov; 206 uint16_t e_d_tov; 207 uint16_t lun0_delay; 208 int max_concur_seqs; 209 uint32_t fcp_csp; 210 struct timer_list retry_timer; 211 int del_timer_inprogress; 212 int retry_counter; 213 int timer_pending; 214 unsigned int num_pending_cmds; 215 int nexus_restart_count; 216 int exch_reset_in_progress; 217 void *iport; 218 struct work_struct tport_del_work; 219 struct completion *tport_del_done; 220 struct fc_rport *rport; 221 char str_wwpn[20]; 222 char str_wwnn[20]; 223 }; 224 225 /* OXID pool related structures */ 226 struct reclaim_entry_s { 227 struct list_head links; 228 /* oxid that needs to be freed after 2*r_a_tov */ 229 uint16_t oxid_idx; 230 /* in jiffies. Use this to waiting time */ 231 unsigned long expires; 232 unsigned long *bitmap; 233 }; 234 235 /* used for allocating oxids for fabric and fdmi requests */ 236 struct fnic_oxid_pool_s { 237 DECLARE_BITMAP(bitmap, FNIC_OXID_POOL_SZ); 238 int sz; /* size of the pool or block */ 239 int next_idx; /* used for cycling through the oxid pool */ 240 241 /* retry schedule free */ 242 DECLARE_BITMAP(pending_schedule_free, FNIC_OXID_POOL_SZ); 243 struct delayed_work schedule_oxid_free_retry; 244 245 /* List of oxids that need to be freed and reclaimed. 246 * This list is shared by all the oxid pools 247 */ 248 struct list_head oxid_reclaim_list; 249 /* Work associated with reclaim list */ 250 struct delayed_work oxid_reclaim_work; 251 }; 252 253 /* iport */ 254 enum fnic_iport_state_e { 255 FNIC_IPORT_STATE_INIT = 0, 256 FNIC_IPORT_STATE_LINK_WAIT, 257 FNIC_IPORT_STATE_FIP, 258 FNIC_IPORT_STATE_FABRIC_DISC, 259 FNIC_IPORT_STATE_READY 260 }; 261 262 struct fnic_iport_s { 263 enum fnic_iport_state_e state; 264 struct fnic *fnic; 265 uint64_t boot_time; 266 uint32_t flags; 267 int usefip; 268 uint8_t hwmac[6]; /* HW MAC Addr */ 269 uint8_t fpma[6]; /* Fabric Provided MA */ 270 uint8_t fcfmac[6]; /* MAC addr of Fabric */ 271 uint16_t vlan_id; 272 uint32_t fcid; 273 274 /* oxid pool */ 275 struct fnic_oxid_pool_s oxid_pool; 276 277 /* 278 * fabric reqs are serialized and only one req at a time. 279 * Tracking the oxid for sending abort 280 */ 281 uint16_t active_oxid_fabric_req; 282 /* fdmi only */ 283 uint16_t active_oxid_fdmi_plogi; 284 uint16_t active_oxid_fdmi_rhba; 285 uint16_t active_oxid_fdmi_rpa; 286 287 struct fnic_fip_fcf_s selected_fcf; 288 struct fnic_fdls_fip_s fip; 289 struct fnic_fdls_fabric_s fabric; 290 struct list_head tport_list; 291 struct list_head tport_list_pending_del; 292 /* list of tports for which we are yet to send PLOGO */ 293 struct list_head inprocess_tport_list; 294 struct list_head deleted_tport_list; 295 struct work_struct tport_event_work; 296 uint32_t e_d_tov; /* msec */ 297 uint32_t r_a_tov; /* msec */ 298 uint32_t link_supported_speeds; 299 uint32_t max_flogi_retries; 300 uint32_t max_plogi_retries; 301 uint32_t plogi_timeout; 302 uint32_t service_params; 303 uint64_t wwpn; 304 uint64_t wwnn; 305 uint16_t max_payload_size; 306 spinlock_t deleted_tport_lst_lock; 307 struct completion *flogi_reg_done; 308 struct fnic_iport_stats iport_stats; 309 char str_wwpn[20]; 310 char str_wwnn[20]; 311 }; 312 313 struct rport_dd_data_s { 314 struct fnic_tport_s *tport; 315 struct fnic_iport_s *iport; 316 }; 317 318 enum fnic_recv_frame_type_e { 319 FNIC_FABRIC_FLOGI_RSP = 1, 320 FNIC_FABRIC_PLOGI_RSP, 321 FNIC_FABRIC_RPN_RSP, 322 FNIC_FABRIC_RFT_RSP, 323 FNIC_FABRIC_RFF_RSP, 324 FNIC_FABRIC_SCR_RSP, 325 FNIC_FABRIC_GPN_FT_RSP, 326 FNIC_FABRIC_BLS_ABTS_RSP, 327 FNIC_FDMI_PLOGI_RSP, 328 FNIC_FDMI_REG_HBA_RSP, 329 FNIC_FDMI_RPA_RSP, 330 FNIC_FDMI_BLS_ABTS_RSP, 331 FNIC_FABRIC_LOGO_RSP, 332 333 /* responses to target requests */ 334 FNIC_TPORT_PLOGI_RSP, 335 FNIC_TPORT_PRLI_RSP, 336 FNIC_TPORT_ADISC_RSP, 337 FNIC_TPORT_BLS_ABTS_RSP, 338 FNIC_TPORT_LOGO_RSP, 339 340 /* unsolicited requests */ 341 FNIC_BLS_ABTS_REQ, 342 FNIC_ELS_PLOGI_REQ, 343 FNIC_ELS_RSCN_REQ, 344 FNIC_ELS_LOGO_REQ, 345 FNIC_ELS_ECHO_REQ, 346 FNIC_ELS_ADISC, 347 FNIC_ELS_RLS, 348 FNIC_ELS_RRQ, 349 FNIC_ELS_UNSUPPORTED_REQ, 350 }; 351 352 enum fnic_port_speeds { 353 DCEM_PORTSPEED_NONE = 0, 354 DCEM_PORTSPEED_1G = 1000, 355 DCEM_PORTSPEED_2G = 2000, 356 DCEM_PORTSPEED_4G = 4000, 357 DCEM_PORTSPEED_8G = 8000, 358 DCEM_PORTSPEED_10G = 10000, 359 DCEM_PORTSPEED_16G = 16000, 360 DCEM_PORTSPEED_20G = 20000, 361 DCEM_PORTSPEED_25G = 25000, 362 DCEM_PORTSPEED_32G = 32000, 363 DCEM_PORTSPEED_40G = 40000, 364 DCEM_PORTSPEED_4x10G = 41000, 365 DCEM_PORTSPEED_50G = 50000, 366 DCEM_PORTSPEED_64G = 64000, 367 DCEM_PORTSPEED_100G = 100000, 368 DCEM_PORTSPEED_128G = 128000, 369 }; 370 371 /* Function Declarations */ 372 /* fdls_disc.c */ 373 void fnic_fdls_disc_init(struct fnic_iport_s *iport); 374 void fnic_fdls_disc_start(struct fnic_iport_s *iport); 375 void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame, 376 int len, int fchdr_offset); 377 void fnic_fdls_link_down(struct fnic_iport_s *iport); 378 int fdls_init_frame_pool(struct fnic_iport_s *iport); 379 uint8_t *fdls_alloc_frame(struct fnic_iport_s *iport); 380 uint16_t fdls_alloc_oxid(struct fnic_iport_s *iport, int oxid_frame_type, 381 uint16_t *active_oxid); 382 void fdls_free_oxid(struct fnic_iport_s *iport, 383 uint16_t oxid, uint16_t *active_oxid); 384 void fdls_tgt_logout(struct fnic_iport_s *iport, 385 struct fnic_tport_s *tport); 386 void fnic_del_fabric_timer_sync(struct fnic *fnic); 387 void fnic_del_tport_timer_sync(struct fnic *fnic, 388 struct fnic_tport_s *tport); 389 void fdls_send_fabric_logo(struct fnic_iport_s *iport); 390 int fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport, 391 struct fc_frame_header *fchdr); 392 void fdls_send_tport_abts(struct fnic_iport_s *iport, 393 struct fnic_tport_s *tport); 394 bool fdls_delete_tport(struct fnic_iport_s *iport, 395 struct fnic_tport_s *tport); 396 void fdls_fdmi_timer_callback(struct timer_list *t); 397 398 /* fnic_fcs.c */ 399 void fnic_fdls_init(struct fnic *fnic, int usefip); 400 void fnic_send_fcoe_frame(struct fnic_iport_s *iport, void *frame, 401 int frame_size); 402 void fnic_fcoe_send_vlan_req(struct fnic *fnic); 403 int fnic_send_fip_frame(struct fnic_iport_s *iport, 404 void *frame, int frame_size); 405 void fnic_fdls_learn_fcoe_macs(struct fnic_iport_s *iport, void *rx_frame, 406 uint8_t *fcid); 407 void fnic_fdls_add_tport(struct fnic_iport_s *iport, 408 struct fnic_tport_s *tport, unsigned long flags); 409 void fnic_fdls_remove_tport(struct fnic_iport_s *iport, 410 struct fnic_tport_s *tport, 411 unsigned long flags); 412 413 /* fip.c */ 414 void fnic_fcoe_send_vlan_req(struct fnic *fnic); 415 void fnic_common_fip_cleanup(struct fnic *fnic); 416 int fdls_fip_recv_frame(struct fnic *fnic, void *frame); 417 void fnic_handle_fcs_ka_timer(struct timer_list *t); 418 void fnic_handle_enode_ka_timer(struct timer_list *t); 419 void fnic_handle_vn_ka_timer(struct timer_list *t); 420 void fnic_handle_fip_timer(struct timer_list *t); 421 extern void fdls_fabric_timer_callback(struct timer_list *t); 422 423 /* fnic_scsi.c */ 424 void fnic_scsi_fcpio_reset(struct fnic *fnic); 425 extern void fdls_fabric_timer_callback(struct timer_list *t); 426 void fnic_rport_exch_reset(struct fnic *fnic, u32 fcid); 427 int fnic_fdls_register_portid(struct fnic_iport_s *iport, u32 port_id, 428 void *fp); 429 struct fnic_tport_s *fnic_find_tport_by_fcid(struct fnic_iport_s *iport, 430 uint32_t fcid); 431 struct fnic_tport_s *fnic_find_tport_by_wwpn(struct fnic_iport_s *iport, 432 uint64_t wwpn); 433 434 #endif /* _FNIC_FDLS_H_ */ 435