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
, void *val
, size_t val_len
)
244 struct fc_fdmi_attr_entry
*ae
= (struct fc_fdmi_attr_entry
*)*ptr
;
246 if (WARN_ON(val_len
> U16_MAX
))
251 ae
->type
= htons(type
);
252 len
+= 4; /* includes attribute type and length */
253 len
= (len
+ 3) & ~3; /* should be multiple of 4 bytes */
254 ae
->len
= htons(len
);
255 memcpy(ae
->value
, val
, val_len
);
257 memset(ae
->value
+ val_len
, 0, len
- val_len
);
262 * csio_ln_fdmi_done - FDMI registeration completion
264 * @fdmi_req: fdmi request
267 csio_ln_fdmi_done(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
270 struct csio_lnode
*ln
= fdmi_req
->lnode
;
272 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
273 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rpa cmd\n",
274 fdmi_req
->wr_status
);
275 CSIO_INC_STATS(ln
, n_fdmi_err
);
278 cmd
= fdmi_req
->dma_buf
.vaddr
;
279 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
280 csio_ln_dbg(ln
, "fdmi rpa cmd rejected reason %x expl %x\n",
281 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
286 * csio_ln_fdmi_rhba_cbfn - RHBA completion
288 * @fdmi_req: fdmi request
291 csio_ln_fdmi_rhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
298 uint32_t numattrs
= 0;
299 struct csio_lnode
*ln
= fdmi_req
->lnode
;
300 struct fs_fdmi_attrs
*attrib_blk
;
301 struct fc_fdmi_port_name
*port_name
;
306 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
307 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rhba cmd\n",
308 fdmi_req
->wr_status
);
309 CSIO_INC_STATS(ln
, n_fdmi_err
);
312 cmd
= fdmi_req
->dma_buf
.vaddr
;
313 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
314 csio_ln_dbg(ln
, "fdmi rhba cmd rejected reason %x expl %x\n",
315 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
318 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
319 CSIO_INC_STATS(ln
, n_fdmi_err
);
323 /* Prepare CT hdr for RPA cmd */
324 memset(cmd
, 0, FC_CT_HDR_LEN
);
325 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RPA
);
327 /* Prepare RPA payload */
328 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
329 port_name
= (struct fc_fdmi_port_name
*)pld
;
330 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
331 pld
+= sizeof(*port_name
);
333 /* Start appending Port attributes */
334 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
335 attrib_blk
->numattrs
= 0;
336 len
+= sizeof(attrib_blk
->numattrs
);
337 pld
+= sizeof(attrib_blk
->numattrs
);
340 memset(fc4_type
, 0, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
343 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_FC4TYPES
,
344 fc4_type
, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
346 val
= htonl(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
347 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED
,
349 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
);
352 if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_1G
)
353 val
= htonl(FC_PORTSPEED_1GBIT
);
354 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_10G
)
355 val
= htonl(FC_PORTSPEED_10GBIT
);
357 val
= htonl(CSIO_HBA_PORTSPEED_UNKNOWN
);
358 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED
,
359 &val
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
);
362 mfs
= ln
->ln_sparm
.csp
.sp_bb_data
;
363 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_MAXFRAMESIZE
,
367 strcpy(buf
, "csiostor");
368 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_OSDEVICENAME
, buf
,
372 if (!csio_hostname(buf
, sizeof(buf
))) {
373 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_HOSTNAME
,
377 attrib_blk
->numattrs
= htonl(numattrs
);
378 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
380 /* Submit FDMI RPA request */
381 spin_lock_irqsave(&hw
->lock
, flags
);
382 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_done
,
383 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
384 CSIO_INC_STATS(ln
, n_fdmi_err
);
385 csio_ln_dbg(ln
, "Failed to issue fdmi rpa req\n");
387 spin_unlock_irqrestore(&hw
->lock
, flags
);
391 * csio_ln_fdmi_dprt_cbfn - DPRT completion
393 * @fdmi_req: fdmi request
396 csio_ln_fdmi_dprt_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
401 uint32_t numattrs
= 0;
402 __be32 maxpayload
= htonl(65536);
403 struct fc_fdmi_hba_identifier
*hbaid
;
404 struct csio_lnode
*ln
= fdmi_req
->lnode
;
405 struct fc_fdmi_rpl
*reg_pl
;
406 struct fs_fdmi_attrs
*attrib_blk
;
410 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
411 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dprt cmd\n",
412 fdmi_req
->wr_status
);
413 CSIO_INC_STATS(ln
, n_fdmi_err
);
416 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
417 CSIO_INC_STATS(ln
, n_fdmi_err
);
420 cmd
= fdmi_req
->dma_buf
.vaddr
;
421 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
422 csio_ln_dbg(ln
, "fdmi dprt cmd rejected reason %x expl %x\n",
423 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
426 /* Prepare CT hdr for RHBA cmd */
427 memset(cmd
, 0, FC_CT_HDR_LEN
);
428 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RHBA
);
431 /* Prepare RHBA payload */
432 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
433 hbaid
= (struct fc_fdmi_hba_identifier
*)pld
;
434 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8); /* HBA identifer */
435 pld
+= sizeof(*hbaid
);
437 /* Register one port per hba */
438 reg_pl
= (struct fc_fdmi_rpl
*)pld
;
439 reg_pl
->numport
= htonl(1);
440 memcpy(®_pl
->port
[0].portname
, csio_ln_wwpn(ln
), 8);
441 pld
+= sizeof(*reg_pl
);
443 /* Start appending HBA attributes hba */
444 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
445 attrib_blk
->numattrs
= 0;
446 len
+= sizeof(attrib_blk
->numattrs
);
447 pld
+= sizeof(attrib_blk
->numattrs
);
449 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_NODENAME
, csio_ln_wwnn(ln
),
450 FC_FDMI_HBA_ATTR_NODENAME_LEN
);
453 memset(buf
, 0, sizeof(buf
));
455 strcpy(buf
, "Chelsio Communications");
456 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MANUFACTURER
, buf
,
459 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_SERIALNUMBER
,
460 hw
->vpd
.sn
, sizeof(hw
->vpd
.sn
));
462 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODEL
, hw
->vpd
.id
,
465 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODELDESCRIPTION
,
466 hw
->model_desc
, strlen(hw
->model_desc
));
468 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_HARDWAREVERSION
,
469 hw
->hw_ver
, sizeof(hw
->hw_ver
));
471 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_FIRMWAREVERSION
,
472 hw
->fwrev_str
, strlen(hw
->fwrev_str
));
475 if (!csio_osname(buf
, sizeof(buf
))) {
476 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_OSNAMEVERSION
,
481 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD
,
482 &maxpayload
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN
);
483 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
485 attrib_blk
->numattrs
= htonl(numattrs
);
487 /* Submit FDMI RHBA request */
488 spin_lock_irqsave(&hw
->lock
, flags
);
489 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_rhba_cbfn
,
490 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
491 CSIO_INC_STATS(ln
, n_fdmi_err
);
492 csio_ln_dbg(ln
, "Failed to issue fdmi rhba req\n");
494 spin_unlock_irqrestore(&hw
->lock
, flags
);
498 * csio_ln_fdmi_dhba_cbfn - DHBA completion
500 * @fdmi_req: fdmi request
503 csio_ln_fdmi_dhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
505 struct csio_lnode
*ln
= fdmi_req
->lnode
;
507 struct fc_fdmi_port_name
*port_name
;
511 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
512 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dhba cmd\n",
513 fdmi_req
->wr_status
);
514 CSIO_INC_STATS(ln
, n_fdmi_err
);
517 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
518 CSIO_INC_STATS(ln
, n_fdmi_err
);
521 cmd
= fdmi_req
->dma_buf
.vaddr
;
522 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
523 csio_ln_dbg(ln
, "fdmi dhba cmd rejected reason %x expl %x\n",
524 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
527 /* Send FDMI cmd to de-register any Port attributes if registered
531 /* Prepare FDMI DPRT cmd */
532 memset(cmd
, 0, FC_CT_HDR_LEN
);
533 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DPRT
);
535 port_name
= (struct fc_fdmi_port_name
*)csio_ct_get_pld(cmd
);
536 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
537 len
+= sizeof(*port_name
);
539 /* Submit FDMI request */
540 spin_lock_irqsave(&hw
->lock
, flags
);
541 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dprt_cbfn
,
542 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
543 CSIO_INC_STATS(ln
, n_fdmi_err
);
544 csio_ln_dbg(ln
, "Failed to issue fdmi dprt req\n");
546 spin_unlock_irqrestore(&hw
->lock
, flags
);
550 * csio_ln_fdmi_start - Start an FDMI request.
552 * @context: session context
554 * Issued with lock held.
557 csio_ln_fdmi_start(struct csio_lnode
*ln
, void *context
)
559 struct csio_ioreq
*fdmi_req
;
560 struct csio_rnode
*fdmi_rn
= (struct csio_rnode
*)context
;
562 struct fc_fdmi_hba_identifier
*hbaid
;
565 if (!(ln
->flags
& CSIO_LNF_FDMI_ENABLE
))
566 return -EPROTONOSUPPORT
;
568 if (!csio_is_rnode_ready(fdmi_rn
))
569 CSIO_INC_STATS(ln
, n_fdmi_err
);
571 /* Send FDMI cmd to de-register any HBA attributes if registered
575 fdmi_req
= ln
->mgmt_req
;
576 fdmi_req
->lnode
= ln
;
577 fdmi_req
->rnode
= fdmi_rn
;
579 /* Prepare FDMI DHBA cmd */
580 cmd
= fdmi_req
->dma_buf
.vaddr
;
581 memset(cmd
, 0, FC_CT_HDR_LEN
);
582 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DHBA
);
585 hbaid
= (struct fc_fdmi_hba_identifier
*)csio_ct_get_pld(cmd
);
586 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8);
587 len
+= sizeof(*hbaid
);
589 /* Submit FDMI request */
590 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dhba_cbfn
,
591 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
592 CSIO_INC_STATS(ln
, n_fdmi_err
);
593 csio_ln_dbg(ln
, "Failed to issue fdmi dhba req\n");
600 * csio_ln_vnp_read_cbfn - vnp read completion handler.
602 * @cbfn: Completion handler.
604 * Reads vnp response and updates ln parameters.
607 csio_ln_vnp_read_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
609 struct csio_lnode
*ln
= ((struct csio_lnode
*)mbp
->priv
);
610 struct fw_fcoe_vnp_cmd
*rsp
= (struct fw_fcoe_vnp_cmd
*)(mbp
->mb
);
611 struct fc_els_csp
*csp
;
612 struct fc_els_cssp
*clsp
;
613 enum fw_retval retval
;
616 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->alloc_to_len16
));
617 if (retval
!= FW_SUCCESS
) {
618 csio_err(hw
, "FCOE VNP read cmd returned error:0x%x\n", retval
);
619 mempool_free(mbp
, hw
->mb_mempool
);
623 spin_lock_irq(&hw
->lock
);
625 memcpy(ln
->mac
, rsp
->vnport_mac
, sizeof(ln
->mac
));
626 memcpy(&nport_id
, &rsp
->vnport_mac
[3], sizeof(uint8_t)*3);
627 ln
->nport_id
= ntohl(nport_id
);
628 ln
->nport_id
= ln
->nport_id
>> 8;
632 * This may look like a duplication of what csio_fcoe_enable_link()
633 * does, but is absolutely necessary if the vnpi changes between
634 * a FCOE LINK UP and FCOE LINK DOWN.
636 memcpy(csio_ln_wwnn(ln
), rsp
->vnport_wwnn
, 8);
637 memcpy(csio_ln_wwpn(ln
), rsp
->vnport_wwpn
, 8);
639 /* Copy common sparam */
640 csp
= (struct fc_els_csp
*)rsp
->cmn_srv_parms
;
641 ln
->ln_sparm
.csp
.sp_hi_ver
= csp
->sp_hi_ver
;
642 ln
->ln_sparm
.csp
.sp_lo_ver
= csp
->sp_lo_ver
;
643 ln
->ln_sparm
.csp
.sp_bb_cred
= csp
->sp_bb_cred
;
644 ln
->ln_sparm
.csp
.sp_features
= csp
->sp_features
;
645 ln
->ln_sparm
.csp
.sp_bb_data
= csp
->sp_bb_data
;
646 ln
->ln_sparm
.csp
.sp_r_a_tov
= csp
->sp_r_a_tov
;
647 ln
->ln_sparm
.csp
.sp_e_d_tov
= csp
->sp_e_d_tov
;
649 /* Copy word 0 & word 1 of class sparam */
650 clsp
= (struct fc_els_cssp
*)rsp
->clsp_word_0_1
;
651 ln
->ln_sparm
.clsp
[2].cp_class
= clsp
->cp_class
;
652 ln
->ln_sparm
.clsp
[2].cp_init
= clsp
->cp_init
;
653 ln
->ln_sparm
.clsp
[2].cp_recip
= clsp
->cp_recip
;
654 ln
->ln_sparm
.clsp
[2].cp_rdfs
= clsp
->cp_rdfs
;
656 spin_unlock_irq(&hw
->lock
);
658 mempool_free(mbp
, hw
->mb_mempool
);
660 /* Send an event to update local attribs */
661 csio_lnode_async_event(ln
, CSIO_LN_FC_ATTRIB_UPDATE
);
665 * csio_ln_vnp_read - Read vnp params.
667 * @cbfn: Completion handler.
669 * Issued with lock held.
672 csio_ln_vnp_read(struct csio_lnode
*ln
,
673 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
675 struct csio_hw
*hw
= ln
->hwp
;
678 /* Allocate Mbox request */
679 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
681 CSIO_INC_STATS(hw
, n_err_nomem
);
685 /* Prepare VNP Command */
686 csio_fcoe_vnp_read_init_mb(ln
, mbp
,
693 if (csio_mb_issue(hw
, mbp
)) {
694 csio_err(hw
, "Failed to issue mbox FCoE VNP command\n");
695 mempool_free(mbp
, hw
->mb_mempool
);
703 * csio_fcoe_enable_link - Enable fcoe link.
705 * @enable: enable/disable
706 * Issued with lock held.
707 * Issues mbox cmd to bring up FCOE link on port associated with given ln.
710 csio_fcoe_enable_link(struct csio_lnode
*ln
, bool enable
)
712 struct csio_hw
*hw
= ln
->hwp
;
714 enum fw_retval retval
;
717 struct fw_fcoe_link_cmd
*lcmd
;
720 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
722 CSIO_INC_STATS(hw
, n_err_nomem
);
727 sub_op
= enable
? FCOE_LINK_UP
: FCOE_LINK_DOWN
;
729 csio_dbg(hw
, "bringing FCOE LINK %s on Port:%d\n",
730 sub_op
? "UP" : "DOWN", portid
);
732 csio_write_fcoe_link_cond_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
733 portid
, sub_op
, 0, 0, 0, NULL
);
735 if (csio_mb_issue(hw
, mbp
)) {
736 csio_err(hw
, "failed to issue FCOE LINK cmd on port[%d]\n",
738 mempool_free(mbp
, hw
->mb_mempool
);
742 retval
= csio_mb_fw_retval(mbp
);
743 if (retval
!= FW_SUCCESS
) {
745 "FCOE LINK %s cmd on port[%d] failed with "
746 "ret:x%x\n", sub_op
? "UP" : "DOWN", portid
, retval
);
747 mempool_free(mbp
, hw
->mb_mempool
);
754 lcmd
= (struct fw_fcoe_link_cmd
*)mbp
->mb
;
756 memcpy(csio_ln_wwnn(ln
), lcmd
->vnport_wwnn
, 8);
757 memcpy(csio_ln_wwpn(ln
), lcmd
->vnport_wwpn
, 8);
759 for (i
= 0; i
< CSIO_MAX_PPORTS
; i
++)
760 if (hw
->pport
[i
].portid
== portid
)
761 memcpy(hw
->pport
[i
].mac
, lcmd
->phy_mac
, 6);
764 mempool_free(mbp
, hw
->mb_mempool
);
769 * csio_ln_read_fcf_cbfn - Read fcf parameters
772 * read fcf response and Update ln fcf information.
775 csio_ln_read_fcf_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
777 struct csio_lnode
*ln
= (struct csio_lnode
*)mbp
->priv
;
778 struct csio_fcf_info
*fcf_info
;
779 struct fw_fcoe_fcf_cmd
*rsp
=
780 (struct fw_fcoe_fcf_cmd
*)(mbp
->mb
);
781 enum fw_retval retval
;
783 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->retval_len16
));
784 if (retval
!= FW_SUCCESS
) {
785 csio_ln_err(ln
, "FCOE FCF cmd failed with ret x%x\n",
787 mempool_free(mbp
, hw
->mb_mempool
);
791 spin_lock_irq(&hw
->lock
);
792 fcf_info
= ln
->fcfinfo
;
793 fcf_info
->priority
= FW_FCOE_FCF_CMD_PRIORITY_GET(
794 ntohs(rsp
->priority_pkd
));
795 fcf_info
->vf_id
= ntohs(rsp
->vf_id
);
796 fcf_info
->vlan_id
= rsp
->vlan_id
;
797 fcf_info
->max_fcoe_size
= ntohs(rsp
->max_fcoe_size
);
798 fcf_info
->fka_adv
= be32_to_cpu(rsp
->fka_adv
);
799 fcf_info
->fcfi
= FW_FCOE_FCF_CMD_FCFI_GET(ntohl(rsp
->op_to_fcfi
));
800 fcf_info
->fpma
= FW_FCOE_FCF_CMD_FPMA_GET(rsp
->fpma_to_portid
);
801 fcf_info
->spma
= FW_FCOE_FCF_CMD_SPMA_GET(rsp
->fpma_to_portid
);
802 fcf_info
->login
= FW_FCOE_FCF_CMD_LOGIN_GET(rsp
->fpma_to_portid
);
803 fcf_info
->portid
= FW_FCOE_FCF_CMD_PORTID_GET(rsp
->fpma_to_portid
);
804 memcpy(fcf_info
->fc_map
, rsp
->fc_map
, sizeof(fcf_info
->fc_map
));
805 memcpy(fcf_info
->mac
, rsp
->mac
, sizeof(fcf_info
->mac
));
806 memcpy(fcf_info
->name_id
, rsp
->name_id
, sizeof(fcf_info
->name_id
));
807 memcpy(fcf_info
->fabric
, rsp
->fabric
, sizeof(fcf_info
->fabric
));
808 memcpy(fcf_info
->spma_mac
, rsp
->spma_mac
, sizeof(fcf_info
->spma_mac
));
810 spin_unlock_irq(&hw
->lock
);
812 mempool_free(mbp
, hw
->mb_mempool
);
816 * csio_ln_read_fcf_entry - Read fcf entry.
818 * @cbfn: Completion handler.
820 * Issued with lock held.
823 csio_ln_read_fcf_entry(struct csio_lnode
*ln
,
824 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
826 struct csio_hw
*hw
= ln
->hwp
;
829 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
831 CSIO_INC_STATS(hw
, n_err_nomem
);
835 /* Get FCoE FCF information */
836 csio_fcoe_read_fcf_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
837 ln
->portid
, ln
->fcf_flowid
, cbfn
);
839 if (csio_mb_issue(hw
, mbp
)) {
840 csio_err(hw
, "failed to issue FCOE FCF cmd\n");
841 mempool_free(mbp
, hw
->mb_mempool
);
849 * csio_handle_link_up - Logical Linkup event.
851 * @portid - Physical port number
856 * This event is received from FW, when virtual link is established between
857 * Physical port[ENode] and FCF. If its new vnpi, then local node object is
858 * created on this FCF and set to [ONLINE] state.
859 * Lnode waits for FW_RDEV_CMD event to be received indicating that
860 * Fabric login is completed and lnode moves to [READY] state.
862 * This called with hw lock held
865 csio_handle_link_up(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
868 struct csio_lnode
*ln
= NULL
;
870 /* Lookup lnode based on vnpi */
871 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
873 /* Pick lnode based on portid */
874 ln
= csio_ln_lookup_by_portid(hw
, portid
);
876 csio_err(hw
, "failed to lookup fcoe lnode on port:%d\n",
882 /* Check if lnode has valid vnp flowid */
883 if (ln
->vnp_flowid
!= CSIO_INVALID_IDX
) {
885 spin_unlock_irq(&hw
->lock
);
886 csio_lnode_alloc(hw
);
887 spin_lock_irq(&hw
->lock
);
890 "failed to allocate fcoe lnode"
891 "for port:%d vnpi:x%x\n",
898 ln
->vnp_flowid
= vnpi
;
899 ln
->dev_num
&= ~0xFFFF;
904 ln
->fcf_flowid
= fcfi
;
906 csio_info(hw
, "Port:%d - FCOE LINK UP\n", portid
);
908 CSIO_INC_STATS(ln
, n_link_up
);
910 /* Send LINKUP event to SM */
911 csio_post_event(&ln
->sm
, CSIO_LNE_LINKUP
);
915 * csio_post_event_rns
917 * @evt - Given rnode event
920 * Posts given rnode event to all FCOE rnodes connected with given Lnode.
921 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
924 * This called with hw lock held
927 csio_post_event_rns(struct csio_lnode
*ln
, enum csio_rn_ev evt
)
929 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
930 struct list_head
*tmp
, *next
;
931 struct csio_rnode
*rn
;
933 list_for_each_safe(tmp
, next
, &rnhead
->sm
.sm_list
) {
934 rn
= (struct csio_rnode
*) tmp
;
935 csio_post_event(&rn
->sm
, evt
);
944 * Frees all FCOE rnodes connected with given Lnode.
946 * This called with hw lock held
949 csio_cleanup_rns(struct csio_lnode
*ln
)
951 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
952 struct list_head
*tmp
, *next_rn
;
953 struct csio_rnode
*rn
;
955 list_for_each_safe(tmp
, next_rn
, &rnhead
->sm
.sm_list
) {
956 rn
= (struct csio_rnode
*) tmp
;
957 csio_put_rnode(ln
, rn
);
963 * csio_post_event_lns
965 * @evt - Given lnode event
968 * Posts given lnode event to all FCOE lnodes connected with given Lnode.
969 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
972 * This called with hw lock held
975 csio_post_event_lns(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
977 struct list_head
*tmp
;
978 struct csio_lnode
*cln
, *sln
;
980 /* If NPIV lnode, send evt only to that and return */
981 if (csio_is_npiv_ln(ln
)) {
982 csio_post_event(&ln
->sm
, evt
);
987 /* Traverse children lnodes list and send evt */
988 list_for_each(tmp
, &sln
->cln_head
) {
989 cln
= (struct csio_lnode
*) tmp
;
990 csio_post_event(&cln
->sm
, evt
);
993 /* Send evt to parent lnode */
994 csio_post_event(&ln
->sm
, evt
);
998 * csio_ln_down - Lcoal nport is down
1002 * Sends LINK_DOWN events to Lnode and its associated NPIVs lnodes.
1004 * This called with hw lock held
1007 csio_ln_down(struct csio_lnode
*ln
)
1009 csio_post_event_lns(ln
, CSIO_LNE_LINK_DOWN
);
1013 * csio_handle_link_down - Logical Linkdown event.
1015 * @portid - Physical port number
1016 * @fcfi - FCF index.
1017 * @vnpi - VNP index.
1020 * This event is received from FW, when virtual link goes down between
1021 * Physical port[ENode] and FCF. Lnode and its associated NPIVs lnode hosted on
1022 * this vnpi[VN-Port] will be de-instantiated.
1024 * This called with hw lock held
1027 csio_handle_link_down(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
1030 struct csio_fcf_info
*fp
;
1031 struct csio_lnode
*ln
;
1033 /* Lookup lnode based on vnpi */
1034 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1037 CSIO_INC_STATS(ln
, n_link_down
);
1039 /*Warn if linkdown received if lnode is not in ready state */
1040 if (!csio_is_lnode_ready(ln
)) {
1042 "warn: FCOE link is already in offline "
1043 "Ignoring Fcoe linkdown event on portid %d\n",
1045 CSIO_INC_STATS(ln
, n_evt_drop
);
1050 if (fp
->portid
!= portid
) {
1052 "warn: FCOE linkdown recv with "
1053 "invalid port %d\n", portid
);
1054 CSIO_INC_STATS(ln
, n_evt_drop
);
1059 if (ln
->fcf_flowid
!= fcfi
) {
1061 "warn: FCOE linkdown recv with "
1062 "invalid fcfi x%x\n", fcfi
);
1063 CSIO_INC_STATS(ln
, n_evt_drop
);
1067 csio_info(hw
, "Port:%d - FCOE LINK DOWN\n", portid
);
1069 /* Send LINK_DOWN event to lnode s/m */
1075 "warn: FCOE linkdown recv with invalid vnpi x%x\n",
1077 CSIO_INC_STATS(hw
, n_evt_drop
);
1082 * csio_is_lnode_ready - Checks FCOE lnode is in ready state.
1085 * Returns True if FCOE lnode is in ready state.
1088 csio_is_lnode_ready(struct csio_lnode
*ln
)
1090 return (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
));
1093 /*****************************************************************************/
1094 /* START: Lnode SM */
1095 /*****************************************************************************/
1097 * csio_lns_uninit - The request in uninit state.
1099 * @evt - Event to be processed.
1101 * Process the given lnode event which is currently in "uninit" state.
1102 * Invoked with HW lock held.
1106 csio_lns_uninit(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1108 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1109 struct csio_lnode
*rln
= hw
->rln
;
1112 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1114 case CSIO_LNE_LINKUP
:
1115 csio_set_state(&ln
->sm
, csio_lns_online
);
1116 /* Read FCF only for physical lnode */
1117 if (csio_is_phys_ln(ln
)) {
1118 rv
= csio_ln_read_fcf_entry(ln
,
1119 csio_ln_read_fcf_cbfn
);
1121 /* TODO: Send HW RESET event */
1122 CSIO_INC_STATS(ln
, n_err
);
1126 /* Add FCF record */
1127 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1130 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1132 /* TODO: Send HW RESET event */
1133 CSIO_INC_STATS(ln
, n_err
);
1137 case CSIO_LNE_DOWN_LINK
:
1142 "unexp ln event %d recv from did:x%x in "
1143 "ln state[uninit].\n", evt
, ln
->nport_id
);
1144 CSIO_INC_STATS(ln
, n_evt_unexp
);
1146 } /* switch event */
1150 * csio_lns_online - The request in online state.
1152 * @evt - Event to be processed.
1154 * Process the given lnode event which is currently in "online" state.
1155 * Invoked with HW lock held.
1159 csio_lns_online(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1161 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1163 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1165 case CSIO_LNE_LINKUP
:
1167 "warn: FCOE link is up already "
1168 "Ignoring linkup on port:%d\n", ln
->portid
);
1169 CSIO_INC_STATS(ln
, n_evt_drop
);
1172 case CSIO_LNE_FAB_INIT_DONE
:
1173 csio_set_state(&ln
->sm
, csio_lns_ready
);
1175 spin_unlock_irq(&hw
->lock
);
1176 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKUP
);
1177 spin_lock_irq(&hw
->lock
);
1181 case CSIO_LNE_LINK_DOWN
:
1183 case CSIO_LNE_DOWN_LINK
:
1184 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1185 if (csio_is_phys_ln(ln
)) {
1186 /* Remove FCF entry */
1187 list_del_init(&ln
->fcfinfo
->list
);
1193 "unexp ln event %d recv from did:x%x in "
1194 "ln state[uninit].\n", evt
, ln
->nport_id
);
1195 CSIO_INC_STATS(ln
, n_evt_unexp
);
1198 } /* switch event */
1202 * csio_lns_ready - The request in ready state.
1204 * @evt - Event to be processed.
1206 * Process the given lnode event which is currently in "ready" state.
1207 * Invoked with HW lock held.
1211 csio_lns_ready(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1213 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1215 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1217 case CSIO_LNE_FAB_INIT_DONE
:
1219 "ignoring event %d recv from did x%x"
1220 "in ln state[ready].\n", evt
, ln
->nport_id
);
1221 CSIO_INC_STATS(ln
, n_evt_drop
);
1224 case CSIO_LNE_LINK_DOWN
:
1225 csio_set_state(&ln
->sm
, csio_lns_offline
);
1226 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1228 spin_unlock_irq(&hw
->lock
);
1229 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1230 spin_lock_irq(&hw
->lock
);
1232 if (csio_is_phys_ln(ln
)) {
1233 /* Remove FCF entry */
1234 list_del_init(&ln
->fcfinfo
->list
);
1238 case CSIO_LNE_DOWN_LINK
:
1239 csio_set_state(&ln
->sm
, csio_lns_offline
);
1240 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1242 /* Host need to issue aborts in case if FW has not returned
1243 * WRs with status "ABORTED"
1245 spin_unlock_irq(&hw
->lock
);
1246 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1247 spin_lock_irq(&hw
->lock
);
1249 if (csio_is_phys_ln(ln
)) {
1250 /* Remove FCF entry */
1251 list_del_init(&ln
->fcfinfo
->list
);
1255 case CSIO_LNE_CLOSE
:
1256 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1257 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1261 csio_set_state(&ln
->sm
, csio_lns_offline
);
1262 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1267 "unexp ln event %d recv from did:x%x in "
1268 "ln state[uninit].\n", evt
, ln
->nport_id
);
1269 CSIO_INC_STATS(ln
, n_evt_unexp
);
1272 } /* switch event */
1276 * csio_lns_offline - The request in offline state.
1278 * @evt - Event to be processed.
1280 * Process the given lnode event which is currently in "offline" state.
1281 * Invoked with HW lock held.
1285 csio_lns_offline(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1287 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1288 struct csio_lnode
*rln
= hw
->rln
;
1291 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1293 case CSIO_LNE_LINKUP
:
1294 csio_set_state(&ln
->sm
, csio_lns_online
);
1295 /* Read FCF only for physical lnode */
1296 if (csio_is_phys_ln(ln
)) {
1297 rv
= csio_ln_read_fcf_entry(ln
,
1298 csio_ln_read_fcf_cbfn
);
1300 /* TODO: Send HW RESET event */
1301 CSIO_INC_STATS(ln
, n_err
);
1305 /* Add FCF record */
1306 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1309 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1311 /* TODO: Send HW RESET event */
1312 CSIO_INC_STATS(ln
, n_err
);
1316 case CSIO_LNE_LINK_DOWN
:
1317 case CSIO_LNE_DOWN_LINK
:
1320 "ignoring event %d recv from did x%x"
1321 "in ln state[offline].\n", evt
, ln
->nport_id
);
1322 CSIO_INC_STATS(ln
, n_evt_drop
);
1325 case CSIO_LNE_CLOSE
:
1326 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1327 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1332 "unexp ln event %d recv from did:x%x in "
1333 "ln state[offline]\n", evt
, ln
->nport_id
);
1334 CSIO_INC_STATS(ln
, n_evt_unexp
);
1337 } /* switch event */
1340 /*****************************************************************************/
1342 /*****************************************************************************/
1345 csio_free_fcfinfo(struct kref
*kref
)
1347 struct csio_fcf_info
*fcfinfo
= container_of(kref
,
1348 struct csio_fcf_info
, kref
);
1352 /* Helper routines for attributes */
1354 * csio_lnode_state_to_str - Get current state of FCOE lnode.
1356 * @str - state of lnode.
1360 csio_lnode_state_to_str(struct csio_lnode
*ln
, int8_t *str
)
1362 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_uninit
)) {
1363 strcpy(str
, "UNINIT");
1366 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
)) {
1367 strcpy(str
, "READY");
1370 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_offline
)) {
1371 strcpy(str
, "OFFLINE");
1374 strcpy(str
, "UNKNOWN");
1375 } /* csio_lnode_state_to_str */
1379 csio_get_phy_port_stats(struct csio_hw
*hw
, uint8_t portid
,
1380 struct fw_fcoe_port_stats
*port_stats
)
1382 struct csio_mb
*mbp
;
1383 struct fw_fcoe_port_cmd_params portparams
;
1384 enum fw_retval retval
;
1387 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
1389 csio_err(hw
, "FCoE FCF PARAMS command out of memory!\n");
1392 portparams
.portid
= portid
;
1394 for (idx
= 1; idx
<= 3; idx
++) {
1395 portparams
.idx
= (idx
-1)*6 + 1;
1396 portparams
.nstats
= 6;
1398 portparams
.nstats
= 4;
1399 csio_fcoe_read_portparams_init_mb(hw
, mbp
, CSIO_MB_DEFAULT_TMO
,
1401 if (csio_mb_issue(hw
, mbp
)) {
1402 csio_err(hw
, "Issue of FCoE port params failed!\n");
1403 mempool_free(mbp
, hw
->mb_mempool
);
1406 csio_mb_process_portparams_rsp(hw
, mbp
, &retval
,
1407 &portparams
, port_stats
);
1410 mempool_free(mbp
, hw
->mb_mempool
);
1415 * csio_ln_mgmt_wr_handler -Mgmt Work Request handler.
1418 * This handler is invoked when an outstanding mgmt WR is completed.
1419 * Its invoked in the context of FW event worker thread for every
1420 * mgmt event received.
1425 csio_ln_mgmt_wr_handler(struct csio_hw
*hw
, void *wr
, uint32_t len
)
1427 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1428 struct csio_ioreq
*io_req
= NULL
;
1429 struct fw_fcoe_els_ct_wr
*wr_cmd
;
1432 wr_cmd
= (struct fw_fcoe_els_ct_wr
*) wr
;
1434 if (len
< sizeof(struct fw_fcoe_els_ct_wr
)) {
1436 "Invalid ELS CT WR length recvd, len:%x\n", len
);
1437 mgmtm
->stats
.n_err
++;
1441 io_req
= (struct csio_ioreq
*) ((uintptr_t) wr_cmd
->cookie
);
1442 io_req
->wr_status
= csio_wr_status(wr_cmd
);
1444 /* lookup ioreq exists in our active Q */
1445 spin_lock_irq(&hw
->lock
);
1446 if (csio_mgmt_req_lookup(mgmtm
, io_req
) != 0) {
1448 "Error- Invalid IO handle recv in WR. handle: %p\n",
1450 mgmtm
->stats
.n_err
++;
1451 spin_unlock_irq(&hw
->lock
);
1455 mgmtm
= csio_hw_to_mgmtm(hw
);
1457 /* Dequeue from active queue */
1458 list_del_init(&io_req
->sm
.sm_list
);
1459 mgmtm
->stats
.n_active
--;
1460 spin_unlock_irq(&hw
->lock
);
1462 /* io_req will be freed by completion handler */
1463 if (io_req
->io_cbfn
)
1464 io_req
->io_cbfn(hw
, io_req
);
1468 * csio_fcoe_fwevt_handler - Event handler for Firmware FCoE events.
1470 * @cpl_op: CPL opcode
1473 * Process received FCoE cmd/WR event from FW.
1476 csio_fcoe_fwevt_handler(struct csio_hw
*hw
, __u8 cpl_op
, __be64
*cmd
)
1478 struct csio_lnode
*ln
;
1479 struct csio_rnode
*rn
;
1480 uint8_t portid
, opcode
= *(uint8_t *)cmd
;
1481 struct fw_fcoe_link_cmd
*lcmd
;
1482 struct fw_wr_hdr
*wr
;
1483 struct fw_rdev_wr
*rdev_wr
;
1484 enum fw_fcoe_link_status lstatus
;
1485 uint32_t fcfi
, rdev_flowid
, vnpi
;
1486 enum csio_ln_ev evt
;
1488 if (cpl_op
== CPL_FW6_MSG
&& opcode
== FW_FCOE_LINK_CMD
) {
1490 lcmd
= (struct fw_fcoe_link_cmd
*)cmd
;
1491 lstatus
= lcmd
->lstatus
;
1492 portid
= FW_FCOE_LINK_CMD_PORTID_GET(
1493 ntohl(lcmd
->op_to_portid
));
1494 fcfi
= FW_FCOE_LINK_CMD_FCFI_GET(ntohl(lcmd
->sub_opcode_fcfi
));
1495 vnpi
= FW_FCOE_LINK_CMD_VNPI_GET(ntohl(lcmd
->vnpi_pkd
));
1497 if (lstatus
== FCOE_LINKUP
) {
1500 spin_lock_irq(&hw
->lock
);
1501 csio_handle_link_up(hw
, portid
, fcfi
, vnpi
);
1502 spin_unlock_irq(&hw
->lock
);
1503 /* HW un lock here */
1505 } else if (lstatus
== FCOE_LINKDOWN
) {
1508 spin_lock_irq(&hw
->lock
);
1509 csio_handle_link_down(hw
, portid
, fcfi
, vnpi
);
1510 spin_unlock_irq(&hw
->lock
);
1511 /* HW un lock here */
1513 csio_warn(hw
, "Unexpected FCOE LINK status:0x%x\n",
1515 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1517 } else if (cpl_op
== CPL_FW6_PLD
) {
1518 wr
= (struct fw_wr_hdr
*) (cmd
+ 4);
1519 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
))
1522 rdev_wr
= (struct fw_rdev_wr
*) (cmd
+ 4);
1524 rdev_flowid
= FW_RDEV_WR_FLOWID_GET(
1525 ntohl(rdev_wr
->alloc_to_len16
));
1526 vnpi
= FW_RDEV_WR_ASSOC_FLOWID_GET(
1527 ntohl(rdev_wr
->flags_to_assoc_flowid
));
1530 "FW_RDEV_WR: flowid:x%x ev_cause:x%x "
1531 "vnpi:0x%x\n", rdev_flowid
,
1532 rdev_wr
->event_cause
, vnpi
);
1534 if (rdev_wr
->protocol
!= PROT_FCOE
) {
1536 "FW_RDEV_WR: invalid proto:x%x "
1537 "received with flowid:x%x\n",
1540 CSIO_INC_STATS(hw
, n_evt_drop
);
1545 spin_lock_irq(&hw
->lock
);
1546 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1549 "FW_DEV_WR: invalid vnpi:x%x received "
1550 "with flowid:x%x\n", vnpi
, rdev_flowid
);
1551 CSIO_INC_STATS(hw
, n_evt_drop
);
1555 rn
= csio_confirm_rnode(ln
, rdev_flowid
,
1556 &rdev_wr
->u
.fcoe_rdev
);
1559 "Failed to confirm rnode "
1560 "for flowid:x%x\n", rdev_flowid
);
1561 CSIO_INC_STATS(hw
, n_evt_drop
);
1565 /* save previous event for debugging */
1566 ln
->prev_evt
= ln
->cur_evt
;
1567 ln
->cur_evt
= rdev_wr
->event_cause
;
1568 CSIO_INC_STATS(ln
, n_evt_fw
[rdev_wr
->event_cause
]);
1570 /* Translate all the fabric events to lnode SM events */
1571 evt
= CSIO_FWE_TO_LNE(rdev_wr
->event_cause
);
1574 "Posting event to lnode event:%d "
1575 "cause:%d flowid:x%x\n", evt
,
1576 rdev_wr
->event_cause
, rdev_flowid
);
1577 csio_post_event(&ln
->sm
, evt
);
1580 /* Handover event to rn SM here. */
1581 csio_rnode_fwevt_handler(rn
, rdev_wr
->event_cause
);
1583 spin_unlock_irq(&hw
->lock
);
1586 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1587 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1588 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1590 } else if (cpl_op
== CPL_FW6_MSG
) {
1591 wr
= (struct fw_wr_hdr
*) (cmd
);
1592 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
)) == FW_FCOE_ELS_CT_WR
) {
1593 csio_ln_mgmt_wr_handler(hw
, wr
,
1594 sizeof(struct fw_fcoe_els_ct_wr
));
1596 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1597 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1598 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1601 csio_warn(hw
, "unexpected CPL op(0x%x) recv\n", opcode
);
1602 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1607 * csio_lnode_start - Kickstart lnode discovery.
1610 * This routine kickstarts the discovery by issuing an FCOE_LINK (up) command.
1613 csio_lnode_start(struct csio_lnode
*ln
)
1616 if (csio_is_phys_ln(ln
) && !(ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1617 rv
= csio_fcoe_enable_link(ln
, 1);
1618 ln
->flags
|= CSIO_LNF_LINK_ENABLE
;
1625 * csio_lnode_stop - Stop the lnode.
1628 * This routine is invoked by HW module to stop lnode and its associated NPIV
1632 csio_lnode_stop(struct csio_lnode
*ln
)
1634 csio_post_event_lns(ln
, CSIO_LNE_DOWN_LINK
);
1635 if (csio_is_phys_ln(ln
) && (ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1636 csio_fcoe_enable_link(ln
, 0);
1637 ln
->flags
&= ~CSIO_LNF_LINK_ENABLE
;
1639 csio_ln_dbg(ln
, "stopping ln :%p\n", ln
);
1643 * csio_lnode_close - Close an lnode.
1646 * This routine is invoked by HW module to close an lnode and its
1647 * associated NPIV lnodes. Lnode and its associated NPIV lnodes are
1648 * set to uninitialized state.
1651 csio_lnode_close(struct csio_lnode
*ln
)
1653 csio_post_event_lns(ln
, CSIO_LNE_CLOSE
);
1654 if (csio_is_phys_ln(ln
))
1655 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1657 csio_ln_dbg(ln
, "closed ln :%p\n", ln
);
1661 * csio_ln_prep_ecwr - Prepare ELS/CT WR.
1662 * @io_req - IO request.
1664 * @immd_len - WR immediate data
1665 * @sub_op - Sub opcode
1666 * @sid - source portid.
1667 * @did - destination portid
1669 * @fw_wr - ELS/CT WR to be prepared.
1670 * Returns: 0 - on success
1673 csio_ln_prep_ecwr(struct csio_ioreq
*io_req
, uint32_t wr_len
,
1674 uint32_t immd_len
, uint8_t sub_op
, uint32_t sid
,
1675 uint32_t did
, uint32_t flow_id
, uint8_t *fw_wr
)
1677 struct fw_fcoe_els_ct_wr
*wr
;
1680 wr
= (struct fw_fcoe_els_ct_wr
*)fw_wr
;
1681 wr
->op_immdlen
= cpu_to_be32(FW_WR_OP_V(FW_FCOE_ELS_CT_WR
) |
1682 FW_FCOE_ELS_CT_WR_IMMDLEN(immd_len
));
1684 wr_len
= DIV_ROUND_UP(wr_len
, 16);
1685 wr
->flowid_len16
= cpu_to_be32(FW_WR_FLOWID_V(flow_id
) |
1686 FW_WR_LEN16_V(wr_len
));
1687 wr
->els_ct_type
= sub_op
;
1689 wr
->cp_en_class
= 0;
1690 wr
->cookie
= io_req
->fw_handle
;
1691 wr
->iqid
= cpu_to_be16(csio_q_physiqid(
1692 io_req
->lnode
->hwp
, io_req
->iq_idx
));
1693 wr
->fl_to_sp
= FW_FCOE_ELS_CT_WR_SP(1);
1694 wr
->tmo_val
= (uint8_t) io_req
->tmo
;
1695 port_id
= htonl(sid
);
1696 memcpy(wr
->l_id
, PORT_ID_PTR(port_id
), 3);
1697 port_id
= htonl(did
);
1698 memcpy(wr
->r_id
, PORT_ID_PTR(port_id
), 3);
1700 /* Prepare RSP SGL */
1701 wr
->rsp_dmalen
= cpu_to_be32(io_req
->dma_buf
.len
);
1702 wr
->rsp_dmaaddr
= cpu_to_be64(io_req
->dma_buf
.paddr
);
1707 * csio_ln_mgmt_submit_wr - Post elsct work request.
1709 * @io_req - io request.
1710 * @sub_op - ELS or CT request type
1711 * @pld - Dma Payload buffer
1712 * @pld_len - Payload len
1713 * Prepares ELSCT Work request and sents it to FW.
1714 * Returns: 0 - on success
1717 csio_ln_mgmt_submit_wr(struct csio_mgmtm
*mgmtm
, struct csio_ioreq
*io_req
,
1718 uint8_t sub_op
, struct csio_dma_buf
*pld
,
1721 struct csio_wr_pair wrp
;
1722 struct csio_lnode
*ln
= io_req
->lnode
;
1723 struct csio_rnode
*rn
= io_req
->rnode
;
1724 struct csio_hw
*hw
= mgmtm
->hw
;
1726 struct ulptx_sgl dsgl
;
1727 uint32_t wr_size
= 0;
1729 uint32_t wr_off
= 0;
1733 /* Calculate WR Size for this ELS REQ */
1734 wr_size
= sizeof(struct fw_fcoe_els_ct_wr
);
1736 /* Send as immediate data if pld < 256 */
1737 if (pld_len
< 256) {
1738 wr_size
+= ALIGN(pld_len
, 8);
1739 im_len
= (uint8_t)pld_len
;
1741 wr_size
+= sizeof(struct ulptx_sgl
);
1743 /* Roundup WR size in units of 16 bytes */
1744 wr_size
= ALIGN(wr_size
, 16);
1746 /* Get WR to send ELS REQ */
1747 ret
= csio_wr_get(hw
, mgmtm
->eq_idx
, wr_size
, &wrp
);
1749 csio_err(hw
, "Failed to get WR for ec_req %p ret:%d\n",
1754 /* Prepare Generic WR used by all ELS/CT cmd */
1755 csio_ln_prep_ecwr(io_req
, wr_size
, im_len
, sub_op
,
1756 ln
->nport_id
, rn
->nport_id
,
1760 /* Copy ELS/CT WR CMD */
1761 csio_wr_copy_to_wrp(&fw_wr
[0], &wrp
, wr_off
,
1762 sizeof(struct fw_fcoe_els_ct_wr
));
1763 wr_off
+= sizeof(struct fw_fcoe_els_ct_wr
);
1765 /* Copy payload to Immediate section of WR */
1767 csio_wr_copy_to_wrp(pld
->vaddr
, &wrp
, wr_off
, im_len
);
1769 /* Program DSGL to dma payload */
1770 dsgl
.cmd_nsge
= htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL
) |
1771 ULPTX_MORE_F
| ULPTX_NSGE_V(1));
1772 dsgl
.len0
= cpu_to_be32(pld_len
);
1773 dsgl
.addr0
= cpu_to_be64(pld
->paddr
);
1774 csio_wr_copy_to_wrp(&dsgl
, &wrp
, ALIGN(wr_off
, 8),
1775 sizeof(struct ulptx_sgl
));
1778 /* Issue work request to xmit ELS/CT req to FW */
1779 csio_wr_issue(mgmtm
->hw
, mgmtm
->eq_idx
, false);
1784 * csio_ln_mgmt_submit_req - Submit FCOE Mgmt request.
1785 * @io_req - IO Request
1786 * @io_cbfn - Completion handler.
1787 * @req_type - ELS or CT request type
1788 * @pld - Dma Payload buffer
1789 * @pld_len - Payload len
1792 * This API used submit managment ELS/CT request.
1793 * This called with hw lock held
1794 * Returns: 0 - on success
1795 * -ENOMEM - on error.
1798 csio_ln_mgmt_submit_req(struct csio_ioreq
*io_req
,
1799 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
1800 enum fcoe_cmn_type req_type
, struct csio_dma_buf
*pld
,
1803 struct csio_hw
*hw
= csio_lnode_to_hw(io_req
->lnode
);
1804 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1807 BUG_ON(pld_len
> pld
->len
);
1809 io_req
->io_cbfn
= io_cbfn
; /* Upper layer callback handler */
1810 io_req
->fw_handle
= (uintptr_t) (io_req
);
1811 io_req
->eq_idx
= mgmtm
->eq_idx
;
1812 io_req
->iq_idx
= mgmtm
->iq_idx
;
1814 rv
= csio_ln_mgmt_submit_wr(mgmtm
, io_req
, req_type
, pld
, pld_len
);
1816 list_add_tail(&io_req
->sm
.sm_list
, &mgmtm
->active_q
);
1817 mgmtm
->stats
.n_active
++;
1823 * csio_ln_fdmi_init - FDMI Init entry point.
1827 csio_ln_fdmi_init(struct csio_lnode
*ln
)
1829 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1830 struct csio_dma_buf
*dma_buf
;
1832 /* Allocate MGMT request required for FDMI */
1833 ln
->mgmt_req
= kzalloc(sizeof(struct csio_ioreq
), GFP_KERNEL
);
1834 if (!ln
->mgmt_req
) {
1835 csio_ln_err(ln
, "Failed to alloc ioreq for FDMI\n");
1836 CSIO_INC_STATS(hw
, n_err_nomem
);
1840 /* Allocate Dma buffers for FDMI response Payload */
1841 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1842 dma_buf
->len
= 2048;
1843 dma_buf
->vaddr
= pci_alloc_consistent(hw
->pdev
, dma_buf
->len
,
1845 if (!dma_buf
->vaddr
) {
1846 csio_err(hw
, "Failed to alloc DMA buffer for FDMI!\n");
1847 kfree(ln
->mgmt_req
);
1848 ln
->mgmt_req
= NULL
;
1852 ln
->flags
|= CSIO_LNF_FDMI_ENABLE
;
1857 * csio_ln_fdmi_exit - FDMI exit entry point.
1861 csio_ln_fdmi_exit(struct csio_lnode
*ln
)
1863 struct csio_dma_buf
*dma_buf
;
1864 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1869 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1871 pci_free_consistent(hw
->pdev
, dma_buf
->len
, dma_buf
->vaddr
,
1874 kfree(ln
->mgmt_req
);
1879 csio_scan_done(struct csio_lnode
*ln
, unsigned long ticks
,
1880 unsigned long time
, unsigned long max_scan_ticks
,
1881 unsigned long delta_scan_ticks
)
1885 if (time
>= max_scan_ticks
)
1888 if (!ln
->tgt_scan_tick
)
1889 ln
->tgt_scan_tick
= ticks
;
1891 if (((ticks
- ln
->tgt_scan_tick
) >= delta_scan_ticks
)) {
1892 if (!ln
->last_scan_ntgts
)
1893 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1895 if (ln
->last_scan_ntgts
== ln
->n_scsi_tgts
)
1898 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1900 ln
->tgt_scan_tick
= ticks
;
1906 * csio_notify_lnodes:
1908 * @note: Notification
1910 * Called from the HW SM to fan out notifications to the
1911 * Lnode SM. Since the HW SM is entered with lock held,
1912 * there is no need to hold locks here.
1916 csio_notify_lnodes(struct csio_hw
*hw
, enum csio_ln_notify note
)
1918 struct list_head
*tmp
;
1919 struct csio_lnode
*ln
;
1921 csio_dbg(hw
, "Notifying all nodes of event %d\n", note
);
1923 /* Traverse children lnodes list and send evt */
1924 list_for_each(tmp
, &hw
->sln_head
) {
1925 ln
= (struct csio_lnode
*) tmp
;
1928 case CSIO_LN_NOTIFY_HWREADY
:
1929 csio_lnode_start(ln
);
1932 case CSIO_LN_NOTIFY_HWRESET
:
1933 case CSIO_LN_NOTIFY_HWREMOVE
:
1934 csio_lnode_close(ln
);
1937 case CSIO_LN_NOTIFY_HWSTOP
:
1938 csio_lnode_stop(ln
);
1949 * csio_disable_lnodes:
1952 * @disable: disable/enable flag.
1953 * If disable=1, disables all lnode hosted on given physical port.
1954 * otherwise enables all the lnodes on given phsysical port.
1955 * This routine need to called with hw lock held.
1958 csio_disable_lnodes(struct csio_hw
*hw
, uint8_t portid
, bool disable
)
1960 struct list_head
*tmp
;
1961 struct csio_lnode
*ln
;
1963 csio_dbg(hw
, "Notifying event to all nodes of port:%d\n", portid
);
1965 /* Traverse sibling lnodes list and send evt */
1966 list_for_each(tmp
, &hw
->sln_head
) {
1967 ln
= (struct csio_lnode
*) tmp
;
1968 if (ln
->portid
!= portid
)
1972 csio_lnode_stop(ln
);
1974 csio_lnode_start(ln
);
1979 * csio_ln_init - Initialize an lnode.
1984 csio_ln_init(struct csio_lnode
*ln
)
1987 struct csio_lnode
*rln
, *pln
;
1988 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1990 csio_init_state(&ln
->sm
, csio_lns_uninit
);
1991 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1992 ln
->fcf_flowid
= CSIO_INVALID_IDX
;
1994 if (csio_is_root_ln(ln
)) {
1996 /* This is the lnode used during initialization */
1998 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
), GFP_KERNEL
);
2000 csio_ln_err(ln
, "Failed to alloc FCF record\n");
2001 CSIO_INC_STATS(hw
, n_err_nomem
);
2005 INIT_LIST_HEAD(&ln
->fcf_lsthead
);
2006 kref_init(&ln
->fcfinfo
->kref
);
2008 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2011 } else { /* Either a non-root physical or a virtual lnode */
2014 * THe rest is common for non-root physical and NPIV lnodes.
2015 * Just get references to all other modules
2017 rln
= csio_root_lnode(ln
);
2019 if (csio_is_npiv_ln(ln
)) {
2021 pln
= csio_parent_lnode(ln
);
2022 kref_get(&pln
->fcfinfo
->kref
);
2023 ln
->fcfinfo
= pln
->fcfinfo
;
2025 /* Another non-root physical lnode (FCF) */
2026 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
),
2029 csio_ln_err(ln
, "Failed to alloc FCF info\n");
2030 CSIO_INC_STATS(hw
, n_err_nomem
);
2034 kref_init(&ln
->fcfinfo
->kref
);
2036 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2040 } /* if (!csio_is_root_ln(ln)) */
2048 csio_ln_exit(struct csio_lnode
*ln
)
2050 struct csio_lnode
*pln
;
2052 csio_cleanup_rns(ln
);
2053 if (csio_is_npiv_ln(ln
)) {
2054 pln
= csio_parent_lnode(ln
);
2055 kref_put(&pln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2057 kref_put(&ln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2058 if (csio_fdmi_enable
)
2059 csio_ln_fdmi_exit(ln
);
2065 * csio_lnode_init - Initialize the members of an lnode.
2070 csio_lnode_init(struct csio_lnode
*ln
, struct csio_hw
*hw
,
2071 struct csio_lnode
*pln
)
2075 /* Link this lnode to hw */
2076 csio_lnode_to_hw(ln
) = hw
;
2078 /* Link child to parent if child lnode */
2084 /* Initialize scsi_tgt and timers to zero */
2085 ln
->n_scsi_tgts
= 0;
2086 ln
->last_scan_ntgts
= 0;
2087 ln
->tgt_scan_tick
= 0;
2089 /* Initialize rnode list */
2090 INIT_LIST_HEAD(&ln
->rnhead
);
2091 INIT_LIST_HEAD(&ln
->cln_head
);
2093 /* Initialize log level for debug */
2094 ln
->params
.log_level
= hw
->params
.log_level
;
2096 if (csio_ln_init(ln
))
2099 /* Add lnode to list of sibling or children lnodes */
2100 spin_lock_irq(&hw
->lock
);
2101 list_add_tail(&ln
->sm
.sm_list
, pln
? &pln
->cln_head
: &hw
->sln_head
);
2104 spin_unlock_irq(&hw
->lock
);
2110 csio_lnode_to_hw(ln
) = NULL
;
2115 * csio_lnode_exit - De-instantiate an lnode.
2120 csio_lnode_exit(struct csio_lnode
*ln
)
2122 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
2126 /* Remove this lnode from hw->sln_head */
2127 spin_lock_irq(&hw
->lock
);
2129 list_del_init(&ln
->sm
.sm_list
);
2131 /* If it is children lnode, decrement the
2132 * counter in its parent lnode
2135 ln
->pln
->num_vports
--;
2137 /* Update root lnode pointer */
2138 if (list_empty(&hw
->sln_head
))
2141 hw
->rln
= (struct csio_lnode
*)csio_list_next(&hw
->sln_head
);
2143 spin_unlock_irq(&hw
->lock
);
2145 csio_lnode_to_hw(ln
) = NULL
;