2 * This file is part of the Chelsio FCoE driver for Linux.
4 * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/kernel.h>
36 #include <linux/delay.h>
37 #include <linux/slab.h>
38 #include <linux/utsname.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_transport_fc.h>
41 #include <asm/unaligned.h>
42 #include <scsi/fc/fc_els.h>
43 #include <scsi/fc/fc_fs.h>
44 #include <scsi/fc/fc_gs.h>
45 #include <scsi/fc/fc_ms.h>
49 #include "csio_lnode.h"
50 #include "csio_rnode.h"
52 int csio_fcoe_rnodes
= 1024;
53 int csio_fdmi_enable
= 1;
55 #define PORT_ID_PTR(_x) ((uint8_t *)(&_x) + 1)
57 /* Lnode SM declarations */
58 static void csio_lns_uninit(struct csio_lnode
*, enum csio_ln_ev
);
59 static void csio_lns_online(struct csio_lnode
*, enum csio_ln_ev
);
60 static void csio_lns_ready(struct csio_lnode
*, enum csio_ln_ev
);
61 static void csio_lns_offline(struct csio_lnode
*, enum csio_ln_ev
);
63 static int csio_ln_mgmt_submit_req(struct csio_ioreq
*,
64 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
65 enum fcoe_cmn_type
, struct csio_dma_buf
*, uint32_t);
67 /* LN event mapping */
68 static enum csio_ln_ev fwevt_to_lnevt
[] = {
69 CSIO_LNE_NONE
, /* None */
70 CSIO_LNE_NONE
, /* PLOGI_ACC_RCVD */
71 CSIO_LNE_NONE
, /* PLOGI_RJT_RCVD */
72 CSIO_LNE_NONE
, /* PLOGI_RCVD */
73 CSIO_LNE_NONE
, /* PLOGO_RCVD */
74 CSIO_LNE_NONE
, /* PRLI_ACC_RCVD */
75 CSIO_LNE_NONE
, /* PRLI_RJT_RCVD */
76 CSIO_LNE_NONE
, /* PRLI_RCVD */
77 CSIO_LNE_NONE
, /* PRLO_RCVD */
78 CSIO_LNE_NONE
, /* NPORT_ID_CHGD */
79 CSIO_LNE_LOGO
, /* FLOGO_RCVD */
80 CSIO_LNE_LOGO
, /* CLR_VIRT_LNK_RCVD */
81 CSIO_LNE_FAB_INIT_DONE
,/* FLOGI_ACC_RCVD */
82 CSIO_LNE_NONE
, /* FLOGI_RJT_RCVD */
83 CSIO_LNE_FAB_INIT_DONE
,/* FDISC_ACC_RCVD */
84 CSIO_LNE_NONE
, /* FDISC_RJT_RCVD */
85 CSIO_LNE_NONE
, /* FLOGI_TMO_MAX_RETRY */
86 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_ACC */
87 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_RJT */
88 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_CNFLT */
89 CSIO_LNE_NONE
, /* PRLI_TMO */
90 CSIO_LNE_NONE
, /* ADISC_TMO */
91 CSIO_LNE_NONE
, /* RSCN_DEV_LOST */
92 CSIO_LNE_NONE
, /* SCR_ACC_RCVD */
93 CSIO_LNE_NONE
, /* ADISC_RJT_RCVD */
94 CSIO_LNE_NONE
, /* LOGO_SNT */
95 CSIO_LNE_NONE
, /* PROTO_ERR_IMPL_LOGO */
98 #define CSIO_FWE_TO_LNE(_evt) ((_evt > PROTO_ERR_IMPL_LOGO) ? \
100 fwevt_to_lnevt[_evt])
102 #define csio_ct_rsp(cp) (((struct fc_ct_hdr *)cp)->ct_cmd)
103 #define csio_ct_reason(cp) (((struct fc_ct_hdr *)cp)->ct_reason)
104 #define csio_ct_expl(cp) (((struct fc_ct_hdr *)cp)->ct_explan)
105 #define csio_ct_get_pld(cp) ((void *)(((uint8_t *)cp) + FC_CT_HDR_LEN))
108 * csio_ln_match_by_portid - lookup lnode using given portid.
112 * If found, returns lnode matching given portid otherwise returns NULL.
114 static struct csio_lnode
*
115 csio_ln_lookup_by_portid(struct csio_hw
*hw
, uint8_t portid
)
117 struct csio_lnode
*ln
= hw
->rln
;
118 struct list_head
*tmp
;
120 /* Match siblings lnode with portid */
121 list_for_each(tmp
, &hw
->sln_head
) {
122 ln
= (struct csio_lnode
*) tmp
;
123 if (ln
->portid
== portid
)
131 * csio_ln_lookup_by_vnpi - Lookup lnode using given vnp id.
134 * Returns - If found, returns lnode matching given vnp id
135 * otherwise returns NULL.
137 static struct csio_lnode
*
138 csio_ln_lookup_by_vnpi(struct csio_hw
*hw
, uint32_t vnp_id
)
140 struct list_head
*tmp1
, *tmp2
;
141 struct csio_lnode
*sln
= NULL
, *cln
= NULL
;
143 if (list_empty(&hw
->sln_head
)) {
144 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
147 /* Traverse sibling lnodes */
148 list_for_each(tmp1
, &hw
->sln_head
) {
149 sln
= (struct csio_lnode
*) tmp1
;
151 /* Match sibling lnode */
152 if (sln
->vnp_flowid
== vnp_id
)
155 if (list_empty(&sln
->cln_head
))
158 /* Traverse children lnodes */
159 list_for_each(tmp2
, &sln
->cln_head
) {
160 cln
= (struct csio_lnode
*) tmp2
;
162 if (cln
->vnp_flowid
== vnp_id
)
166 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
171 * csio_lnode_lookup_by_wwpn - Lookup lnode using given wwpn.
175 * If found, returns lnode matching given wwpn, returns NULL otherwise.
178 csio_lnode_lookup_by_wwpn(struct csio_hw
*hw
, uint8_t *wwpn
)
180 struct list_head
*tmp1
, *tmp2
;
181 struct csio_lnode
*sln
= NULL
, *cln
= NULL
;
183 if (list_empty(&hw
->sln_head
)) {
184 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
187 /* Traverse sibling lnodes */
188 list_for_each(tmp1
, &hw
->sln_head
) {
189 sln
= (struct csio_lnode
*) tmp1
;
191 /* Match sibling lnode */
192 if (!memcmp(csio_ln_wwpn(sln
), wwpn
, 8))
195 if (list_empty(&sln
->cln_head
))
198 /* Traverse children lnodes */
199 list_for_each(tmp2
, &sln
->cln_head
) {
200 cln
= (struct csio_lnode
*) tmp2
;
202 if (!memcmp(csio_ln_wwpn(cln
), wwpn
, 8))
211 csio_fill_ct_iu(void *buf
, uint8_t type
, uint8_t sub_type
, uint16_t op
)
213 struct fc_ct_hdr
*cmd
= (struct fc_ct_hdr
*)buf
;
214 cmd
->ct_rev
= FC_CT_REV
;
215 cmd
->ct_fs_type
= type
;
216 cmd
->ct_fs_subtype
= sub_type
;
217 cmd
->ct_cmd
= htons(op
);
221 csio_hostname(uint8_t *buf
, size_t buf_len
)
223 if (snprintf(buf
, buf_len
, "%s", init_utsname()->nodename
) > 0)
229 csio_osname(uint8_t *buf
, size_t buf_len
)
231 if (snprintf(buf
, buf_len
, "%s %s %s",
232 init_utsname()->sysname
,
233 init_utsname()->release
,
234 init_utsname()->version
) > 0)
241 csio_append_attrib(uint8_t **ptr
, uint16_t type
, uint8_t *val
, uint16_t len
)
243 struct fc_fdmi_attr_entry
*ae
= (struct fc_fdmi_attr_entry
*)*ptr
;
244 ae
->type
= htons(type
);
245 len
+= 4; /* includes attribute type and length */
246 len
= (len
+ 3) & ~3; /* should be multiple of 4 bytes */
247 ae
->len
= htons(len
);
248 memcpy(ae
->value
, val
, len
);
253 * csio_ln_fdmi_done - FDMI registeration completion
255 * @fdmi_req: fdmi request
258 csio_ln_fdmi_done(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
261 struct csio_lnode
*ln
= fdmi_req
->lnode
;
263 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
264 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rpa cmd\n",
265 fdmi_req
->wr_status
);
266 CSIO_INC_STATS(ln
, n_fdmi_err
);
269 cmd
= fdmi_req
->dma_buf
.vaddr
;
270 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
271 csio_ln_dbg(ln
, "fdmi rpa cmd rejected reason %x expl %x\n",
272 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
277 * csio_ln_fdmi_rhba_cbfn - RHBA completion
279 * @fdmi_req: fdmi request
282 csio_ln_fdmi_rhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
289 uint32_t numattrs
= 0;
290 struct csio_lnode
*ln
= fdmi_req
->lnode
;
291 struct fs_fdmi_attrs
*attrib_blk
;
292 struct fc_fdmi_port_name
*port_name
;
296 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
297 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rhba cmd\n",
298 fdmi_req
->wr_status
);
299 CSIO_INC_STATS(ln
, n_fdmi_err
);
302 cmd
= fdmi_req
->dma_buf
.vaddr
;
303 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
304 csio_ln_dbg(ln
, "fdmi rhba cmd rejected reason %x expl %x\n",
305 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
308 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
309 CSIO_INC_STATS(ln
, n_fdmi_err
);
313 /* Prepare CT hdr for RPA cmd */
314 memset(cmd
, 0, FC_CT_HDR_LEN
);
315 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RPA
);
317 /* Prepare RPA payload */
318 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
319 port_name
= (struct fc_fdmi_port_name
*)pld
;
320 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
321 pld
+= sizeof(*port_name
);
323 /* Start appending Port attributes */
324 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
325 attrib_blk
->numattrs
= 0;
326 len
+= sizeof(attrib_blk
->numattrs
);
327 pld
+= sizeof(attrib_blk
->numattrs
);
330 memset(fc4_type
, 0, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
333 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_FC4TYPES
,
334 fc4_type
, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
336 val
= htonl(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
337 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED
,
339 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
);
342 if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_1G
)
343 val
= htonl(FC_PORTSPEED_1GBIT
);
344 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_10G
)
345 val
= htonl(FC_PORTSPEED_10GBIT
);
347 val
= htonl(CSIO_HBA_PORTSPEED_UNKNOWN
);
348 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED
,
350 FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
);
353 mfs
= ln
->ln_sparm
.csp
.sp_bb_data
;
354 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_MAXFRAMESIZE
,
355 (uint8_t *)&mfs
, FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN
);
358 strcpy(buf
, "csiostor");
359 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_OSDEVICENAME
, buf
,
360 (uint16_t)strlen(buf
));
363 if (!csio_hostname(buf
, sizeof(buf
))) {
364 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_HOSTNAME
,
365 buf
, (uint16_t)strlen(buf
));
368 attrib_blk
->numattrs
= htonl(numattrs
);
369 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
371 /* Submit FDMI RPA request */
372 spin_lock_irq(&hw
->lock
);
373 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_done
,
374 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
375 CSIO_INC_STATS(ln
, n_fdmi_err
);
376 csio_ln_dbg(ln
, "Failed to issue fdmi rpa req\n");
378 spin_unlock_irq(&hw
->lock
);
382 * csio_ln_fdmi_dprt_cbfn - DPRT completion
384 * @fdmi_req: fdmi request
387 csio_ln_fdmi_dprt_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
392 uint32_t numattrs
= 0;
393 __be32 maxpayload
= htonl(65536);
394 struct fc_fdmi_hba_identifier
*hbaid
;
395 struct csio_lnode
*ln
= fdmi_req
->lnode
;
396 struct fc_fdmi_rpl
*reg_pl
;
397 struct fs_fdmi_attrs
*attrib_blk
;
400 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
401 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dprt cmd\n",
402 fdmi_req
->wr_status
);
403 CSIO_INC_STATS(ln
, n_fdmi_err
);
406 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
407 CSIO_INC_STATS(ln
, n_fdmi_err
);
410 cmd
= fdmi_req
->dma_buf
.vaddr
;
411 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
412 csio_ln_dbg(ln
, "fdmi dprt cmd rejected reason %x expl %x\n",
413 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
416 /* Prepare CT hdr for RHBA cmd */
417 memset(cmd
, 0, FC_CT_HDR_LEN
);
418 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RHBA
);
421 /* Prepare RHBA payload */
422 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
423 hbaid
= (struct fc_fdmi_hba_identifier
*)pld
;
424 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8); /* HBA identifer */
425 pld
+= sizeof(*hbaid
);
427 /* Register one port per hba */
428 reg_pl
= (struct fc_fdmi_rpl
*)pld
;
429 reg_pl
->numport
= htonl(1);
430 memcpy(®_pl
->port
[0].portname
, csio_ln_wwpn(ln
), 8);
431 pld
+= sizeof(*reg_pl
);
433 /* Start appending HBA attributes hba */
434 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
435 attrib_blk
->numattrs
= 0;
436 len
+= sizeof(attrib_blk
->numattrs
);
437 pld
+= sizeof(attrib_blk
->numattrs
);
439 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_NODENAME
, csio_ln_wwnn(ln
),
440 FC_FDMI_HBA_ATTR_NODENAME_LEN
);
443 memset(buf
, 0, sizeof(buf
));
445 strcpy(buf
, "Chelsio Communications");
446 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MANUFACTURER
, buf
,
447 (uint16_t)strlen(buf
));
449 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_SERIALNUMBER
,
450 hw
->vpd
.sn
, (uint16_t)sizeof(hw
->vpd
.sn
));
452 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODEL
, hw
->vpd
.id
,
453 (uint16_t)sizeof(hw
->vpd
.id
));
455 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODELDESCRIPTION
,
456 hw
->model_desc
, (uint16_t)strlen(hw
->model_desc
));
458 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_HARDWAREVERSION
,
459 hw
->hw_ver
, (uint16_t)sizeof(hw
->hw_ver
));
461 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_FIRMWAREVERSION
,
462 hw
->fwrev_str
, (uint16_t)strlen(hw
->fwrev_str
));
465 if (!csio_osname(buf
, sizeof(buf
))) {
466 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_OSNAMEVERSION
,
467 buf
, (uint16_t)strlen(buf
));
471 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD
,
472 (uint8_t *)&maxpayload
,
473 FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN
);
474 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
476 attrib_blk
->numattrs
= htonl(numattrs
);
478 /* Submit FDMI RHBA request */
479 spin_lock_irq(&hw
->lock
);
480 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_rhba_cbfn
,
481 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
482 CSIO_INC_STATS(ln
, n_fdmi_err
);
483 csio_ln_dbg(ln
, "Failed to issue fdmi rhba req\n");
485 spin_unlock_irq(&hw
->lock
);
489 * csio_ln_fdmi_dhba_cbfn - DHBA completion
491 * @fdmi_req: fdmi request
494 csio_ln_fdmi_dhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
496 struct csio_lnode
*ln
= fdmi_req
->lnode
;
498 struct fc_fdmi_port_name
*port_name
;
501 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
502 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dhba cmd\n",
503 fdmi_req
->wr_status
);
504 CSIO_INC_STATS(ln
, n_fdmi_err
);
507 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
508 CSIO_INC_STATS(ln
, n_fdmi_err
);
511 cmd
= fdmi_req
->dma_buf
.vaddr
;
512 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
513 csio_ln_dbg(ln
, "fdmi dhba cmd rejected reason %x expl %x\n",
514 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
517 /* Send FDMI cmd to de-register any Port attributes if registered
521 /* Prepare FDMI DPRT cmd */
522 memset(cmd
, 0, FC_CT_HDR_LEN
);
523 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DPRT
);
525 port_name
= (struct fc_fdmi_port_name
*)csio_ct_get_pld(cmd
);
526 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
527 len
+= sizeof(*port_name
);
529 /* Submit FDMI request */
530 spin_lock_irq(&hw
->lock
);
531 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dprt_cbfn
,
532 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
533 CSIO_INC_STATS(ln
, n_fdmi_err
);
534 csio_ln_dbg(ln
, "Failed to issue fdmi dprt req\n");
536 spin_unlock_irq(&hw
->lock
);
540 * csio_ln_fdmi_start - Start an FDMI request.
542 * @context: session context
544 * Issued with lock held.
547 csio_ln_fdmi_start(struct csio_lnode
*ln
, void *context
)
549 struct csio_ioreq
*fdmi_req
;
550 struct csio_rnode
*fdmi_rn
= (struct csio_rnode
*)context
;
552 struct fc_fdmi_hba_identifier
*hbaid
;
555 if (!(ln
->flags
& CSIO_LNF_FDMI_ENABLE
))
556 return -EPROTONOSUPPORT
;
558 if (!csio_is_rnode_ready(fdmi_rn
))
559 CSIO_INC_STATS(ln
, n_fdmi_err
);
561 /* Send FDMI cmd to de-register any HBA attributes if registered
565 fdmi_req
= ln
->mgmt_req
;
566 fdmi_req
->lnode
= ln
;
567 fdmi_req
->rnode
= fdmi_rn
;
569 /* Prepare FDMI DHBA cmd */
570 cmd
= fdmi_req
->dma_buf
.vaddr
;
571 memset(cmd
, 0, FC_CT_HDR_LEN
);
572 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DHBA
);
575 hbaid
= (struct fc_fdmi_hba_identifier
*)csio_ct_get_pld(cmd
);
576 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8);
577 len
+= sizeof(*hbaid
);
579 /* Submit FDMI request */
580 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dhba_cbfn
,
581 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
582 CSIO_INC_STATS(ln
, n_fdmi_err
);
583 csio_ln_dbg(ln
, "Failed to issue fdmi dhba req\n");
590 * csio_ln_vnp_read_cbfn - vnp read completion handler.
592 * @cbfn: Completion handler.
594 * Reads vnp response and updates ln parameters.
597 csio_ln_vnp_read_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
599 struct csio_lnode
*ln
= ((struct csio_lnode
*)mbp
->priv
);
600 struct fw_fcoe_vnp_cmd
*rsp
= (struct fw_fcoe_vnp_cmd
*)(mbp
->mb
);
601 struct fc_els_csp
*csp
;
602 struct fc_els_cssp
*clsp
;
603 enum fw_retval retval
;
606 retval
= FW_CMD_RETVAL_GET(ntohl(rsp
->alloc_to_len16
));
607 if (retval
!= FW_SUCCESS
) {
608 csio_err(hw
, "FCOE VNP read cmd returned error:0x%x\n", retval
);
609 mempool_free(mbp
, hw
->mb_mempool
);
613 spin_lock_irq(&hw
->lock
);
615 memcpy(ln
->mac
, rsp
->vnport_mac
, sizeof(ln
->mac
));
616 memcpy(&nport_id
, &rsp
->vnport_mac
[3], sizeof(uint8_t)*3);
617 ln
->nport_id
= ntohl(nport_id
);
618 ln
->nport_id
= ln
->nport_id
>> 8;
622 * This may look like a duplication of what csio_fcoe_enable_link()
623 * does, but is absolutely necessary if the vnpi changes between
624 * a FCOE LINK UP and FCOE LINK DOWN.
626 memcpy(csio_ln_wwnn(ln
), rsp
->vnport_wwnn
, 8);
627 memcpy(csio_ln_wwpn(ln
), rsp
->vnport_wwpn
, 8);
629 /* Copy common sparam */
630 csp
= (struct fc_els_csp
*)rsp
->cmn_srv_parms
;
631 ln
->ln_sparm
.csp
.sp_hi_ver
= csp
->sp_hi_ver
;
632 ln
->ln_sparm
.csp
.sp_lo_ver
= csp
->sp_lo_ver
;
633 ln
->ln_sparm
.csp
.sp_bb_cred
= csp
->sp_bb_cred
;
634 ln
->ln_sparm
.csp
.sp_features
= csp
->sp_features
;
635 ln
->ln_sparm
.csp
.sp_bb_data
= csp
->sp_bb_data
;
636 ln
->ln_sparm
.csp
.sp_r_a_tov
= csp
->sp_r_a_tov
;
637 ln
->ln_sparm
.csp
.sp_e_d_tov
= csp
->sp_e_d_tov
;
639 /* Copy word 0 & word 1 of class sparam */
640 clsp
= (struct fc_els_cssp
*)rsp
->clsp_word_0_1
;
641 ln
->ln_sparm
.clsp
[2].cp_class
= clsp
->cp_class
;
642 ln
->ln_sparm
.clsp
[2].cp_init
= clsp
->cp_init
;
643 ln
->ln_sparm
.clsp
[2].cp_recip
= clsp
->cp_recip
;
644 ln
->ln_sparm
.clsp
[2].cp_rdfs
= clsp
->cp_rdfs
;
646 spin_unlock_irq(&hw
->lock
);
648 mempool_free(mbp
, hw
->mb_mempool
);
650 /* Send an event to update local attribs */
651 csio_lnode_async_event(ln
, CSIO_LN_FC_ATTRIB_UPDATE
);
655 * csio_ln_vnp_read - Read vnp params.
657 * @cbfn: Completion handler.
659 * Issued with lock held.
662 csio_ln_vnp_read(struct csio_lnode
*ln
,
663 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
665 struct csio_hw
*hw
= ln
->hwp
;
668 /* Allocate Mbox request */
669 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
671 CSIO_INC_STATS(hw
, n_err_nomem
);
675 /* Prepare VNP Command */
676 csio_fcoe_vnp_read_init_mb(ln
, mbp
,
683 if (csio_mb_issue(hw
, mbp
)) {
684 csio_err(hw
, "Failed to issue mbox FCoE VNP command\n");
685 mempool_free(mbp
, hw
->mb_mempool
);
693 * csio_fcoe_enable_link - Enable fcoe link.
695 * @enable: enable/disable
696 * Issued with lock held.
697 * Issues mbox cmd to bring up FCOE link on port associated with given ln.
700 csio_fcoe_enable_link(struct csio_lnode
*ln
, bool enable
)
702 struct csio_hw
*hw
= ln
->hwp
;
704 enum fw_retval retval
;
707 struct fw_fcoe_link_cmd
*lcmd
;
710 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
712 CSIO_INC_STATS(hw
, n_err_nomem
);
717 sub_op
= enable
? FCOE_LINK_UP
: FCOE_LINK_DOWN
;
719 csio_dbg(hw
, "bringing FCOE LINK %s on Port:%d\n",
720 sub_op
? "UP" : "DOWN", portid
);
722 csio_write_fcoe_link_cond_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
723 portid
, sub_op
, 0, 0, 0, NULL
);
725 if (csio_mb_issue(hw
, mbp
)) {
726 csio_err(hw
, "failed to issue FCOE LINK cmd on port[%d]\n",
728 mempool_free(mbp
, hw
->mb_mempool
);
732 retval
= csio_mb_fw_retval(mbp
);
733 if (retval
!= FW_SUCCESS
) {
735 "FCOE LINK %s cmd on port[%d] failed with "
736 "ret:x%x\n", sub_op
? "UP" : "DOWN", portid
, retval
);
737 mempool_free(mbp
, hw
->mb_mempool
);
744 lcmd
= (struct fw_fcoe_link_cmd
*)mbp
->mb
;
746 memcpy(csio_ln_wwnn(ln
), lcmd
->vnport_wwnn
, 8);
747 memcpy(csio_ln_wwpn(ln
), lcmd
->vnport_wwpn
, 8);
749 for (i
= 0; i
< CSIO_MAX_PPORTS
; i
++)
750 if (hw
->pport
[i
].portid
== portid
)
751 memcpy(hw
->pport
[i
].mac
, lcmd
->phy_mac
, 6);
754 mempool_free(mbp
, hw
->mb_mempool
);
759 * csio_ln_read_fcf_cbfn - Read fcf parameters
762 * read fcf response and Update ln fcf information.
765 csio_ln_read_fcf_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
767 struct csio_lnode
*ln
= (struct csio_lnode
*)mbp
->priv
;
768 struct csio_fcf_info
*fcf_info
;
769 struct fw_fcoe_fcf_cmd
*rsp
=
770 (struct fw_fcoe_fcf_cmd
*)(mbp
->mb
);
771 enum fw_retval retval
;
773 retval
= FW_CMD_RETVAL_GET(ntohl(rsp
->retval_len16
));
774 if (retval
!= FW_SUCCESS
) {
775 csio_ln_err(ln
, "FCOE FCF cmd failed with ret x%x\n",
777 mempool_free(mbp
, hw
->mb_mempool
);
781 spin_lock_irq(&hw
->lock
);
782 fcf_info
= ln
->fcfinfo
;
783 fcf_info
->priority
= FW_FCOE_FCF_CMD_PRIORITY_GET(
784 ntohs(rsp
->priority_pkd
));
785 fcf_info
->vf_id
= ntohs(rsp
->vf_id
);
786 fcf_info
->vlan_id
= rsp
->vlan_id
;
787 fcf_info
->max_fcoe_size
= ntohs(rsp
->max_fcoe_size
);
788 fcf_info
->fka_adv
= be32_to_cpu(rsp
->fka_adv
);
789 fcf_info
->fcfi
= FW_FCOE_FCF_CMD_FCFI_GET(ntohl(rsp
->op_to_fcfi
));
790 fcf_info
->fpma
= FW_FCOE_FCF_CMD_FPMA_GET(rsp
->fpma_to_portid
);
791 fcf_info
->spma
= FW_FCOE_FCF_CMD_SPMA_GET(rsp
->fpma_to_portid
);
792 fcf_info
->login
= FW_FCOE_FCF_CMD_LOGIN_GET(rsp
->fpma_to_portid
);
793 fcf_info
->portid
= FW_FCOE_FCF_CMD_PORTID_GET(rsp
->fpma_to_portid
);
794 memcpy(fcf_info
->fc_map
, rsp
->fc_map
, sizeof(fcf_info
->fc_map
));
795 memcpy(fcf_info
->mac
, rsp
->mac
, sizeof(fcf_info
->mac
));
796 memcpy(fcf_info
->name_id
, rsp
->name_id
, sizeof(fcf_info
->name_id
));
797 memcpy(fcf_info
->fabric
, rsp
->fabric
, sizeof(fcf_info
->fabric
));
798 memcpy(fcf_info
->spma_mac
, rsp
->spma_mac
, sizeof(fcf_info
->spma_mac
));
800 spin_unlock_irq(&hw
->lock
);
802 mempool_free(mbp
, hw
->mb_mempool
);
806 * csio_ln_read_fcf_entry - Read fcf entry.
808 * @cbfn: Completion handler.
810 * Issued with lock held.
813 csio_ln_read_fcf_entry(struct csio_lnode
*ln
,
814 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
816 struct csio_hw
*hw
= ln
->hwp
;
819 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
821 CSIO_INC_STATS(hw
, n_err_nomem
);
825 /* Get FCoE FCF information */
826 csio_fcoe_read_fcf_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
827 ln
->portid
, ln
->fcf_flowid
, cbfn
);
829 if (csio_mb_issue(hw
, mbp
)) {
830 csio_err(hw
, "failed to issue FCOE FCF cmd\n");
831 mempool_free(mbp
, hw
->mb_mempool
);
839 * csio_handle_link_up - Logical Linkup event.
841 * @portid - Physical port number
846 * This event is received from FW, when virtual link is established between
847 * Physical port[ENode] and FCF. If its new vnpi, then local node object is
848 * created on this FCF and set to [ONLINE] state.
849 * Lnode waits for FW_RDEV_CMD event to be received indicating that
850 * Fabric login is completed and lnode moves to [READY] state.
852 * This called with hw lock held
855 csio_handle_link_up(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
858 struct csio_lnode
*ln
= NULL
;
860 /* Lookup lnode based on vnpi */
861 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
863 /* Pick lnode based on portid */
864 ln
= csio_ln_lookup_by_portid(hw
, portid
);
866 csio_err(hw
, "failed to lookup fcoe lnode on port:%d\n",
872 /* Check if lnode has valid vnp flowid */
873 if (ln
->vnp_flowid
!= CSIO_INVALID_IDX
) {
875 spin_unlock_irq(&hw
->lock
);
876 csio_lnode_alloc(hw
);
877 spin_lock_irq(&hw
->lock
);
880 "failed to allocate fcoe lnode"
881 "for port:%d vnpi:x%x\n",
888 ln
->vnp_flowid
= vnpi
;
889 ln
->dev_num
&= ~0xFFFF;
894 ln
->fcf_flowid
= fcfi
;
896 csio_info(hw
, "Port:%d - FCOE LINK UP\n", portid
);
898 CSIO_INC_STATS(ln
, n_link_up
);
900 /* Send LINKUP event to SM */
901 csio_post_event(&ln
->sm
, CSIO_LNE_LINKUP
);
905 * csio_post_event_rns
907 * @evt - Given rnode event
910 * Posts given rnode event to all FCOE rnodes connected with given Lnode.
911 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
914 * This called with hw lock held
917 csio_post_event_rns(struct csio_lnode
*ln
, enum csio_rn_ev evt
)
919 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
920 struct list_head
*tmp
, *next
;
921 struct csio_rnode
*rn
;
923 list_for_each_safe(tmp
, next
, &rnhead
->sm
.sm_list
) {
924 rn
= (struct csio_rnode
*) tmp
;
925 csio_post_event(&rn
->sm
, evt
);
934 * Frees all FCOE rnodes connected with given Lnode.
936 * This called with hw lock held
939 csio_cleanup_rns(struct csio_lnode
*ln
)
941 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
942 struct list_head
*tmp
, *next_rn
;
943 struct csio_rnode
*rn
;
945 list_for_each_safe(tmp
, next_rn
, &rnhead
->sm
.sm_list
) {
946 rn
= (struct csio_rnode
*) tmp
;
947 csio_put_rnode(ln
, rn
);
953 * csio_post_event_lns
955 * @evt - Given lnode event
958 * Posts given lnode event to all FCOE lnodes connected with given Lnode.
959 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
962 * This called with hw lock held
965 csio_post_event_lns(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
967 struct list_head
*tmp
;
968 struct csio_lnode
*cln
, *sln
;
970 /* If NPIV lnode, send evt only to that and return */
971 if (csio_is_npiv_ln(ln
)) {
972 csio_post_event(&ln
->sm
, evt
);
977 /* Traverse children lnodes list and send evt */
978 list_for_each(tmp
, &sln
->cln_head
) {
979 cln
= (struct csio_lnode
*) tmp
;
980 csio_post_event(&cln
->sm
, evt
);
983 /* Send evt to parent lnode */
984 csio_post_event(&ln
->sm
, evt
);
988 * csio_ln_down - Lcoal nport is down
992 * Sends LINK_DOWN events to Lnode and its associated NPIVs lnodes.
994 * This called with hw lock held
997 csio_ln_down(struct csio_lnode
*ln
)
999 csio_post_event_lns(ln
, CSIO_LNE_LINK_DOWN
);
1003 * csio_handle_link_down - Logical Linkdown event.
1005 * @portid - Physical port number
1006 * @fcfi - FCF index.
1007 * @vnpi - VNP index.
1010 * This event is received from FW, when virtual link goes down between
1011 * Physical port[ENode] and FCF. Lnode and its associated NPIVs lnode hosted on
1012 * this vnpi[VN-Port] will be de-instantiated.
1014 * This called with hw lock held
1017 csio_handle_link_down(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
1020 struct csio_fcf_info
*fp
;
1021 struct csio_lnode
*ln
;
1023 /* Lookup lnode based on vnpi */
1024 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1027 CSIO_INC_STATS(ln
, n_link_down
);
1029 /*Warn if linkdown received if lnode is not in ready state */
1030 if (!csio_is_lnode_ready(ln
)) {
1032 "warn: FCOE link is already in offline "
1033 "Ignoring Fcoe linkdown event on portid %d\n",
1035 CSIO_INC_STATS(ln
, n_evt_drop
);
1040 if (fp
->portid
!= portid
) {
1042 "warn: FCOE linkdown recv with "
1043 "invalid port %d\n", portid
);
1044 CSIO_INC_STATS(ln
, n_evt_drop
);
1049 if (ln
->fcf_flowid
!= fcfi
) {
1051 "warn: FCOE linkdown recv with "
1052 "invalid fcfi x%x\n", fcfi
);
1053 CSIO_INC_STATS(ln
, n_evt_drop
);
1057 csio_info(hw
, "Port:%d - FCOE LINK DOWN\n", portid
);
1059 /* Send LINK_DOWN event to lnode s/m */
1065 "warn: FCOE linkdown recv with invalid vnpi x%x\n",
1067 CSIO_INC_STATS(hw
, n_evt_drop
);
1072 * csio_is_lnode_ready - Checks FCOE lnode is in ready state.
1075 * Returns True if FCOE lnode is in ready state.
1078 csio_is_lnode_ready(struct csio_lnode
*ln
)
1080 return (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
));
1083 /*****************************************************************************/
1084 /* START: Lnode SM */
1085 /*****************************************************************************/
1087 * csio_lns_uninit - The request in uninit state.
1089 * @evt - Event to be processed.
1091 * Process the given lnode event which is currently in "uninit" state.
1092 * Invoked with HW lock held.
1096 csio_lns_uninit(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1098 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1099 struct csio_lnode
*rln
= hw
->rln
;
1102 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1104 case CSIO_LNE_LINKUP
:
1105 csio_set_state(&ln
->sm
, csio_lns_online
);
1106 /* Read FCF only for physical lnode */
1107 if (csio_is_phys_ln(ln
)) {
1108 rv
= csio_ln_read_fcf_entry(ln
,
1109 csio_ln_read_fcf_cbfn
);
1111 /* TODO: Send HW RESET event */
1112 CSIO_INC_STATS(ln
, n_err
);
1116 /* Add FCF record */
1117 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1120 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1122 /* TODO: Send HW RESET event */
1123 CSIO_INC_STATS(ln
, n_err
);
1127 case CSIO_LNE_DOWN_LINK
:
1132 "unexp ln event %d recv from did:x%x in "
1133 "ln state[uninit].\n", evt
, ln
->nport_id
);
1134 CSIO_INC_STATS(ln
, n_evt_unexp
);
1136 } /* switch event */
1140 * csio_lns_online - The request in online state.
1142 * @evt - Event to be processed.
1144 * Process the given lnode event which is currently in "online" state.
1145 * Invoked with HW lock held.
1149 csio_lns_online(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1151 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1153 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1155 case CSIO_LNE_LINKUP
:
1157 "warn: FCOE link is up already "
1158 "Ignoring linkup on port:%d\n", ln
->portid
);
1159 CSIO_INC_STATS(ln
, n_evt_drop
);
1162 case CSIO_LNE_FAB_INIT_DONE
:
1163 csio_set_state(&ln
->sm
, csio_lns_ready
);
1165 spin_unlock_irq(&hw
->lock
);
1166 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKUP
);
1167 spin_lock_irq(&hw
->lock
);
1171 case CSIO_LNE_LINK_DOWN
:
1173 case CSIO_LNE_DOWN_LINK
:
1174 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1175 if (csio_is_phys_ln(ln
)) {
1176 /* Remove FCF entry */
1177 list_del_init(&ln
->fcfinfo
->list
);
1183 "unexp ln event %d recv from did:x%x in "
1184 "ln state[uninit].\n", evt
, ln
->nport_id
);
1185 CSIO_INC_STATS(ln
, n_evt_unexp
);
1188 } /* switch event */
1192 * csio_lns_ready - The request in ready state.
1194 * @evt - Event to be processed.
1196 * Process the given lnode event which is currently in "ready" state.
1197 * Invoked with HW lock held.
1201 csio_lns_ready(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1203 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1205 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1207 case CSIO_LNE_FAB_INIT_DONE
:
1209 "ignoring event %d recv from did x%x"
1210 "in ln state[ready].\n", evt
, ln
->nport_id
);
1211 CSIO_INC_STATS(ln
, n_evt_drop
);
1214 case CSIO_LNE_LINK_DOWN
:
1215 csio_set_state(&ln
->sm
, csio_lns_offline
);
1216 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1218 spin_unlock_irq(&hw
->lock
);
1219 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1220 spin_lock_irq(&hw
->lock
);
1222 if (csio_is_phys_ln(ln
)) {
1223 /* Remove FCF entry */
1224 list_del_init(&ln
->fcfinfo
->list
);
1228 case CSIO_LNE_DOWN_LINK
:
1229 csio_set_state(&ln
->sm
, csio_lns_offline
);
1230 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1232 /* Host need to issue aborts in case if FW has not returned
1233 * WRs with status "ABORTED"
1235 spin_unlock_irq(&hw
->lock
);
1236 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1237 spin_lock_irq(&hw
->lock
);
1239 if (csio_is_phys_ln(ln
)) {
1240 /* Remove FCF entry */
1241 list_del_init(&ln
->fcfinfo
->list
);
1245 case CSIO_LNE_CLOSE
:
1246 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1247 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1251 csio_set_state(&ln
->sm
, csio_lns_offline
);
1252 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1257 "unexp ln event %d recv from did:x%x in "
1258 "ln state[uninit].\n", evt
, ln
->nport_id
);
1259 CSIO_INC_STATS(ln
, n_evt_unexp
);
1262 } /* switch event */
1266 * csio_lns_offline - The request in offline state.
1268 * @evt - Event to be processed.
1270 * Process the given lnode event which is currently in "offline" state.
1271 * Invoked with HW lock held.
1275 csio_lns_offline(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1277 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1278 struct csio_lnode
*rln
= hw
->rln
;
1281 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1283 case CSIO_LNE_LINKUP
:
1284 csio_set_state(&ln
->sm
, csio_lns_online
);
1285 /* Read FCF only for physical lnode */
1286 if (csio_is_phys_ln(ln
)) {
1287 rv
= csio_ln_read_fcf_entry(ln
,
1288 csio_ln_read_fcf_cbfn
);
1290 /* TODO: Send HW RESET event */
1291 CSIO_INC_STATS(ln
, n_err
);
1295 /* Add FCF record */
1296 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1299 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1301 /* TODO: Send HW RESET event */
1302 CSIO_INC_STATS(ln
, n_err
);
1306 case CSIO_LNE_LINK_DOWN
:
1307 case CSIO_LNE_DOWN_LINK
:
1310 "ignoring event %d recv from did x%x"
1311 "in ln state[offline].\n", evt
, ln
->nport_id
);
1312 CSIO_INC_STATS(ln
, n_evt_drop
);
1315 case CSIO_LNE_CLOSE
:
1316 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1317 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1322 "unexp ln event %d recv from did:x%x in "
1323 "ln state[offline]\n", evt
, ln
->nport_id
);
1324 CSIO_INC_STATS(ln
, n_evt_unexp
);
1327 } /* switch event */
1330 /*****************************************************************************/
1332 /*****************************************************************************/
1335 csio_free_fcfinfo(struct kref
*kref
)
1337 struct csio_fcf_info
*fcfinfo
= container_of(kref
,
1338 struct csio_fcf_info
, kref
);
1342 /* Helper routines for attributes */
1344 * csio_lnode_state_to_str - Get current state of FCOE lnode.
1346 * @str - state of lnode.
1350 csio_lnode_state_to_str(struct csio_lnode
*ln
, int8_t *str
)
1352 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_uninit
)) {
1353 strcpy(str
, "UNINIT");
1356 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
)) {
1357 strcpy(str
, "READY");
1360 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_offline
)) {
1361 strcpy(str
, "OFFLINE");
1364 strcpy(str
, "UNKNOWN");
1365 } /* csio_lnode_state_to_str */
1369 csio_get_phy_port_stats(struct csio_hw
*hw
, uint8_t portid
,
1370 struct fw_fcoe_port_stats
*port_stats
)
1372 struct csio_mb
*mbp
;
1373 struct fw_fcoe_port_cmd_params portparams
;
1374 enum fw_retval retval
;
1377 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
1379 csio_err(hw
, "FCoE FCF PARAMS command out of memory!\n");
1382 portparams
.portid
= portid
;
1384 for (idx
= 1; idx
<= 3; idx
++) {
1385 portparams
.idx
= (idx
-1)*6 + 1;
1386 portparams
.nstats
= 6;
1388 portparams
.nstats
= 4;
1389 csio_fcoe_read_portparams_init_mb(hw
, mbp
, CSIO_MB_DEFAULT_TMO
,
1391 if (csio_mb_issue(hw
, mbp
)) {
1392 csio_err(hw
, "Issue of FCoE port params failed!\n");
1393 mempool_free(mbp
, hw
->mb_mempool
);
1396 csio_mb_process_portparams_rsp(hw
, mbp
, &retval
,
1397 &portparams
, port_stats
);
1400 mempool_free(mbp
, hw
->mb_mempool
);
1405 * csio_ln_mgmt_wr_handler -Mgmt Work Request handler.
1408 * This handler is invoked when an outstanding mgmt WR is completed.
1409 * Its invoked in the context of FW event worker thread for every
1410 * mgmt event received.
1415 csio_ln_mgmt_wr_handler(struct csio_hw
*hw
, void *wr
, uint32_t len
)
1417 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1418 struct csio_ioreq
*io_req
= NULL
;
1419 struct fw_fcoe_els_ct_wr
*wr_cmd
;
1422 wr_cmd
= (struct fw_fcoe_els_ct_wr
*) wr
;
1424 if (len
< sizeof(struct fw_fcoe_els_ct_wr
)) {
1426 "Invalid ELS CT WR length recvd, len:%x\n", len
);
1427 mgmtm
->stats
.n_err
++;
1431 io_req
= (struct csio_ioreq
*) ((uintptr_t) wr_cmd
->cookie
);
1432 io_req
->wr_status
= csio_wr_status(wr_cmd
);
1434 /* lookup ioreq exists in our active Q */
1435 spin_lock_irq(&hw
->lock
);
1436 if (csio_mgmt_req_lookup(mgmtm
, io_req
) != 0) {
1438 "Error- Invalid IO handle recv in WR. handle: %p\n",
1440 mgmtm
->stats
.n_err
++;
1441 spin_unlock_irq(&hw
->lock
);
1445 mgmtm
= csio_hw_to_mgmtm(hw
);
1447 /* Dequeue from active queue */
1448 list_del_init(&io_req
->sm
.sm_list
);
1449 mgmtm
->stats
.n_active
--;
1450 spin_unlock_irq(&hw
->lock
);
1452 /* io_req will be freed by completion handler */
1453 if (io_req
->io_cbfn
)
1454 io_req
->io_cbfn(hw
, io_req
);
1458 * csio_fcoe_fwevt_handler - Event handler for Firmware FCoE events.
1460 * @cpl_op: CPL opcode
1463 * Process received FCoE cmd/WR event from FW.
1466 csio_fcoe_fwevt_handler(struct csio_hw
*hw
, __u8 cpl_op
, __be64
*cmd
)
1468 struct csio_lnode
*ln
;
1469 struct csio_rnode
*rn
;
1470 uint8_t portid
, opcode
= *(uint8_t *)cmd
;
1471 struct fw_fcoe_link_cmd
*lcmd
;
1472 struct fw_wr_hdr
*wr
;
1473 struct fw_rdev_wr
*rdev_wr
;
1474 enum fw_fcoe_link_status lstatus
;
1475 uint32_t fcfi
, rdev_flowid
, vnpi
;
1476 enum csio_ln_ev evt
;
1478 if (cpl_op
== CPL_FW6_MSG
&& opcode
== FW_FCOE_LINK_CMD
) {
1480 lcmd
= (struct fw_fcoe_link_cmd
*)cmd
;
1481 lstatus
= lcmd
->lstatus
;
1482 portid
= FW_FCOE_LINK_CMD_PORTID_GET(
1483 ntohl(lcmd
->op_to_portid
));
1484 fcfi
= FW_FCOE_LINK_CMD_FCFI_GET(ntohl(lcmd
->sub_opcode_fcfi
));
1485 vnpi
= FW_FCOE_LINK_CMD_VNPI_GET(ntohl(lcmd
->vnpi_pkd
));
1487 if (lstatus
== FCOE_LINKUP
) {
1490 spin_lock_irq(&hw
->lock
);
1491 csio_handle_link_up(hw
, portid
, fcfi
, vnpi
);
1492 spin_unlock_irq(&hw
->lock
);
1493 /* HW un lock here */
1495 } else if (lstatus
== FCOE_LINKDOWN
) {
1498 spin_lock_irq(&hw
->lock
);
1499 csio_handle_link_down(hw
, portid
, fcfi
, vnpi
);
1500 spin_unlock_irq(&hw
->lock
);
1501 /* HW un lock here */
1503 csio_warn(hw
, "Unexpected FCOE LINK status:0x%x\n",
1505 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1507 } else if (cpl_op
== CPL_FW6_PLD
) {
1508 wr
= (struct fw_wr_hdr
*) (cmd
+ 4);
1509 if (FW_WR_OP_GET(be32_to_cpu(wr
->hi
))
1512 rdev_wr
= (struct fw_rdev_wr
*) (cmd
+ 4);
1514 rdev_flowid
= FW_RDEV_WR_FLOWID_GET(
1515 ntohl(rdev_wr
->alloc_to_len16
));
1516 vnpi
= FW_RDEV_WR_ASSOC_FLOWID_GET(
1517 ntohl(rdev_wr
->flags_to_assoc_flowid
));
1520 "FW_RDEV_WR: flowid:x%x ev_cause:x%x "
1521 "vnpi:0x%x\n", rdev_flowid
,
1522 rdev_wr
->event_cause
, vnpi
);
1524 if (rdev_wr
->protocol
!= PROT_FCOE
) {
1526 "FW_RDEV_WR: invalid proto:x%x "
1527 "received with flowid:x%x\n",
1530 CSIO_INC_STATS(hw
, n_evt_drop
);
1535 spin_lock_irq(&hw
->lock
);
1536 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1539 "FW_DEV_WR: invalid vnpi:x%x received "
1540 "with flowid:x%x\n", vnpi
, rdev_flowid
);
1541 CSIO_INC_STATS(hw
, n_evt_drop
);
1545 rn
= csio_confirm_rnode(ln
, rdev_flowid
,
1546 &rdev_wr
->u
.fcoe_rdev
);
1549 "Failed to confirm rnode "
1550 "for flowid:x%x\n", rdev_flowid
);
1551 CSIO_INC_STATS(hw
, n_evt_drop
);
1555 /* save previous event for debugging */
1556 ln
->prev_evt
= ln
->cur_evt
;
1557 ln
->cur_evt
= rdev_wr
->event_cause
;
1558 CSIO_INC_STATS(ln
, n_evt_fw
[rdev_wr
->event_cause
]);
1560 /* Translate all the fabric events to lnode SM events */
1561 evt
= CSIO_FWE_TO_LNE(rdev_wr
->event_cause
);
1564 "Posting event to lnode event:%d "
1565 "cause:%d flowid:x%x\n", evt
,
1566 rdev_wr
->event_cause
, rdev_flowid
);
1567 csio_post_event(&ln
->sm
, evt
);
1570 /* Handover event to rn SM here. */
1571 csio_rnode_fwevt_handler(rn
, rdev_wr
->event_cause
);
1573 spin_unlock_irq(&hw
->lock
);
1576 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1577 FW_WR_OP_GET(be32_to_cpu((wr
->hi
))));
1578 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1580 } else if (cpl_op
== CPL_FW6_MSG
) {
1581 wr
= (struct fw_wr_hdr
*) (cmd
);
1582 if (FW_WR_OP_GET(be32_to_cpu(wr
->hi
)) == FW_FCOE_ELS_CT_WR
) {
1583 csio_ln_mgmt_wr_handler(hw
, wr
,
1584 sizeof(struct fw_fcoe_els_ct_wr
));
1586 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1587 FW_WR_OP_GET(be32_to_cpu((wr
->hi
))));
1588 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1591 csio_warn(hw
, "unexpected CPL op(0x%x) recv\n", opcode
);
1592 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1597 * csio_lnode_start - Kickstart lnode discovery.
1600 * This routine kickstarts the discovery by issuing an FCOE_LINK (up) command.
1603 csio_lnode_start(struct csio_lnode
*ln
)
1606 if (csio_is_phys_ln(ln
) && !(ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1607 rv
= csio_fcoe_enable_link(ln
, 1);
1608 ln
->flags
|= CSIO_LNF_LINK_ENABLE
;
1615 * csio_lnode_stop - Stop the lnode.
1618 * This routine is invoked by HW module to stop lnode and its associated NPIV
1622 csio_lnode_stop(struct csio_lnode
*ln
)
1624 csio_post_event_lns(ln
, CSIO_LNE_DOWN_LINK
);
1625 if (csio_is_phys_ln(ln
) && (ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1626 csio_fcoe_enable_link(ln
, 0);
1627 ln
->flags
&= ~CSIO_LNF_LINK_ENABLE
;
1629 csio_ln_dbg(ln
, "stopping ln :%p\n", ln
);
1633 * csio_lnode_close - Close an lnode.
1636 * This routine is invoked by HW module to close an lnode and its
1637 * associated NPIV lnodes. Lnode and its associated NPIV lnodes are
1638 * set to uninitialized state.
1641 csio_lnode_close(struct csio_lnode
*ln
)
1643 csio_post_event_lns(ln
, CSIO_LNE_CLOSE
);
1644 if (csio_is_phys_ln(ln
))
1645 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1647 csio_ln_dbg(ln
, "closed ln :%p\n", ln
);
1651 * csio_ln_prep_ecwr - Prepare ELS/CT WR.
1652 * @io_req - IO request.
1654 * @immd_len - WR immediate data
1655 * @sub_op - Sub opcode
1656 * @sid - source portid.
1657 * @did - destination portid
1659 * @fw_wr - ELS/CT WR to be prepared.
1660 * Returns: 0 - on success
1663 csio_ln_prep_ecwr(struct csio_ioreq
*io_req
, uint32_t wr_len
,
1664 uint32_t immd_len
, uint8_t sub_op
, uint32_t sid
,
1665 uint32_t did
, uint32_t flow_id
, uint8_t *fw_wr
)
1667 struct fw_fcoe_els_ct_wr
*wr
;
1670 wr
= (struct fw_fcoe_els_ct_wr
*)fw_wr
;
1671 wr
->op_immdlen
= cpu_to_be32(FW_WR_OP(FW_FCOE_ELS_CT_WR
) |
1672 FW_FCOE_ELS_CT_WR_IMMDLEN(immd_len
));
1674 wr_len
= DIV_ROUND_UP(wr_len
, 16);
1675 wr
->flowid_len16
= cpu_to_be32(FW_WR_FLOWID(flow_id
) |
1676 FW_WR_LEN16(wr_len
));
1677 wr
->els_ct_type
= sub_op
;
1679 wr
->cp_en_class
= 0;
1680 wr
->cookie
= io_req
->fw_handle
;
1681 wr
->iqid
= cpu_to_be16(csio_q_physiqid(
1682 io_req
->lnode
->hwp
, io_req
->iq_idx
));
1683 wr
->fl_to_sp
= FW_FCOE_ELS_CT_WR_SP(1);
1684 wr
->tmo_val
= (uint8_t) io_req
->tmo
;
1685 port_id
= htonl(sid
);
1686 memcpy(wr
->l_id
, PORT_ID_PTR(port_id
), 3);
1687 port_id
= htonl(did
);
1688 memcpy(wr
->r_id
, PORT_ID_PTR(port_id
), 3);
1690 /* Prepare RSP SGL */
1691 wr
->rsp_dmalen
= cpu_to_be32(io_req
->dma_buf
.len
);
1692 wr
->rsp_dmaaddr
= cpu_to_be64(io_req
->dma_buf
.paddr
);
1697 * csio_ln_mgmt_submit_wr - Post elsct work request.
1699 * @io_req - io request.
1700 * @sub_op - ELS or CT request type
1701 * @pld - Dma Payload buffer
1702 * @pld_len - Payload len
1703 * Prepares ELSCT Work request and sents it to FW.
1704 * Returns: 0 - on success
1707 csio_ln_mgmt_submit_wr(struct csio_mgmtm
*mgmtm
, struct csio_ioreq
*io_req
,
1708 uint8_t sub_op
, struct csio_dma_buf
*pld
,
1711 struct csio_wr_pair wrp
;
1712 struct csio_lnode
*ln
= io_req
->lnode
;
1713 struct csio_rnode
*rn
= io_req
->rnode
;
1714 struct csio_hw
*hw
= mgmtm
->hw
;
1716 struct ulptx_sgl dsgl
;
1717 uint32_t wr_size
= 0;
1719 uint32_t wr_off
= 0;
1723 /* Calculate WR Size for this ELS REQ */
1724 wr_size
= sizeof(struct fw_fcoe_els_ct_wr
);
1726 /* Send as immediate data if pld < 256 */
1727 if (pld_len
< 256) {
1728 wr_size
+= ALIGN(pld_len
, 8);
1729 im_len
= (uint8_t)pld_len
;
1731 wr_size
+= sizeof(struct ulptx_sgl
);
1733 /* Roundup WR size in units of 16 bytes */
1734 wr_size
= ALIGN(wr_size
, 16);
1736 /* Get WR to send ELS REQ */
1737 ret
= csio_wr_get(hw
, mgmtm
->eq_idx
, wr_size
, &wrp
);
1739 csio_err(hw
, "Failed to get WR for ec_req %p ret:%d\n",
1744 /* Prepare Generic WR used by all ELS/CT cmd */
1745 csio_ln_prep_ecwr(io_req
, wr_size
, im_len
, sub_op
,
1746 ln
->nport_id
, rn
->nport_id
,
1750 /* Copy ELS/CT WR CMD */
1751 csio_wr_copy_to_wrp(&fw_wr
[0], &wrp
, wr_off
,
1752 sizeof(struct fw_fcoe_els_ct_wr
));
1753 wr_off
+= sizeof(struct fw_fcoe_els_ct_wr
);
1755 /* Copy payload to Immediate section of WR */
1757 csio_wr_copy_to_wrp(pld
->vaddr
, &wrp
, wr_off
, im_len
);
1759 /* Program DSGL to dma payload */
1760 dsgl
.cmd_nsge
= htonl(ULPTX_CMD(ULP_TX_SC_DSGL
) |
1761 ULPTX_MORE
| ULPTX_NSGE(1));
1762 dsgl
.len0
= cpu_to_be32(pld_len
);
1763 dsgl
.addr0
= cpu_to_be64(pld
->paddr
);
1764 csio_wr_copy_to_wrp(&dsgl
, &wrp
, ALIGN(wr_off
, 8),
1765 sizeof(struct ulptx_sgl
));
1768 /* Issue work request to xmit ELS/CT req to FW */
1769 csio_wr_issue(mgmtm
->hw
, mgmtm
->eq_idx
, false);
1774 * csio_ln_mgmt_submit_req - Submit FCOE Mgmt request.
1775 * @io_req - IO Request
1776 * @io_cbfn - Completion handler.
1777 * @req_type - ELS or CT request type
1778 * @pld - Dma Payload buffer
1779 * @pld_len - Payload len
1782 * This API used submit managment ELS/CT request.
1783 * This called with hw lock held
1784 * Returns: 0 - on success
1785 * -ENOMEM - on error.
1788 csio_ln_mgmt_submit_req(struct csio_ioreq
*io_req
,
1789 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
1790 enum fcoe_cmn_type req_type
, struct csio_dma_buf
*pld
,
1793 struct csio_hw
*hw
= csio_lnode_to_hw(io_req
->lnode
);
1794 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1797 io_req
->io_cbfn
= io_cbfn
; /* Upper layer callback handler */
1798 io_req
->fw_handle
= (uintptr_t) (io_req
);
1799 io_req
->eq_idx
= mgmtm
->eq_idx
;
1800 io_req
->iq_idx
= mgmtm
->iq_idx
;
1802 rv
= csio_ln_mgmt_submit_wr(mgmtm
, io_req
, req_type
, pld
, pld_len
);
1804 list_add_tail(&io_req
->sm
.sm_list
, &mgmtm
->active_q
);
1805 mgmtm
->stats
.n_active
++;
1811 * csio_ln_fdmi_init - FDMI Init entry point.
1815 csio_ln_fdmi_init(struct csio_lnode
*ln
)
1817 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1818 struct csio_dma_buf
*dma_buf
;
1820 /* Allocate MGMT request required for FDMI */
1821 ln
->mgmt_req
= kzalloc(sizeof(struct csio_ioreq
), GFP_KERNEL
);
1822 if (!ln
->mgmt_req
) {
1823 csio_ln_err(ln
, "Failed to alloc ioreq for FDMI\n");
1824 CSIO_INC_STATS(hw
, n_err_nomem
);
1828 /* Allocate Dma buffers for FDMI response Payload */
1829 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1830 dma_buf
->len
= 2048;
1831 dma_buf
->vaddr
= pci_alloc_consistent(hw
->pdev
, dma_buf
->len
,
1833 if (!dma_buf
->vaddr
) {
1834 csio_err(hw
, "Failed to alloc DMA buffer for FDMI!\n");
1835 kfree(ln
->mgmt_req
);
1836 ln
->mgmt_req
= NULL
;
1840 ln
->flags
|= CSIO_LNF_FDMI_ENABLE
;
1845 * csio_ln_fdmi_exit - FDMI exit entry point.
1849 csio_ln_fdmi_exit(struct csio_lnode
*ln
)
1851 struct csio_dma_buf
*dma_buf
;
1852 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1857 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1859 pci_free_consistent(hw
->pdev
, dma_buf
->len
, dma_buf
->vaddr
,
1862 kfree(ln
->mgmt_req
);
1867 csio_scan_done(struct csio_lnode
*ln
, unsigned long ticks
,
1868 unsigned long time
, unsigned long max_scan_ticks
,
1869 unsigned long delta_scan_ticks
)
1873 if (time
>= max_scan_ticks
)
1876 if (!ln
->tgt_scan_tick
)
1877 ln
->tgt_scan_tick
= ticks
;
1879 if (((ticks
- ln
->tgt_scan_tick
) >= delta_scan_ticks
)) {
1880 if (!ln
->last_scan_ntgts
)
1881 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1883 if (ln
->last_scan_ntgts
== ln
->n_scsi_tgts
)
1886 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1888 ln
->tgt_scan_tick
= ticks
;
1894 * csio_notify_lnodes:
1896 * @note: Notification
1898 * Called from the HW SM to fan out notifications to the
1899 * Lnode SM. Since the HW SM is entered with lock held,
1900 * there is no need to hold locks here.
1904 csio_notify_lnodes(struct csio_hw
*hw
, enum csio_ln_notify note
)
1906 struct list_head
*tmp
;
1907 struct csio_lnode
*ln
;
1909 csio_dbg(hw
, "Notifying all nodes of event %d\n", note
);
1911 /* Traverse children lnodes list and send evt */
1912 list_for_each(tmp
, &hw
->sln_head
) {
1913 ln
= (struct csio_lnode
*) tmp
;
1916 case CSIO_LN_NOTIFY_HWREADY
:
1917 csio_lnode_start(ln
);
1920 case CSIO_LN_NOTIFY_HWRESET
:
1921 case CSIO_LN_NOTIFY_HWREMOVE
:
1922 csio_lnode_close(ln
);
1925 case CSIO_LN_NOTIFY_HWSTOP
:
1926 csio_lnode_stop(ln
);
1937 * csio_disable_lnodes:
1940 * @disable: disable/enable flag.
1941 * If disable=1, disables all lnode hosted on given physical port.
1942 * otherwise enables all the lnodes on given phsysical port.
1943 * This routine need to called with hw lock held.
1946 csio_disable_lnodes(struct csio_hw
*hw
, uint8_t portid
, bool disable
)
1948 struct list_head
*tmp
;
1949 struct csio_lnode
*ln
;
1951 csio_dbg(hw
, "Notifying event to all nodes of port:%d\n", portid
);
1953 /* Traverse sibling lnodes list and send evt */
1954 list_for_each(tmp
, &hw
->sln_head
) {
1955 ln
= (struct csio_lnode
*) tmp
;
1956 if (ln
->portid
!= portid
)
1960 csio_lnode_stop(ln
);
1962 csio_lnode_start(ln
);
1967 * csio_ln_init - Initialize an lnode.
1972 csio_ln_init(struct csio_lnode
*ln
)
1975 struct csio_lnode
*rln
, *pln
;
1976 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1978 csio_init_state(&ln
->sm
, csio_lns_uninit
);
1979 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1980 ln
->fcf_flowid
= CSIO_INVALID_IDX
;
1982 if (csio_is_root_ln(ln
)) {
1984 /* This is the lnode used during initialization */
1986 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
), GFP_KERNEL
);
1988 csio_ln_err(ln
, "Failed to alloc FCF record\n");
1989 CSIO_INC_STATS(hw
, n_err_nomem
);
1993 INIT_LIST_HEAD(&ln
->fcf_lsthead
);
1994 kref_init(&ln
->fcfinfo
->kref
);
1996 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
1999 } else { /* Either a non-root physical or a virtual lnode */
2002 * THe rest is common for non-root physical and NPIV lnodes.
2003 * Just get references to all other modules
2005 rln
= csio_root_lnode(ln
);
2007 if (csio_is_npiv_ln(ln
)) {
2009 pln
= csio_parent_lnode(ln
);
2010 kref_get(&pln
->fcfinfo
->kref
);
2011 ln
->fcfinfo
= pln
->fcfinfo
;
2013 /* Another non-root physical lnode (FCF) */
2014 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
),
2017 csio_ln_err(ln
, "Failed to alloc FCF info\n");
2018 CSIO_INC_STATS(hw
, n_err_nomem
);
2022 kref_init(&ln
->fcfinfo
->kref
);
2024 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2028 } /* if (!csio_is_root_ln(ln)) */
2036 csio_ln_exit(struct csio_lnode
*ln
)
2038 struct csio_lnode
*pln
;
2040 csio_cleanup_rns(ln
);
2041 if (csio_is_npiv_ln(ln
)) {
2042 pln
= csio_parent_lnode(ln
);
2043 kref_put(&pln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2045 kref_put(&ln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2046 if (csio_fdmi_enable
)
2047 csio_ln_fdmi_exit(ln
);
2053 * csio_lnode_init - Initialize the members of an lnode.
2058 csio_lnode_init(struct csio_lnode
*ln
, struct csio_hw
*hw
,
2059 struct csio_lnode
*pln
)
2063 /* Link this lnode to hw */
2064 csio_lnode_to_hw(ln
) = hw
;
2066 /* Link child to parent if child lnode */
2072 /* Initialize scsi_tgt and timers to zero */
2073 ln
->n_scsi_tgts
= 0;
2074 ln
->last_scan_ntgts
= 0;
2075 ln
->tgt_scan_tick
= 0;
2077 /* Initialize rnode list */
2078 INIT_LIST_HEAD(&ln
->rnhead
);
2079 INIT_LIST_HEAD(&ln
->cln_head
);
2081 /* Initialize log level for debug */
2082 ln
->params
.log_level
= hw
->params
.log_level
;
2084 if (csio_ln_init(ln
))
2087 /* Add lnode to list of sibling or children lnodes */
2088 spin_lock_irq(&hw
->lock
);
2089 list_add_tail(&ln
->sm
.sm_list
, pln
? &pln
->cln_head
: &hw
->sln_head
);
2092 spin_unlock_irq(&hw
->lock
);
2098 csio_lnode_to_hw(ln
) = NULL
;
2103 * csio_lnode_exit - De-instantiate an lnode.
2108 csio_lnode_exit(struct csio_lnode
*ln
)
2110 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
2114 /* Remove this lnode from hw->sln_head */
2115 spin_lock_irq(&hw
->lock
);
2117 list_del_init(&ln
->sm
.sm_list
);
2119 /* If it is children lnode, decrement the
2120 * counter in its parent lnode
2123 ln
->pln
->num_vports
--;
2125 /* Update root lnode pointer */
2126 if (list_empty(&hw
->sln_head
))
2129 hw
->rln
= (struct csio_lnode
*)csio_list_next(&hw
->sln_head
);
2131 spin_unlock_irq(&hw
->lock
);
2133 csio_lnode_to_hw(ln
) = NULL
;