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