18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify 58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 158c2ecf20Sopenharmony_ci * SOFTWARE. 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifndef __SNIC_DISC_H 198c2ecf20Sopenharmony_ci#define __SNIC_DISC_H 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include "snic_fwint.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cienum snic_disc_state { 248c2ecf20Sopenharmony_ci SNIC_DISC_NONE, 258c2ecf20Sopenharmony_ci SNIC_DISC_INIT, 268c2ecf20Sopenharmony_ci SNIC_DISC_PENDING, 278c2ecf20Sopenharmony_ci SNIC_DISC_DONE 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct snic; 318c2ecf20Sopenharmony_cistruct snic_disc { 328c2ecf20Sopenharmony_ci struct list_head tgt_list; 338c2ecf20Sopenharmony_ci enum snic_disc_state state; 348c2ecf20Sopenharmony_ci struct mutex mutex; 358c2ecf20Sopenharmony_ci u16 disc_id; 368c2ecf20Sopenharmony_ci u8 req_cnt; 378c2ecf20Sopenharmony_ci u32 nxt_tgt_id; 388c2ecf20Sopenharmony_ci u32 rtgt_cnt; 398c2ecf20Sopenharmony_ci u8 *rtgt_info; 408c2ecf20Sopenharmony_ci struct delayed_work disc_timeout; 418c2ecf20Sopenharmony_ci void (*cb)(struct snic *); 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define SNIC_TGT_NAM_LEN 16 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cienum snic_tgt_state { 478c2ecf20Sopenharmony_ci SNIC_TGT_STAT_NONE, 488c2ecf20Sopenharmony_ci SNIC_TGT_STAT_INIT, 498c2ecf20Sopenharmony_ci SNIC_TGT_STAT_ONLINE, /* Target is Online */ 508c2ecf20Sopenharmony_ci SNIC_TGT_STAT_OFFLINE, /* Target is Offline */ 518c2ecf20Sopenharmony_ci SNIC_TGT_STAT_DEL, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct snic_tgt_priv { 558c2ecf20Sopenharmony_ci struct list_head list; 568c2ecf20Sopenharmony_ci enum snic_tgt_type typ; 578c2ecf20Sopenharmony_ci u16 disc_id; 588c2ecf20Sopenharmony_ci char *name[SNIC_TGT_NAM_LEN]; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci union { 618c2ecf20Sopenharmony_ci /*DAS Target specific info */ 628c2ecf20Sopenharmony_ci /*SAN Target specific info */ 638c2ecf20Sopenharmony_ci u8 dummmy; 648c2ecf20Sopenharmony_ci } u; 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* snic tgt flags */ 688c2ecf20Sopenharmony_ci#define SNIC_TGT_SCAN_PENDING 0x01 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct snic_tgt { 718c2ecf20Sopenharmony_ci struct list_head list; 728c2ecf20Sopenharmony_ci u16 id; 738c2ecf20Sopenharmony_ci u16 channel; 748c2ecf20Sopenharmony_ci u32 flags; 758c2ecf20Sopenharmony_ci u32 scsi_tgt_id; 768c2ecf20Sopenharmony_ci enum snic_tgt_state state; 778c2ecf20Sopenharmony_ci struct device dev; 788c2ecf20Sopenharmony_ci struct work_struct scan_work; 798c2ecf20Sopenharmony_ci struct work_struct del_work; 808c2ecf20Sopenharmony_ci struct snic_tgt_priv tdata; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistruct snic_fw_req; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_civoid snic_disc_init(struct snic_disc *); 878c2ecf20Sopenharmony_ciint snic_disc_start(struct snic *); 888c2ecf20Sopenharmony_civoid snic_disc_term(struct snic *); 898c2ecf20Sopenharmony_ciint snic_report_tgt_cmpl_handler(struct snic *, struct snic_fw_req *); 908c2ecf20Sopenharmony_ciint snic_tgtinfo_cmpl_handler(struct snic *snic, struct snic_fw_req *fwreq); 918c2ecf20Sopenharmony_civoid snic_process_report_tgts_rsp(struct work_struct *); 928c2ecf20Sopenharmony_civoid snic_handle_tgt_disc(struct work_struct *); 938c2ecf20Sopenharmony_civoid snic_handle_disc(struct work_struct *); 948c2ecf20Sopenharmony_civoid snic_tgt_dev_release(struct device *); 958c2ecf20Sopenharmony_civoid snic_tgt_del_all(struct snic *); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define dev_to_tgt(d) \ 988c2ecf20Sopenharmony_ci container_of(d, struct snic_tgt, dev) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistatic inline int 1018c2ecf20Sopenharmony_ciis_snic_target(struct device *dev) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci return dev->release == snic_tgt_dev_release; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define starget_to_tgt(st) \ 1078c2ecf20Sopenharmony_ci (is_snic_target(((struct scsi_target *) st)->dev.parent) ? \ 1088c2ecf20Sopenharmony_ci dev_to_tgt(st->dev.parent) : NULL) 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#define snic_tgt_to_shost(t) \ 1118c2ecf20Sopenharmony_ci dev_to_shost(t->dev.parent) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline int 1148c2ecf20Sopenharmony_cisnic_tgt_chkready(struct snic_tgt *tgt) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci if (tgt->state == SNIC_TGT_STAT_ONLINE) 1178c2ecf20Sopenharmony_ci return 0; 1188c2ecf20Sopenharmony_ci else 1198c2ecf20Sopenharmony_ci return DID_NO_CONNECT << 16; 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciconst char *snic_tgt_state_to_str(int); 1238c2ecf20Sopenharmony_ciint snic_tgt_scsi_abort_io(struct snic_tgt *); 1248c2ecf20Sopenharmony_ci#endif /* end of __SNIC_DISC_H */ 125