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
;
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
;
305 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
306 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rhba cmd\n",
307 fdmi_req
->wr_status
);
308 CSIO_INC_STATS(ln
, n_fdmi_err
);
311 cmd
= fdmi_req
->dma_buf
.vaddr
;
312 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
313 csio_ln_dbg(ln
, "fdmi rhba cmd rejected reason %x expl %x\n",
314 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
317 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
318 CSIO_INC_STATS(ln
, n_fdmi_err
);
322 /* Prepare CT hdr for RPA cmd */
323 memset(cmd
, 0, FC_CT_HDR_LEN
);
324 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RPA
);
326 /* Prepare RPA payload */
327 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
328 port_name
= (struct fc_fdmi_port_name
*)pld
;
329 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
330 pld
+= sizeof(*port_name
);
332 /* Start appending Port attributes */
333 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
334 attrib_blk
->numattrs
= 0;
335 len
+= sizeof(attrib_blk
->numattrs
);
336 pld
+= sizeof(attrib_blk
->numattrs
);
339 memset(fc4_type
, 0, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
342 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_FC4TYPES
,
343 fc4_type
, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
345 val
= htonl(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
346 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED
,
348 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
);
351 if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_1G
)
352 val
= htonl(FC_PORTSPEED_1GBIT
);
353 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_10G
)
354 val
= htonl(FC_PORTSPEED_10GBIT
);
356 val
= htonl(CSIO_HBA_PORTSPEED_UNKNOWN
);
357 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED
,
358 &val
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
);
361 mfs
= ln
->ln_sparm
.csp
.sp_bb_data
;
362 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_MAXFRAMESIZE
,
366 strcpy(buf
, "csiostor");
367 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_OSDEVICENAME
, buf
,
371 if (!csio_hostname(buf
, sizeof(buf
))) {
372 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_HOSTNAME
,
376 attrib_blk
->numattrs
= htonl(numattrs
);
377 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
379 /* Submit FDMI RPA request */
380 spin_lock_irq(&hw
->lock
);
381 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_done
,
382 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
383 CSIO_INC_STATS(ln
, n_fdmi_err
);
384 csio_ln_dbg(ln
, "Failed to issue fdmi rpa req\n");
386 spin_unlock_irq(&hw
->lock
);
390 * csio_ln_fdmi_dprt_cbfn - DPRT completion
392 * @fdmi_req: fdmi request
395 csio_ln_fdmi_dprt_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
400 uint32_t numattrs
= 0;
401 __be32 maxpayload
= htonl(65536);
402 struct fc_fdmi_hba_identifier
*hbaid
;
403 struct csio_lnode
*ln
= fdmi_req
->lnode
;
404 struct fc_fdmi_rpl
*reg_pl
;
405 struct fs_fdmi_attrs
*attrib_blk
;
408 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
409 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dprt cmd\n",
410 fdmi_req
->wr_status
);
411 CSIO_INC_STATS(ln
, n_fdmi_err
);
414 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
415 CSIO_INC_STATS(ln
, n_fdmi_err
);
418 cmd
= fdmi_req
->dma_buf
.vaddr
;
419 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
420 csio_ln_dbg(ln
, "fdmi dprt cmd rejected reason %x expl %x\n",
421 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
424 /* Prepare CT hdr for RHBA cmd */
425 memset(cmd
, 0, FC_CT_HDR_LEN
);
426 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RHBA
);
429 /* Prepare RHBA payload */
430 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
431 hbaid
= (struct fc_fdmi_hba_identifier
*)pld
;
432 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8); /* HBA identifer */
433 pld
+= sizeof(*hbaid
);
435 /* Register one port per hba */
436 reg_pl
= (struct fc_fdmi_rpl
*)pld
;
437 reg_pl
->numport
= htonl(1);
438 memcpy(®_pl
->port
[0].portname
, csio_ln_wwpn(ln
), 8);
439 pld
+= sizeof(*reg_pl
);
441 /* Start appending HBA attributes hba */
442 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
443 attrib_blk
->numattrs
= 0;
444 len
+= sizeof(attrib_blk
->numattrs
);
445 pld
+= sizeof(attrib_blk
->numattrs
);
447 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_NODENAME
, csio_ln_wwnn(ln
),
448 FC_FDMI_HBA_ATTR_NODENAME_LEN
);
451 memset(buf
, 0, sizeof(buf
));
453 strcpy(buf
, "Chelsio Communications");
454 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MANUFACTURER
, buf
,
457 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_SERIALNUMBER
,
458 hw
->vpd
.sn
, sizeof(hw
->vpd
.sn
));
460 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODEL
, hw
->vpd
.id
,
463 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODELDESCRIPTION
,
464 hw
->model_desc
, strlen(hw
->model_desc
));
466 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_HARDWAREVERSION
,
467 hw
->hw_ver
, sizeof(hw
->hw_ver
));
469 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_FIRMWAREVERSION
,
470 hw
->fwrev_str
, strlen(hw
->fwrev_str
));
473 if (!csio_osname(buf
, sizeof(buf
))) {
474 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_OSNAMEVERSION
,
479 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD
,
480 &maxpayload
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN
);
481 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
483 attrib_blk
->numattrs
= htonl(numattrs
);
485 /* Submit FDMI RHBA request */
486 spin_lock_irq(&hw
->lock
);
487 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_rhba_cbfn
,
488 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
489 CSIO_INC_STATS(ln
, n_fdmi_err
);
490 csio_ln_dbg(ln
, "Failed to issue fdmi rhba req\n");
492 spin_unlock_irq(&hw
->lock
);
496 * csio_ln_fdmi_dhba_cbfn - DHBA completion
498 * @fdmi_req: fdmi request
501 csio_ln_fdmi_dhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
503 struct csio_lnode
*ln
= fdmi_req
->lnode
;
505 struct fc_fdmi_port_name
*port_name
;
508 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
509 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dhba cmd\n",
510 fdmi_req
->wr_status
);
511 CSIO_INC_STATS(ln
, n_fdmi_err
);
514 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
515 CSIO_INC_STATS(ln
, n_fdmi_err
);
518 cmd
= fdmi_req
->dma_buf
.vaddr
;
519 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
520 csio_ln_dbg(ln
, "fdmi dhba cmd rejected reason %x expl %x\n",
521 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
524 /* Send FDMI cmd to de-register any Port attributes if registered
528 /* Prepare FDMI DPRT cmd */
529 memset(cmd
, 0, FC_CT_HDR_LEN
);
530 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DPRT
);
532 port_name
= (struct fc_fdmi_port_name
*)csio_ct_get_pld(cmd
);
533 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
534 len
+= sizeof(*port_name
);
536 /* Submit FDMI request */
537 spin_lock_irq(&hw
->lock
);
538 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dprt_cbfn
,
539 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
540 CSIO_INC_STATS(ln
, n_fdmi_err
);
541 csio_ln_dbg(ln
, "Failed to issue fdmi dprt req\n");
543 spin_unlock_irq(&hw
->lock
);
547 * csio_ln_fdmi_start - Start an FDMI request.
549 * @context: session context
551 * Issued with lock held.
554 csio_ln_fdmi_start(struct csio_lnode
*ln
, void *context
)
556 struct csio_ioreq
*fdmi_req
;
557 struct csio_rnode
*fdmi_rn
= (struct csio_rnode
*)context
;
559 struct fc_fdmi_hba_identifier
*hbaid
;
562 if (!(ln
->flags
& CSIO_LNF_FDMI_ENABLE
))
563 return -EPROTONOSUPPORT
;
565 if (!csio_is_rnode_ready(fdmi_rn
))
566 CSIO_INC_STATS(ln
, n_fdmi_err
);
568 /* Send FDMI cmd to de-register any HBA attributes if registered
572 fdmi_req
= ln
->mgmt_req
;
573 fdmi_req
->lnode
= ln
;
574 fdmi_req
->rnode
= fdmi_rn
;
576 /* Prepare FDMI DHBA cmd */
577 cmd
= fdmi_req
->dma_buf
.vaddr
;
578 memset(cmd
, 0, FC_CT_HDR_LEN
);
579 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DHBA
);
582 hbaid
= (struct fc_fdmi_hba_identifier
*)csio_ct_get_pld(cmd
);
583 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8);
584 len
+= sizeof(*hbaid
);
586 /* Submit FDMI request */
587 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dhba_cbfn
,
588 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
589 CSIO_INC_STATS(ln
, n_fdmi_err
);
590 csio_ln_dbg(ln
, "Failed to issue fdmi dhba req\n");
597 * csio_ln_vnp_read_cbfn - vnp read completion handler.
599 * @cbfn: Completion handler.
601 * Reads vnp response and updates ln parameters.
604 csio_ln_vnp_read_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
606 struct csio_lnode
*ln
= ((struct csio_lnode
*)mbp
->priv
);
607 struct fw_fcoe_vnp_cmd
*rsp
= (struct fw_fcoe_vnp_cmd
*)(mbp
->mb
);
608 struct fc_els_csp
*csp
;
609 struct fc_els_cssp
*clsp
;
610 enum fw_retval retval
;
613 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->alloc_to_len16
));
614 if (retval
!= FW_SUCCESS
) {
615 csio_err(hw
, "FCOE VNP read cmd returned error:0x%x\n", retval
);
616 mempool_free(mbp
, hw
->mb_mempool
);
620 spin_lock_irq(&hw
->lock
);
622 memcpy(ln
->mac
, rsp
->vnport_mac
, sizeof(ln
->mac
));
623 memcpy(&nport_id
, &rsp
->vnport_mac
[3], sizeof(uint8_t)*3);
624 ln
->nport_id
= ntohl(nport_id
);
625 ln
->nport_id
= ln
->nport_id
>> 8;
629 * This may look like a duplication of what csio_fcoe_enable_link()
630 * does, but is absolutely necessary if the vnpi changes between
631 * a FCOE LINK UP and FCOE LINK DOWN.
633 memcpy(csio_ln_wwnn(ln
), rsp
->vnport_wwnn
, 8);
634 memcpy(csio_ln_wwpn(ln
), rsp
->vnport_wwpn
, 8);
636 /* Copy common sparam */
637 csp
= (struct fc_els_csp
*)rsp
->cmn_srv_parms
;
638 ln
->ln_sparm
.csp
.sp_hi_ver
= csp
->sp_hi_ver
;
639 ln
->ln_sparm
.csp
.sp_lo_ver
= csp
->sp_lo_ver
;
640 ln
->ln_sparm
.csp
.sp_bb_cred
= csp
->sp_bb_cred
;
641 ln
->ln_sparm
.csp
.sp_features
= csp
->sp_features
;
642 ln
->ln_sparm
.csp
.sp_bb_data
= csp
->sp_bb_data
;
643 ln
->ln_sparm
.csp
.sp_r_a_tov
= csp
->sp_r_a_tov
;
644 ln
->ln_sparm
.csp
.sp_e_d_tov
= csp
->sp_e_d_tov
;
646 /* Copy word 0 & word 1 of class sparam */
647 clsp
= (struct fc_els_cssp
*)rsp
->clsp_word_0_1
;
648 ln
->ln_sparm
.clsp
[2].cp_class
= clsp
->cp_class
;
649 ln
->ln_sparm
.clsp
[2].cp_init
= clsp
->cp_init
;
650 ln
->ln_sparm
.clsp
[2].cp_recip
= clsp
->cp_recip
;
651 ln
->ln_sparm
.clsp
[2].cp_rdfs
= clsp
->cp_rdfs
;
653 spin_unlock_irq(&hw
->lock
);
655 mempool_free(mbp
, hw
->mb_mempool
);
657 /* Send an event to update local attribs */
658 csio_lnode_async_event(ln
, CSIO_LN_FC_ATTRIB_UPDATE
);
662 * csio_ln_vnp_read - Read vnp params.
664 * @cbfn: Completion handler.
666 * Issued with lock held.
669 csio_ln_vnp_read(struct csio_lnode
*ln
,
670 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
672 struct csio_hw
*hw
= ln
->hwp
;
675 /* Allocate Mbox request */
676 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
678 CSIO_INC_STATS(hw
, n_err_nomem
);
682 /* Prepare VNP Command */
683 csio_fcoe_vnp_read_init_mb(ln
, mbp
,
690 if (csio_mb_issue(hw
, mbp
)) {
691 csio_err(hw
, "Failed to issue mbox FCoE VNP command\n");
692 mempool_free(mbp
, hw
->mb_mempool
);
700 * csio_fcoe_enable_link - Enable fcoe link.
702 * @enable: enable/disable
703 * Issued with lock held.
704 * Issues mbox cmd to bring up FCOE link on port associated with given ln.
707 csio_fcoe_enable_link(struct csio_lnode
*ln
, bool enable
)
709 struct csio_hw
*hw
= ln
->hwp
;
711 enum fw_retval retval
;
714 struct fw_fcoe_link_cmd
*lcmd
;
717 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
719 CSIO_INC_STATS(hw
, n_err_nomem
);
724 sub_op
= enable
? FCOE_LINK_UP
: FCOE_LINK_DOWN
;
726 csio_dbg(hw
, "bringing FCOE LINK %s on Port:%d\n",
727 sub_op
? "UP" : "DOWN", portid
);
729 csio_write_fcoe_link_cond_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
730 portid
, sub_op
, 0, 0, 0, NULL
);
732 if (csio_mb_issue(hw
, mbp
)) {
733 csio_err(hw
, "failed to issue FCOE LINK cmd on port[%d]\n",
735 mempool_free(mbp
, hw
->mb_mempool
);
739 retval
= csio_mb_fw_retval(mbp
);
740 if (retval
!= FW_SUCCESS
) {
742 "FCOE LINK %s cmd on port[%d] failed with "
743 "ret:x%x\n", sub_op
? "UP" : "DOWN", portid
, retval
);
744 mempool_free(mbp
, hw
->mb_mempool
);
751 lcmd
= (struct fw_fcoe_link_cmd
*)mbp
->mb
;
753 memcpy(csio_ln_wwnn(ln
), lcmd
->vnport_wwnn
, 8);
754 memcpy(csio_ln_wwpn(ln
), lcmd
->vnport_wwpn
, 8);
756 for (i
= 0; i
< CSIO_MAX_PPORTS
; i
++)
757 if (hw
->pport
[i
].portid
== portid
)
758 memcpy(hw
->pport
[i
].mac
, lcmd
->phy_mac
, 6);
761 mempool_free(mbp
, hw
->mb_mempool
);
766 * csio_ln_read_fcf_cbfn - Read fcf parameters
769 * read fcf response and Update ln fcf information.
772 csio_ln_read_fcf_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
774 struct csio_lnode
*ln
= (struct csio_lnode
*)mbp
->priv
;
775 struct csio_fcf_info
*fcf_info
;
776 struct fw_fcoe_fcf_cmd
*rsp
=
777 (struct fw_fcoe_fcf_cmd
*)(mbp
->mb
);
778 enum fw_retval retval
;
780 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->retval_len16
));
781 if (retval
!= FW_SUCCESS
) {
782 csio_ln_err(ln
, "FCOE FCF cmd failed with ret x%x\n",
784 mempool_free(mbp
, hw
->mb_mempool
);
788 spin_lock_irq(&hw
->lock
);
789 fcf_info
= ln
->fcfinfo
;
790 fcf_info
->priority
= FW_FCOE_FCF_CMD_PRIORITY_GET(
791 ntohs(rsp
->priority_pkd
));
792 fcf_info
->vf_id
= ntohs(rsp
->vf_id
);
793 fcf_info
->vlan_id
= rsp
->vlan_id
;
794 fcf_info
->max_fcoe_size
= ntohs(rsp
->max_fcoe_size
);
795 fcf_info
->fka_adv
= be32_to_cpu(rsp
->fka_adv
);
796 fcf_info
->fcfi
= FW_FCOE_FCF_CMD_FCFI_GET(ntohl(rsp
->op_to_fcfi
));
797 fcf_info
->fpma
= FW_FCOE_FCF_CMD_FPMA_GET(rsp
->fpma_to_portid
);
798 fcf_info
->spma
= FW_FCOE_FCF_CMD_SPMA_GET(rsp
->fpma_to_portid
);
799 fcf_info
->login
= FW_FCOE_FCF_CMD_LOGIN_GET(rsp
->fpma_to_portid
);
800 fcf_info
->portid
= FW_FCOE_FCF_CMD_PORTID_GET(rsp
->fpma_to_portid
);
801 memcpy(fcf_info
->fc_map
, rsp
->fc_map
, sizeof(fcf_info
->fc_map
));
802 memcpy(fcf_info
->mac
, rsp
->mac
, sizeof(fcf_info
->mac
));
803 memcpy(fcf_info
->name_id
, rsp
->name_id
, sizeof(fcf_info
->name_id
));
804 memcpy(fcf_info
->fabric
, rsp
->fabric
, sizeof(fcf_info
->fabric
));
805 memcpy(fcf_info
->spma_mac
, rsp
->spma_mac
, sizeof(fcf_info
->spma_mac
));
807 spin_unlock_irq(&hw
->lock
);
809 mempool_free(mbp
, hw
->mb_mempool
);
813 * csio_ln_read_fcf_entry - Read fcf entry.
815 * @cbfn: Completion handler.
817 * Issued with lock held.
820 csio_ln_read_fcf_entry(struct csio_lnode
*ln
,
821 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
823 struct csio_hw
*hw
= ln
->hwp
;
826 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
828 CSIO_INC_STATS(hw
, n_err_nomem
);
832 /* Get FCoE FCF information */
833 csio_fcoe_read_fcf_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
834 ln
->portid
, ln
->fcf_flowid
, cbfn
);
836 if (csio_mb_issue(hw
, mbp
)) {
837 csio_err(hw
, "failed to issue FCOE FCF cmd\n");
838 mempool_free(mbp
, hw
->mb_mempool
);
846 * csio_handle_link_up - Logical Linkup event.
848 * @portid - Physical port number
853 * This event is received from FW, when virtual link is established between
854 * Physical port[ENode] and FCF. If its new vnpi, then local node object is
855 * created on this FCF and set to [ONLINE] state.
856 * Lnode waits for FW_RDEV_CMD event to be received indicating that
857 * Fabric login is completed and lnode moves to [READY] state.
859 * This called with hw lock held
862 csio_handle_link_up(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
865 struct csio_lnode
*ln
= NULL
;
867 /* Lookup lnode based on vnpi */
868 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
870 /* Pick lnode based on portid */
871 ln
= csio_ln_lookup_by_portid(hw
, portid
);
873 csio_err(hw
, "failed to lookup fcoe lnode on port:%d\n",
879 /* Check if lnode has valid vnp flowid */
880 if (ln
->vnp_flowid
!= CSIO_INVALID_IDX
) {
882 spin_unlock_irq(&hw
->lock
);
883 csio_lnode_alloc(hw
);
884 spin_lock_irq(&hw
->lock
);
887 "failed to allocate fcoe lnode"
888 "for port:%d vnpi:x%x\n",
895 ln
->vnp_flowid
= vnpi
;
896 ln
->dev_num
&= ~0xFFFF;
901 ln
->fcf_flowid
= fcfi
;
903 csio_info(hw
, "Port:%d - FCOE LINK UP\n", portid
);
905 CSIO_INC_STATS(ln
, n_link_up
);
907 /* Send LINKUP event to SM */
908 csio_post_event(&ln
->sm
, CSIO_LNE_LINKUP
);
912 * csio_post_event_rns
914 * @evt - Given rnode event
917 * Posts given rnode event to all FCOE rnodes connected with given Lnode.
918 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
921 * This called with hw lock held
924 csio_post_event_rns(struct csio_lnode
*ln
, enum csio_rn_ev evt
)
926 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
927 struct list_head
*tmp
, *next
;
928 struct csio_rnode
*rn
;
930 list_for_each_safe(tmp
, next
, &rnhead
->sm
.sm_list
) {
931 rn
= (struct csio_rnode
*) tmp
;
932 csio_post_event(&rn
->sm
, evt
);
941 * Frees all FCOE rnodes connected with given Lnode.
943 * This called with hw lock held
946 csio_cleanup_rns(struct csio_lnode
*ln
)
948 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
949 struct list_head
*tmp
, *next_rn
;
950 struct csio_rnode
*rn
;
952 list_for_each_safe(tmp
, next_rn
, &rnhead
->sm
.sm_list
) {
953 rn
= (struct csio_rnode
*) tmp
;
954 csio_put_rnode(ln
, rn
);
960 * csio_post_event_lns
962 * @evt - Given lnode event
965 * Posts given lnode event to all FCOE lnodes connected with given Lnode.
966 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
969 * This called with hw lock held
972 csio_post_event_lns(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
974 struct list_head
*tmp
;
975 struct csio_lnode
*cln
, *sln
;
977 /* If NPIV lnode, send evt only to that and return */
978 if (csio_is_npiv_ln(ln
)) {
979 csio_post_event(&ln
->sm
, evt
);
984 /* Traverse children lnodes list and send evt */
985 list_for_each(tmp
, &sln
->cln_head
) {
986 cln
= (struct csio_lnode
*) tmp
;
987 csio_post_event(&cln
->sm
, evt
);
990 /* Send evt to parent lnode */
991 csio_post_event(&ln
->sm
, evt
);
995 * csio_ln_down - Lcoal nport is down
999 * Sends LINK_DOWN events to Lnode and its associated NPIVs lnodes.
1001 * This called with hw lock held
1004 csio_ln_down(struct csio_lnode
*ln
)
1006 csio_post_event_lns(ln
, CSIO_LNE_LINK_DOWN
);
1010 * csio_handle_link_down - Logical Linkdown event.
1012 * @portid - Physical port number
1013 * @fcfi - FCF index.
1014 * @vnpi - VNP index.
1017 * This event is received from FW, when virtual link goes down between
1018 * Physical port[ENode] and FCF. Lnode and its associated NPIVs lnode hosted on
1019 * this vnpi[VN-Port] will be de-instantiated.
1021 * This called with hw lock held
1024 csio_handle_link_down(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
1027 struct csio_fcf_info
*fp
;
1028 struct csio_lnode
*ln
;
1030 /* Lookup lnode based on vnpi */
1031 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1034 CSIO_INC_STATS(ln
, n_link_down
);
1036 /*Warn if linkdown received if lnode is not in ready state */
1037 if (!csio_is_lnode_ready(ln
)) {
1039 "warn: FCOE link is already in offline "
1040 "Ignoring Fcoe linkdown event on portid %d\n",
1042 CSIO_INC_STATS(ln
, n_evt_drop
);
1047 if (fp
->portid
!= portid
) {
1049 "warn: FCOE linkdown recv with "
1050 "invalid port %d\n", portid
);
1051 CSIO_INC_STATS(ln
, n_evt_drop
);
1056 if (ln
->fcf_flowid
!= fcfi
) {
1058 "warn: FCOE linkdown recv with "
1059 "invalid fcfi x%x\n", fcfi
);
1060 CSIO_INC_STATS(ln
, n_evt_drop
);
1064 csio_info(hw
, "Port:%d - FCOE LINK DOWN\n", portid
);
1066 /* Send LINK_DOWN event to lnode s/m */
1072 "warn: FCOE linkdown recv with invalid vnpi x%x\n",
1074 CSIO_INC_STATS(hw
, n_evt_drop
);
1079 * csio_is_lnode_ready - Checks FCOE lnode is in ready state.
1082 * Returns True if FCOE lnode is in ready state.
1085 csio_is_lnode_ready(struct csio_lnode
*ln
)
1087 return (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
));
1090 /*****************************************************************************/
1091 /* START: Lnode SM */
1092 /*****************************************************************************/
1094 * csio_lns_uninit - The request in uninit state.
1096 * @evt - Event to be processed.
1098 * Process the given lnode event which is currently in "uninit" state.
1099 * Invoked with HW lock held.
1103 csio_lns_uninit(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1105 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1106 struct csio_lnode
*rln
= hw
->rln
;
1109 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1111 case CSIO_LNE_LINKUP
:
1112 csio_set_state(&ln
->sm
, csio_lns_online
);
1113 /* Read FCF only for physical lnode */
1114 if (csio_is_phys_ln(ln
)) {
1115 rv
= csio_ln_read_fcf_entry(ln
,
1116 csio_ln_read_fcf_cbfn
);
1118 /* TODO: Send HW RESET event */
1119 CSIO_INC_STATS(ln
, n_err
);
1123 /* Add FCF record */
1124 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1127 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1129 /* TODO: Send HW RESET event */
1130 CSIO_INC_STATS(ln
, n_err
);
1134 case CSIO_LNE_DOWN_LINK
:
1139 "unexp ln event %d recv from did:x%x in "
1140 "ln state[uninit].\n", evt
, ln
->nport_id
);
1141 CSIO_INC_STATS(ln
, n_evt_unexp
);
1143 } /* switch event */
1147 * csio_lns_online - The request in online state.
1149 * @evt - Event to be processed.
1151 * Process the given lnode event which is currently in "online" state.
1152 * Invoked with HW lock held.
1156 csio_lns_online(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1158 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1160 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1162 case CSIO_LNE_LINKUP
:
1164 "warn: FCOE link is up already "
1165 "Ignoring linkup on port:%d\n", ln
->portid
);
1166 CSIO_INC_STATS(ln
, n_evt_drop
);
1169 case CSIO_LNE_FAB_INIT_DONE
:
1170 csio_set_state(&ln
->sm
, csio_lns_ready
);
1172 spin_unlock_irq(&hw
->lock
);
1173 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKUP
);
1174 spin_lock_irq(&hw
->lock
);
1178 case CSIO_LNE_LINK_DOWN
:
1180 case CSIO_LNE_DOWN_LINK
:
1181 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1182 if (csio_is_phys_ln(ln
)) {
1183 /* Remove FCF entry */
1184 list_del_init(&ln
->fcfinfo
->list
);
1190 "unexp ln event %d recv from did:x%x in "
1191 "ln state[uninit].\n", evt
, ln
->nport_id
);
1192 CSIO_INC_STATS(ln
, n_evt_unexp
);
1195 } /* switch event */
1199 * csio_lns_ready - The request in ready state.
1201 * @evt - Event to be processed.
1203 * Process the given lnode event which is currently in "ready" state.
1204 * Invoked with HW lock held.
1208 csio_lns_ready(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1210 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1212 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1214 case CSIO_LNE_FAB_INIT_DONE
:
1216 "ignoring event %d recv from did x%x"
1217 "in ln state[ready].\n", evt
, ln
->nport_id
);
1218 CSIO_INC_STATS(ln
, n_evt_drop
);
1221 case CSIO_LNE_LINK_DOWN
:
1222 csio_set_state(&ln
->sm
, csio_lns_offline
);
1223 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1225 spin_unlock_irq(&hw
->lock
);
1226 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1227 spin_lock_irq(&hw
->lock
);
1229 if (csio_is_phys_ln(ln
)) {
1230 /* Remove FCF entry */
1231 list_del_init(&ln
->fcfinfo
->list
);
1235 case CSIO_LNE_DOWN_LINK
:
1236 csio_set_state(&ln
->sm
, csio_lns_offline
);
1237 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1239 /* Host need to issue aborts in case if FW has not returned
1240 * WRs with status "ABORTED"
1242 spin_unlock_irq(&hw
->lock
);
1243 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1244 spin_lock_irq(&hw
->lock
);
1246 if (csio_is_phys_ln(ln
)) {
1247 /* Remove FCF entry */
1248 list_del_init(&ln
->fcfinfo
->list
);
1252 case CSIO_LNE_CLOSE
:
1253 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1254 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1258 csio_set_state(&ln
->sm
, csio_lns_offline
);
1259 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1264 "unexp ln event %d recv from did:x%x in "
1265 "ln state[uninit].\n", evt
, ln
->nport_id
);
1266 CSIO_INC_STATS(ln
, n_evt_unexp
);
1269 } /* switch event */
1273 * csio_lns_offline - The request in offline state.
1275 * @evt - Event to be processed.
1277 * Process the given lnode event which is currently in "offline" state.
1278 * Invoked with HW lock held.
1282 csio_lns_offline(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1284 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1285 struct csio_lnode
*rln
= hw
->rln
;
1288 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1290 case CSIO_LNE_LINKUP
:
1291 csio_set_state(&ln
->sm
, csio_lns_online
);
1292 /* Read FCF only for physical lnode */
1293 if (csio_is_phys_ln(ln
)) {
1294 rv
= csio_ln_read_fcf_entry(ln
,
1295 csio_ln_read_fcf_cbfn
);
1297 /* TODO: Send HW RESET event */
1298 CSIO_INC_STATS(ln
, n_err
);
1302 /* Add FCF record */
1303 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1306 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1308 /* TODO: Send HW RESET event */
1309 CSIO_INC_STATS(ln
, n_err
);
1313 case CSIO_LNE_LINK_DOWN
:
1314 case CSIO_LNE_DOWN_LINK
:
1317 "ignoring event %d recv from did x%x"
1318 "in ln state[offline].\n", evt
, ln
->nport_id
);
1319 CSIO_INC_STATS(ln
, n_evt_drop
);
1322 case CSIO_LNE_CLOSE
:
1323 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1324 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1329 "unexp ln event %d recv from did:x%x in "
1330 "ln state[offline]\n", evt
, ln
->nport_id
);
1331 CSIO_INC_STATS(ln
, n_evt_unexp
);
1334 } /* switch event */
1337 /*****************************************************************************/
1339 /*****************************************************************************/
1342 csio_free_fcfinfo(struct kref
*kref
)
1344 struct csio_fcf_info
*fcfinfo
= container_of(kref
,
1345 struct csio_fcf_info
, kref
);
1349 /* Helper routines for attributes */
1351 * csio_lnode_state_to_str - Get current state of FCOE lnode.
1353 * @str - state of lnode.
1357 csio_lnode_state_to_str(struct csio_lnode
*ln
, int8_t *str
)
1359 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_uninit
)) {
1360 strcpy(str
, "UNINIT");
1363 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
)) {
1364 strcpy(str
, "READY");
1367 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_offline
)) {
1368 strcpy(str
, "OFFLINE");
1371 strcpy(str
, "UNKNOWN");
1372 } /* csio_lnode_state_to_str */
1376 csio_get_phy_port_stats(struct csio_hw
*hw
, uint8_t portid
,
1377 struct fw_fcoe_port_stats
*port_stats
)
1379 struct csio_mb
*mbp
;
1380 struct fw_fcoe_port_cmd_params portparams
;
1381 enum fw_retval retval
;
1384 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
1386 csio_err(hw
, "FCoE FCF PARAMS command out of memory!\n");
1389 portparams
.portid
= portid
;
1391 for (idx
= 1; idx
<= 3; idx
++) {
1392 portparams
.idx
= (idx
-1)*6 + 1;
1393 portparams
.nstats
= 6;
1395 portparams
.nstats
= 4;
1396 csio_fcoe_read_portparams_init_mb(hw
, mbp
, CSIO_MB_DEFAULT_TMO
,
1398 if (csio_mb_issue(hw
, mbp
)) {
1399 csio_err(hw
, "Issue of FCoE port params failed!\n");
1400 mempool_free(mbp
, hw
->mb_mempool
);
1403 csio_mb_process_portparams_rsp(hw
, mbp
, &retval
,
1404 &portparams
, port_stats
);
1407 mempool_free(mbp
, hw
->mb_mempool
);
1412 * csio_ln_mgmt_wr_handler -Mgmt Work Request handler.
1415 * This handler is invoked when an outstanding mgmt WR is completed.
1416 * Its invoked in the context of FW event worker thread for every
1417 * mgmt event received.
1422 csio_ln_mgmt_wr_handler(struct csio_hw
*hw
, void *wr
, uint32_t len
)
1424 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1425 struct csio_ioreq
*io_req
= NULL
;
1426 struct fw_fcoe_els_ct_wr
*wr_cmd
;
1429 wr_cmd
= (struct fw_fcoe_els_ct_wr
*) wr
;
1431 if (len
< sizeof(struct fw_fcoe_els_ct_wr
)) {
1433 "Invalid ELS CT WR length recvd, len:%x\n", len
);
1434 mgmtm
->stats
.n_err
++;
1438 io_req
= (struct csio_ioreq
*) ((uintptr_t) wr_cmd
->cookie
);
1439 io_req
->wr_status
= csio_wr_status(wr_cmd
);
1441 /* lookup ioreq exists in our active Q */
1442 spin_lock_irq(&hw
->lock
);
1443 if (csio_mgmt_req_lookup(mgmtm
, io_req
) != 0) {
1445 "Error- Invalid IO handle recv in WR. handle: %p\n",
1447 mgmtm
->stats
.n_err
++;
1448 spin_unlock_irq(&hw
->lock
);
1452 mgmtm
= csio_hw_to_mgmtm(hw
);
1454 /* Dequeue from active queue */
1455 list_del_init(&io_req
->sm
.sm_list
);
1456 mgmtm
->stats
.n_active
--;
1457 spin_unlock_irq(&hw
->lock
);
1459 /* io_req will be freed by completion handler */
1460 if (io_req
->io_cbfn
)
1461 io_req
->io_cbfn(hw
, io_req
);
1465 * csio_fcoe_fwevt_handler - Event handler for Firmware FCoE events.
1467 * @cpl_op: CPL opcode
1470 * Process received FCoE cmd/WR event from FW.
1473 csio_fcoe_fwevt_handler(struct csio_hw
*hw
, __u8 cpl_op
, __be64
*cmd
)
1475 struct csio_lnode
*ln
;
1476 struct csio_rnode
*rn
;
1477 uint8_t portid
, opcode
= *(uint8_t *)cmd
;
1478 struct fw_fcoe_link_cmd
*lcmd
;
1479 struct fw_wr_hdr
*wr
;
1480 struct fw_rdev_wr
*rdev_wr
;
1481 enum fw_fcoe_link_status lstatus
;
1482 uint32_t fcfi
, rdev_flowid
, vnpi
;
1483 enum csio_ln_ev evt
;
1485 if (cpl_op
== CPL_FW6_MSG
&& opcode
== FW_FCOE_LINK_CMD
) {
1487 lcmd
= (struct fw_fcoe_link_cmd
*)cmd
;
1488 lstatus
= lcmd
->lstatus
;
1489 portid
= FW_FCOE_LINK_CMD_PORTID_GET(
1490 ntohl(lcmd
->op_to_portid
));
1491 fcfi
= FW_FCOE_LINK_CMD_FCFI_GET(ntohl(lcmd
->sub_opcode_fcfi
));
1492 vnpi
= FW_FCOE_LINK_CMD_VNPI_GET(ntohl(lcmd
->vnpi_pkd
));
1494 if (lstatus
== FCOE_LINKUP
) {
1497 spin_lock_irq(&hw
->lock
);
1498 csio_handle_link_up(hw
, portid
, fcfi
, vnpi
);
1499 spin_unlock_irq(&hw
->lock
);
1500 /* HW un lock here */
1502 } else if (lstatus
== FCOE_LINKDOWN
) {
1505 spin_lock_irq(&hw
->lock
);
1506 csio_handle_link_down(hw
, portid
, fcfi
, vnpi
);
1507 spin_unlock_irq(&hw
->lock
);
1508 /* HW un lock here */
1510 csio_warn(hw
, "Unexpected FCOE LINK status:0x%x\n",
1512 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1514 } else if (cpl_op
== CPL_FW6_PLD
) {
1515 wr
= (struct fw_wr_hdr
*) (cmd
+ 4);
1516 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
))
1519 rdev_wr
= (struct fw_rdev_wr
*) (cmd
+ 4);
1521 rdev_flowid
= FW_RDEV_WR_FLOWID_GET(
1522 ntohl(rdev_wr
->alloc_to_len16
));
1523 vnpi
= FW_RDEV_WR_ASSOC_FLOWID_GET(
1524 ntohl(rdev_wr
->flags_to_assoc_flowid
));
1527 "FW_RDEV_WR: flowid:x%x ev_cause:x%x "
1528 "vnpi:0x%x\n", rdev_flowid
,
1529 rdev_wr
->event_cause
, vnpi
);
1531 if (rdev_wr
->protocol
!= PROT_FCOE
) {
1533 "FW_RDEV_WR: invalid proto:x%x "
1534 "received with flowid:x%x\n",
1537 CSIO_INC_STATS(hw
, n_evt_drop
);
1542 spin_lock_irq(&hw
->lock
);
1543 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1546 "FW_DEV_WR: invalid vnpi:x%x received "
1547 "with flowid:x%x\n", vnpi
, rdev_flowid
);
1548 CSIO_INC_STATS(hw
, n_evt_drop
);
1552 rn
= csio_confirm_rnode(ln
, rdev_flowid
,
1553 &rdev_wr
->u
.fcoe_rdev
);
1556 "Failed to confirm rnode "
1557 "for flowid:x%x\n", rdev_flowid
);
1558 CSIO_INC_STATS(hw
, n_evt_drop
);
1562 /* save previous event for debugging */
1563 ln
->prev_evt
= ln
->cur_evt
;
1564 ln
->cur_evt
= rdev_wr
->event_cause
;
1565 CSIO_INC_STATS(ln
, n_evt_fw
[rdev_wr
->event_cause
]);
1567 /* Translate all the fabric events to lnode SM events */
1568 evt
= CSIO_FWE_TO_LNE(rdev_wr
->event_cause
);
1571 "Posting event to lnode event:%d "
1572 "cause:%d flowid:x%x\n", evt
,
1573 rdev_wr
->event_cause
, rdev_flowid
);
1574 csio_post_event(&ln
->sm
, evt
);
1577 /* Handover event to rn SM here. */
1578 csio_rnode_fwevt_handler(rn
, rdev_wr
->event_cause
);
1580 spin_unlock_irq(&hw
->lock
);
1583 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1584 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1585 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1587 } else if (cpl_op
== CPL_FW6_MSG
) {
1588 wr
= (struct fw_wr_hdr
*) (cmd
);
1589 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
)) == FW_FCOE_ELS_CT_WR
) {
1590 csio_ln_mgmt_wr_handler(hw
, wr
,
1591 sizeof(struct fw_fcoe_els_ct_wr
));
1593 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1594 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1595 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1598 csio_warn(hw
, "unexpected CPL op(0x%x) recv\n", opcode
);
1599 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1604 * csio_lnode_start - Kickstart lnode discovery.
1607 * This routine kickstarts the discovery by issuing an FCOE_LINK (up) command.
1610 csio_lnode_start(struct csio_lnode
*ln
)
1613 if (csio_is_phys_ln(ln
) && !(ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1614 rv
= csio_fcoe_enable_link(ln
, 1);
1615 ln
->flags
|= CSIO_LNF_LINK_ENABLE
;
1622 * csio_lnode_stop - Stop the lnode.
1625 * This routine is invoked by HW module to stop lnode and its associated NPIV
1629 csio_lnode_stop(struct csio_lnode
*ln
)
1631 csio_post_event_lns(ln
, CSIO_LNE_DOWN_LINK
);
1632 if (csio_is_phys_ln(ln
) && (ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1633 csio_fcoe_enable_link(ln
, 0);
1634 ln
->flags
&= ~CSIO_LNF_LINK_ENABLE
;
1636 csio_ln_dbg(ln
, "stopping ln :%p\n", ln
);
1640 * csio_lnode_close - Close an lnode.
1643 * This routine is invoked by HW module to close an lnode and its
1644 * associated NPIV lnodes. Lnode and its associated NPIV lnodes are
1645 * set to uninitialized state.
1648 csio_lnode_close(struct csio_lnode
*ln
)
1650 csio_post_event_lns(ln
, CSIO_LNE_CLOSE
);
1651 if (csio_is_phys_ln(ln
))
1652 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1654 csio_ln_dbg(ln
, "closed ln :%p\n", ln
);
1658 * csio_ln_prep_ecwr - Prepare ELS/CT WR.
1659 * @io_req - IO request.
1661 * @immd_len - WR immediate data
1662 * @sub_op - Sub opcode
1663 * @sid - source portid.
1664 * @did - destination portid
1666 * @fw_wr - ELS/CT WR to be prepared.
1667 * Returns: 0 - on success
1670 csio_ln_prep_ecwr(struct csio_ioreq
*io_req
, uint32_t wr_len
,
1671 uint32_t immd_len
, uint8_t sub_op
, uint32_t sid
,
1672 uint32_t did
, uint32_t flow_id
, uint8_t *fw_wr
)
1674 struct fw_fcoe_els_ct_wr
*wr
;
1677 wr
= (struct fw_fcoe_els_ct_wr
*)fw_wr
;
1678 wr
->op_immdlen
= cpu_to_be32(FW_WR_OP_V(FW_FCOE_ELS_CT_WR
) |
1679 FW_FCOE_ELS_CT_WR_IMMDLEN(immd_len
));
1681 wr_len
= DIV_ROUND_UP(wr_len
, 16);
1682 wr
->flowid_len16
= cpu_to_be32(FW_WR_FLOWID_V(flow_id
) |
1683 FW_WR_LEN16_V(wr_len
));
1684 wr
->els_ct_type
= sub_op
;
1686 wr
->cp_en_class
= 0;
1687 wr
->cookie
= io_req
->fw_handle
;
1688 wr
->iqid
= cpu_to_be16(csio_q_physiqid(
1689 io_req
->lnode
->hwp
, io_req
->iq_idx
));
1690 wr
->fl_to_sp
= FW_FCOE_ELS_CT_WR_SP(1);
1691 wr
->tmo_val
= (uint8_t) io_req
->tmo
;
1692 port_id
= htonl(sid
);
1693 memcpy(wr
->l_id
, PORT_ID_PTR(port_id
), 3);
1694 port_id
= htonl(did
);
1695 memcpy(wr
->r_id
, PORT_ID_PTR(port_id
), 3);
1697 /* Prepare RSP SGL */
1698 wr
->rsp_dmalen
= cpu_to_be32(io_req
->dma_buf
.len
);
1699 wr
->rsp_dmaaddr
= cpu_to_be64(io_req
->dma_buf
.paddr
);
1704 * csio_ln_mgmt_submit_wr - Post elsct work request.
1706 * @io_req - io request.
1707 * @sub_op - ELS or CT request type
1708 * @pld - Dma Payload buffer
1709 * @pld_len - Payload len
1710 * Prepares ELSCT Work request and sents it to FW.
1711 * Returns: 0 - on success
1714 csio_ln_mgmt_submit_wr(struct csio_mgmtm
*mgmtm
, struct csio_ioreq
*io_req
,
1715 uint8_t sub_op
, struct csio_dma_buf
*pld
,
1718 struct csio_wr_pair wrp
;
1719 struct csio_lnode
*ln
= io_req
->lnode
;
1720 struct csio_rnode
*rn
= io_req
->rnode
;
1721 struct csio_hw
*hw
= mgmtm
->hw
;
1723 struct ulptx_sgl dsgl
;
1724 uint32_t wr_size
= 0;
1726 uint32_t wr_off
= 0;
1730 /* Calculate WR Size for this ELS REQ */
1731 wr_size
= sizeof(struct fw_fcoe_els_ct_wr
);
1733 /* Send as immediate data if pld < 256 */
1734 if (pld_len
< 256) {
1735 wr_size
+= ALIGN(pld_len
, 8);
1736 im_len
= (uint8_t)pld_len
;
1738 wr_size
+= sizeof(struct ulptx_sgl
);
1740 /* Roundup WR size in units of 16 bytes */
1741 wr_size
= ALIGN(wr_size
, 16);
1743 /* Get WR to send ELS REQ */
1744 ret
= csio_wr_get(hw
, mgmtm
->eq_idx
, wr_size
, &wrp
);
1746 csio_err(hw
, "Failed to get WR for ec_req %p ret:%d\n",
1751 /* Prepare Generic WR used by all ELS/CT cmd */
1752 csio_ln_prep_ecwr(io_req
, wr_size
, im_len
, sub_op
,
1753 ln
->nport_id
, rn
->nport_id
,
1757 /* Copy ELS/CT WR CMD */
1758 csio_wr_copy_to_wrp(&fw_wr
[0], &wrp
, wr_off
,
1759 sizeof(struct fw_fcoe_els_ct_wr
));
1760 wr_off
+= sizeof(struct fw_fcoe_els_ct_wr
);
1762 /* Copy payload to Immediate section of WR */
1764 csio_wr_copy_to_wrp(pld
->vaddr
, &wrp
, wr_off
, im_len
);
1766 /* Program DSGL to dma payload */
1767 dsgl
.cmd_nsge
= htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL
) |
1768 ULPTX_MORE_F
| ULPTX_NSGE_V(1));
1769 dsgl
.len0
= cpu_to_be32(pld_len
);
1770 dsgl
.addr0
= cpu_to_be64(pld
->paddr
);
1771 csio_wr_copy_to_wrp(&dsgl
, &wrp
, ALIGN(wr_off
, 8),
1772 sizeof(struct ulptx_sgl
));
1775 /* Issue work request to xmit ELS/CT req to FW */
1776 csio_wr_issue(mgmtm
->hw
, mgmtm
->eq_idx
, false);
1781 * csio_ln_mgmt_submit_req - Submit FCOE Mgmt request.
1782 * @io_req - IO Request
1783 * @io_cbfn - Completion handler.
1784 * @req_type - ELS or CT request type
1785 * @pld - Dma Payload buffer
1786 * @pld_len - Payload len
1789 * This API used submit managment ELS/CT request.
1790 * This called with hw lock held
1791 * Returns: 0 - on success
1792 * -ENOMEM - on error.
1795 csio_ln_mgmt_submit_req(struct csio_ioreq
*io_req
,
1796 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
1797 enum fcoe_cmn_type req_type
, struct csio_dma_buf
*pld
,
1800 struct csio_hw
*hw
= csio_lnode_to_hw(io_req
->lnode
);
1801 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1804 BUG_ON(pld_len
> pld
->len
);
1806 io_req
->io_cbfn
= io_cbfn
; /* Upper layer callback handler */
1807 io_req
->fw_handle
= (uintptr_t) (io_req
);
1808 io_req
->eq_idx
= mgmtm
->eq_idx
;
1809 io_req
->iq_idx
= mgmtm
->iq_idx
;
1811 rv
= csio_ln_mgmt_submit_wr(mgmtm
, io_req
, req_type
, pld
, pld_len
);
1813 list_add_tail(&io_req
->sm
.sm_list
, &mgmtm
->active_q
);
1814 mgmtm
->stats
.n_active
++;
1820 * csio_ln_fdmi_init - FDMI Init entry point.
1824 csio_ln_fdmi_init(struct csio_lnode
*ln
)
1826 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1827 struct csio_dma_buf
*dma_buf
;
1829 /* Allocate MGMT request required for FDMI */
1830 ln
->mgmt_req
= kzalloc(sizeof(struct csio_ioreq
), GFP_KERNEL
);
1831 if (!ln
->mgmt_req
) {
1832 csio_ln_err(ln
, "Failed to alloc ioreq for FDMI\n");
1833 CSIO_INC_STATS(hw
, n_err_nomem
);
1837 /* Allocate Dma buffers for FDMI response Payload */
1838 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1839 dma_buf
->len
= 2048;
1840 dma_buf
->vaddr
= pci_alloc_consistent(hw
->pdev
, dma_buf
->len
,
1842 if (!dma_buf
->vaddr
) {
1843 csio_err(hw
, "Failed to alloc DMA buffer for FDMI!\n");
1844 kfree(ln
->mgmt_req
);
1845 ln
->mgmt_req
= NULL
;
1849 ln
->flags
|= CSIO_LNF_FDMI_ENABLE
;
1854 * csio_ln_fdmi_exit - FDMI exit entry point.
1858 csio_ln_fdmi_exit(struct csio_lnode
*ln
)
1860 struct csio_dma_buf
*dma_buf
;
1861 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1866 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1868 pci_free_consistent(hw
->pdev
, dma_buf
->len
, dma_buf
->vaddr
,
1871 kfree(ln
->mgmt_req
);
1876 csio_scan_done(struct csio_lnode
*ln
, unsigned long ticks
,
1877 unsigned long time
, unsigned long max_scan_ticks
,
1878 unsigned long delta_scan_ticks
)
1882 if (time
>= max_scan_ticks
)
1885 if (!ln
->tgt_scan_tick
)
1886 ln
->tgt_scan_tick
= ticks
;
1888 if (((ticks
- ln
->tgt_scan_tick
) >= delta_scan_ticks
)) {
1889 if (!ln
->last_scan_ntgts
)
1890 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1892 if (ln
->last_scan_ntgts
== ln
->n_scsi_tgts
)
1895 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1897 ln
->tgt_scan_tick
= ticks
;
1903 * csio_notify_lnodes:
1905 * @note: Notification
1907 * Called from the HW SM to fan out notifications to the
1908 * Lnode SM. Since the HW SM is entered with lock held,
1909 * there is no need to hold locks here.
1913 csio_notify_lnodes(struct csio_hw
*hw
, enum csio_ln_notify note
)
1915 struct list_head
*tmp
;
1916 struct csio_lnode
*ln
;
1918 csio_dbg(hw
, "Notifying all nodes of event %d\n", note
);
1920 /* Traverse children lnodes list and send evt */
1921 list_for_each(tmp
, &hw
->sln_head
) {
1922 ln
= (struct csio_lnode
*) tmp
;
1925 case CSIO_LN_NOTIFY_HWREADY
:
1926 csio_lnode_start(ln
);
1929 case CSIO_LN_NOTIFY_HWRESET
:
1930 case CSIO_LN_NOTIFY_HWREMOVE
:
1931 csio_lnode_close(ln
);
1934 case CSIO_LN_NOTIFY_HWSTOP
:
1935 csio_lnode_stop(ln
);
1946 * csio_disable_lnodes:
1949 * @disable: disable/enable flag.
1950 * If disable=1, disables all lnode hosted on given physical port.
1951 * otherwise enables all the lnodes on given phsysical port.
1952 * This routine need to called with hw lock held.
1955 csio_disable_lnodes(struct csio_hw
*hw
, uint8_t portid
, bool disable
)
1957 struct list_head
*tmp
;
1958 struct csio_lnode
*ln
;
1960 csio_dbg(hw
, "Notifying event to all nodes of port:%d\n", portid
);
1962 /* Traverse sibling lnodes list and send evt */
1963 list_for_each(tmp
, &hw
->sln_head
) {
1964 ln
= (struct csio_lnode
*) tmp
;
1965 if (ln
->portid
!= portid
)
1969 csio_lnode_stop(ln
);
1971 csio_lnode_start(ln
);
1976 * csio_ln_init - Initialize an lnode.
1981 csio_ln_init(struct csio_lnode
*ln
)
1984 struct csio_lnode
*rln
, *pln
;
1985 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1987 csio_init_state(&ln
->sm
, csio_lns_uninit
);
1988 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1989 ln
->fcf_flowid
= CSIO_INVALID_IDX
;
1991 if (csio_is_root_ln(ln
)) {
1993 /* This is the lnode used during initialization */
1995 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
), GFP_KERNEL
);
1997 csio_ln_err(ln
, "Failed to alloc FCF record\n");
1998 CSIO_INC_STATS(hw
, n_err_nomem
);
2002 INIT_LIST_HEAD(&ln
->fcf_lsthead
);
2003 kref_init(&ln
->fcfinfo
->kref
);
2005 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2008 } else { /* Either a non-root physical or a virtual lnode */
2011 * THe rest is common for non-root physical and NPIV lnodes.
2012 * Just get references to all other modules
2014 rln
= csio_root_lnode(ln
);
2016 if (csio_is_npiv_ln(ln
)) {
2018 pln
= csio_parent_lnode(ln
);
2019 kref_get(&pln
->fcfinfo
->kref
);
2020 ln
->fcfinfo
= pln
->fcfinfo
;
2022 /* Another non-root physical lnode (FCF) */
2023 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
),
2026 csio_ln_err(ln
, "Failed to alloc FCF info\n");
2027 CSIO_INC_STATS(hw
, n_err_nomem
);
2031 kref_init(&ln
->fcfinfo
->kref
);
2033 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2037 } /* if (!csio_is_root_ln(ln)) */
2045 csio_ln_exit(struct csio_lnode
*ln
)
2047 struct csio_lnode
*pln
;
2049 csio_cleanup_rns(ln
);
2050 if (csio_is_npiv_ln(ln
)) {
2051 pln
= csio_parent_lnode(ln
);
2052 kref_put(&pln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2054 kref_put(&ln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2055 if (csio_fdmi_enable
)
2056 csio_ln_fdmi_exit(ln
);
2062 * csio_lnode_init - Initialize the members of an lnode.
2067 csio_lnode_init(struct csio_lnode
*ln
, struct csio_hw
*hw
,
2068 struct csio_lnode
*pln
)
2072 /* Link this lnode to hw */
2073 csio_lnode_to_hw(ln
) = hw
;
2075 /* Link child to parent if child lnode */
2081 /* Initialize scsi_tgt and timers to zero */
2082 ln
->n_scsi_tgts
= 0;
2083 ln
->last_scan_ntgts
= 0;
2084 ln
->tgt_scan_tick
= 0;
2086 /* Initialize rnode list */
2087 INIT_LIST_HEAD(&ln
->rnhead
);
2088 INIT_LIST_HEAD(&ln
->cln_head
);
2090 /* Initialize log level for debug */
2091 ln
->params
.log_level
= hw
->params
.log_level
;
2093 if (csio_ln_init(ln
))
2096 /* Add lnode to list of sibling or children lnodes */
2097 spin_lock_irq(&hw
->lock
);
2098 list_add_tail(&ln
->sm
.sm_list
, pln
? &pln
->cln_head
: &hw
->sln_head
);
2101 spin_unlock_irq(&hw
->lock
);
2107 csio_lnode_to_hw(ln
) = NULL
;
2112 * csio_lnode_exit - De-instantiate an lnode.
2117 csio_lnode_exit(struct csio_lnode
*ln
)
2119 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
2123 /* Remove this lnode from hw->sln_head */
2124 spin_lock_irq(&hw
->lock
);
2126 list_del_init(&ln
->sm
.sm_list
);
2128 /* If it is children lnode, decrement the
2129 * counter in its parent lnode
2132 ln
->pln
->num_vports
--;
2134 /* Update root lnode pointer */
2135 if (list_empty(&hw
->sln_head
))
2138 hw
->rln
= (struct csio_lnode
*)csio_list_next(&hw
->sln_head
);
2140 spin_unlock_irq(&hw
->lock
);
2142 csio_lnode_to_hw(ln
) = NULL
;