zfcp_aux.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * (C) Copyright IBM Corp. 2002, 2006
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /*
  22. * Driver authors:
  23. * Martin Peschke (originator of the driver)
  24. * Raimund Schroeder
  25. * Aron Zeh
  26. * Wolfgang Taphorn
  27. * Stefan Bader
  28. * Heiko Carstens (kernel 2.6 port of the driver)
  29. * Andreas Herrmann
  30. * Maxim Shchetynin
  31. * Volker Sameske
  32. * Ralph Wuerthner
  33. */
  34. #include "zfcp_ext.h"
  35. /* accumulated log level (module parameter) */
  36. static u32 loglevel = ZFCP_LOG_LEVEL_DEFAULTS;
  37. static char *device;
  38. /*********************** FUNCTION PROTOTYPES *********************************/
  39. /* written against the module interface */
  40. static int __init zfcp_module_init(void);
  41. /* FCP related */
  42. static void zfcp_ns_gid_pn_handler(unsigned long);
  43. /* miscellaneous */
  44. static inline int zfcp_sg_list_alloc(struct zfcp_sg_list *, size_t);
  45. static inline void zfcp_sg_list_free(struct zfcp_sg_list *);
  46. static inline int zfcp_sg_list_copy_from_user(struct zfcp_sg_list *,
  47. void __user *, size_t);
  48. static inline int zfcp_sg_list_copy_to_user(void __user *,
  49. struct zfcp_sg_list *, size_t);
  50. static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long);
  51. #define ZFCP_CFDC_IOC_MAGIC 0xDD
  52. #define ZFCP_CFDC_IOC \
  53. _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
  54. static struct file_operations zfcp_cfdc_fops = {
  55. .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
  56. #ifdef CONFIG_COMPAT
  57. .compat_ioctl = zfcp_cfdc_dev_ioctl
  58. #endif
  59. };
  60. static struct miscdevice zfcp_cfdc_misc = {
  61. .minor = ZFCP_CFDC_DEV_MINOR,
  62. .name = ZFCP_CFDC_DEV_NAME,
  63. .fops = &zfcp_cfdc_fops
  64. };
  65. /*********************** KERNEL/MODULE PARAMETERS ***************************/
  66. /* declare driver module init/cleanup functions */
  67. module_init(zfcp_module_init);
  68. MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
  69. MODULE_DESCRIPTION
  70. ("FCP (SCSI over Fibre Channel) HBA driver for IBM System z9 and zSeries");
  71. MODULE_LICENSE("GPL");
  72. module_param(device, charp, 0400);
  73. MODULE_PARM_DESC(device, "specify initial device");
  74. module_param(loglevel, uint, 0400);
  75. MODULE_PARM_DESC(loglevel,
  76. "log levels, 8 nibbles: "
  77. "FC ERP QDIO CIO Config FSF SCSI Other, "
  78. "levels: 0=none 1=normal 2=devel 3=trace");
  79. /****************************************************************/
  80. /************** Functions without logging ***********************/
  81. /****************************************************************/
  82. void
  83. _zfcp_hex_dump(char *addr, int count)
  84. {
  85. int i;
  86. for (i = 0; i < count; i++) {
  87. printk("%02x", addr[i]);
  88. if ((i % 4) == 3)
  89. printk(" ");
  90. if ((i % 32) == 31)
  91. printk("\n");
  92. }
  93. if (((i-1) % 32) != 31)
  94. printk("\n");
  95. }
  96. /****************************************************************/
  97. /************** Uncategorised Functions *************************/
  98. /****************************************************************/
  99. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
  100. /**
  101. * zfcp_device_setup - setup function
  102. * @str: pointer to parameter string
  103. *
  104. * Parse "device=..." parameter string.
  105. */
  106. static int __init
  107. zfcp_device_setup(char *devstr)
  108. {
  109. char *tmp, *str;
  110. size_t len;
  111. if (!devstr)
  112. return 0;
  113. len = strlen(devstr) + 1;
  114. str = (char *) kmalloc(len, GFP_KERNEL);
  115. if (!str)
  116. goto err_out;
  117. memcpy(str, devstr, len);
  118. tmp = strchr(str, ',');
  119. if (!tmp)
  120. goto err_out;
  121. *tmp++ = '\0';
  122. strncpy(zfcp_data.init_busid, str, BUS_ID_SIZE);
  123. zfcp_data.init_busid[BUS_ID_SIZE-1] = '\0';
  124. zfcp_data.init_wwpn = simple_strtoull(tmp, &tmp, 0);
  125. if (*tmp++ != ',')
  126. goto err_out;
  127. if (*tmp == '\0')
  128. goto err_out;
  129. zfcp_data.init_fcp_lun = simple_strtoull(tmp, &tmp, 0);
  130. if (*tmp != '\0')
  131. goto err_out;
  132. kfree(str);
  133. return 1;
  134. err_out:
  135. ZFCP_LOG_NORMAL("Parse error for device parameter string %s\n", str);
  136. kfree(str);
  137. return 0;
  138. }
  139. static void __init
  140. zfcp_init_device_configure(void)
  141. {
  142. struct zfcp_adapter *adapter;
  143. struct zfcp_port *port;
  144. struct zfcp_unit *unit;
  145. down(&zfcp_data.config_sema);
  146. read_lock_irq(&zfcp_data.config_lock);
  147. adapter = zfcp_get_adapter_by_busid(zfcp_data.init_busid);
  148. if (adapter)
  149. zfcp_adapter_get(adapter);
  150. read_unlock_irq(&zfcp_data.config_lock);
  151. if (adapter == NULL)
  152. goto out_adapter;
  153. port = zfcp_port_enqueue(adapter, zfcp_data.init_wwpn, 0, 0);
  154. if (!port)
  155. goto out_port;
  156. unit = zfcp_unit_enqueue(port, zfcp_data.init_fcp_lun);
  157. if (!unit)
  158. goto out_unit;
  159. up(&zfcp_data.config_sema);
  160. ccw_device_set_online(adapter->ccw_device);
  161. zfcp_erp_wait(adapter);
  162. down(&zfcp_data.config_sema);
  163. zfcp_unit_put(unit);
  164. out_unit:
  165. zfcp_port_put(port);
  166. out_port:
  167. zfcp_adapter_put(adapter);
  168. out_adapter:
  169. up(&zfcp_data.config_sema);
  170. return;
  171. }
  172. static int __init
  173. zfcp_module_init(void)
  174. {
  175. int retval = 0;
  176. atomic_set(&zfcp_data.loglevel, loglevel);
  177. /* initialize adapter list */
  178. INIT_LIST_HEAD(&zfcp_data.adapter_list_head);
  179. /* initialize adapters to be removed list head */
  180. INIT_LIST_HEAD(&zfcp_data.adapter_remove_lh);
  181. zfcp_transport_template = fc_attach_transport(&zfcp_transport_functions);
  182. if (!zfcp_transport_template)
  183. return -ENODEV;
  184. retval = misc_register(&zfcp_cfdc_misc);
  185. if (retval != 0) {
  186. ZFCP_LOG_INFO("registration of misc device "
  187. "zfcp_cfdc failed\n");
  188. goto out;
  189. }
  190. ZFCP_LOG_TRACE("major/minor for zfcp_cfdc: %d/%d\n",
  191. ZFCP_CFDC_DEV_MAJOR, zfcp_cfdc_misc.minor);
  192. /* Initialise proc semaphores */
  193. sema_init(&zfcp_data.config_sema, 1);
  194. /* initialise configuration rw lock */
  195. rwlock_init(&zfcp_data.config_lock);
  196. /* save address of data structure managing the driver module */
  197. zfcp_data.scsi_host_template.module = THIS_MODULE;
  198. /* setup dynamic I/O */
  199. retval = zfcp_ccw_register();
  200. if (retval) {
  201. ZFCP_LOG_NORMAL("registration with common I/O layer failed\n");
  202. goto out_ccw_register;
  203. }
  204. if (zfcp_device_setup(device))
  205. zfcp_init_device_configure();
  206. goto out;
  207. out_ccw_register:
  208. misc_deregister(&zfcp_cfdc_misc);
  209. out:
  210. return retval;
  211. }
  212. /*
  213. * function: zfcp_cfdc_dev_ioctl
  214. *
  215. * purpose: Handle control file upload/download transaction via IOCTL
  216. * interface
  217. *
  218. * returns: 0 - Operation completed successfuly
  219. * -ENOTTY - Unknown IOCTL command
  220. * -EINVAL - Invalid sense data record
  221. * -ENXIO - The FCP adapter is not available
  222. * -EOPNOTSUPP - The FCP adapter does not have CFDC support
  223. * -ENOMEM - Insufficient memory
  224. * -EFAULT - User space memory I/O operation fault
  225. * -EPERM - Cannot create or queue FSF request or create SBALs
  226. * -ERESTARTSYS- Received signal (is mapped to EAGAIN by VFS)
  227. */
  228. static long
  229. zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
  230. unsigned long buffer)
  231. {
  232. struct zfcp_cfdc_sense_data *sense_data, __user *sense_data_user;
  233. struct zfcp_adapter *adapter = NULL;
  234. struct zfcp_fsf_req *fsf_req = NULL;
  235. struct zfcp_sg_list *sg_list = NULL;
  236. u32 fsf_command, option;
  237. char *bus_id = NULL;
  238. int retval = 0;
  239. sense_data = kmalloc(sizeof(struct zfcp_cfdc_sense_data), GFP_KERNEL);
  240. if (sense_data == NULL) {
  241. retval = -ENOMEM;
  242. goto out;
  243. }
  244. sg_list = kmalloc(sizeof(struct zfcp_sg_list), GFP_KERNEL);
  245. if (sg_list == NULL) {
  246. retval = -ENOMEM;
  247. goto out;
  248. }
  249. memset(sg_list, 0, sizeof(*sg_list));
  250. if (command != ZFCP_CFDC_IOC) {
  251. ZFCP_LOG_INFO("IOC request code 0x%x invalid\n", command);
  252. retval = -ENOTTY;
  253. goto out;
  254. }
  255. if ((sense_data_user = (void __user *) buffer) == NULL) {
  256. ZFCP_LOG_INFO("sense data record is required\n");
  257. retval = -EINVAL;
  258. goto out;
  259. }
  260. retval = copy_from_user(sense_data, sense_data_user,
  261. sizeof(struct zfcp_cfdc_sense_data));
  262. if (retval) {
  263. retval = -EFAULT;
  264. goto out;
  265. }
  266. if (sense_data->signature != ZFCP_CFDC_SIGNATURE) {
  267. ZFCP_LOG_INFO("invalid sense data request signature 0x%08x\n",
  268. ZFCP_CFDC_SIGNATURE);
  269. retval = -EINVAL;
  270. goto out;
  271. }
  272. switch (sense_data->command) {
  273. case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
  274. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  275. option = FSF_CFDC_OPTION_NORMAL_MODE;
  276. break;
  277. case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
  278. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  279. option = FSF_CFDC_OPTION_FORCE;
  280. break;
  281. case ZFCP_CFDC_CMND_FULL_ACCESS:
  282. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  283. option = FSF_CFDC_OPTION_FULL_ACCESS;
  284. break;
  285. case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
  286. fsf_command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
  287. option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
  288. break;
  289. case ZFCP_CFDC_CMND_UPLOAD:
  290. fsf_command = FSF_QTCB_UPLOAD_CONTROL_FILE;
  291. option = 0;
  292. break;
  293. default:
  294. ZFCP_LOG_INFO("invalid command code 0x%08x\n",
  295. sense_data->command);
  296. retval = -EINVAL;
  297. goto out;
  298. }
  299. bus_id = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
  300. if (bus_id == NULL) {
  301. retval = -ENOMEM;
  302. goto out;
  303. }
  304. snprintf(bus_id, BUS_ID_SIZE, "%d.%d.%04x",
  305. (sense_data->devno >> 24),
  306. (sense_data->devno >> 16) & 0xFF,
  307. (sense_data->devno & 0xFFFF));
  308. read_lock_irq(&zfcp_data.config_lock);
  309. adapter = zfcp_get_adapter_by_busid(bus_id);
  310. if (adapter)
  311. zfcp_adapter_get(adapter);
  312. read_unlock_irq(&zfcp_data.config_lock);
  313. kfree(bus_id);
  314. if (adapter == NULL) {
  315. ZFCP_LOG_INFO("invalid adapter\n");
  316. retval = -ENXIO;
  317. goto out;
  318. }
  319. if (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE) {
  320. retval = zfcp_sg_list_alloc(sg_list,
  321. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  322. if (retval) {
  323. retval = -ENOMEM;
  324. goto out;
  325. }
  326. }
  327. if ((sense_data->command & ZFCP_CFDC_DOWNLOAD) &&
  328. (sense_data->command & ZFCP_CFDC_WITH_CONTROL_FILE)) {
  329. retval = zfcp_sg_list_copy_from_user(
  330. sg_list, &sense_data_user->control_file,
  331. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  332. if (retval) {
  333. retval = -EFAULT;
  334. goto out;
  335. }
  336. }
  337. retval = zfcp_fsf_control_file(adapter, &fsf_req, fsf_command,
  338. option, sg_list);
  339. if (retval)
  340. goto out;
  341. if ((fsf_req->qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  342. (fsf_req->qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  343. retval = -ENXIO;
  344. goto out;
  345. }
  346. sense_data->fsf_status = fsf_req->qtcb->header.fsf_status;
  347. memcpy(&sense_data->fsf_status_qual,
  348. &fsf_req->qtcb->header.fsf_status_qual,
  349. sizeof(union fsf_status_qual));
  350. memcpy(&sense_data->payloads, &fsf_req->qtcb->bottom.support.els, 256);
  351. retval = copy_to_user(sense_data_user, sense_data,
  352. sizeof(struct zfcp_cfdc_sense_data));
  353. if (retval) {
  354. retval = -EFAULT;
  355. goto out;
  356. }
  357. if (sense_data->command & ZFCP_CFDC_UPLOAD) {
  358. retval = zfcp_sg_list_copy_to_user(
  359. &sense_data_user->control_file, sg_list,
  360. ZFCP_CFDC_MAX_CONTROL_FILE_SIZE);
  361. if (retval) {
  362. retval = -EFAULT;
  363. goto out;
  364. }
  365. }
  366. out:
  367. if (fsf_req != NULL)
  368. zfcp_fsf_req_free(fsf_req);
  369. if ((adapter != NULL) && (retval != -ENXIO))
  370. zfcp_adapter_put(adapter);
  371. if (sg_list != NULL) {
  372. zfcp_sg_list_free(sg_list);
  373. kfree(sg_list);
  374. }
  375. kfree(sense_data);
  376. return retval;
  377. }
  378. /**
  379. * zfcp_sg_list_alloc - create a scatter-gather list of the specified size
  380. * @sg_list: structure describing a scatter gather list
  381. * @size: size of scatter-gather list
  382. * Return: 0 on success, else -ENOMEM
  383. *
  384. * In sg_list->sg a pointer to the created scatter-gather list is returned,
  385. * or NULL if we run out of memory. sg_list->count specifies the number of
  386. * elements of the scatter-gather list. The maximum size of a single element
  387. * in the scatter-gather list is PAGE_SIZE.
  388. */
  389. static inline int
  390. zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
  391. {
  392. struct scatterlist *sg;
  393. unsigned int i;
  394. int retval = 0;
  395. void *address;
  396. BUG_ON(sg_list == NULL);
  397. sg_list->count = size >> PAGE_SHIFT;
  398. if (size & ~PAGE_MASK)
  399. sg_list->count++;
  400. sg_list->sg = kmalloc(sg_list->count * sizeof(struct scatterlist),
  401. GFP_KERNEL);
  402. if (sg_list->sg == NULL) {
  403. sg_list->count = 0;
  404. retval = -ENOMEM;
  405. goto out;
  406. }
  407. memset(sg_list->sg, 0, sg_list->count * sizeof(struct scatterlist));
  408. for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
  409. sg->length = min(size, PAGE_SIZE);
  410. sg->offset = 0;
  411. address = (void *) get_zeroed_page(GFP_KERNEL);
  412. if (address == NULL) {
  413. sg_list->count = i;
  414. zfcp_sg_list_free(sg_list);
  415. retval = -ENOMEM;
  416. goto out;
  417. }
  418. zfcp_address_to_sg(address, sg);
  419. size -= sg->length;
  420. }
  421. out:
  422. return retval;
  423. }
  424. /**
  425. * zfcp_sg_list_free - free memory of a scatter-gather list
  426. * @sg_list: structure describing a scatter-gather list
  427. *
  428. * Memory for each element in the scatter-gather list is freed.
  429. * Finally sg_list->sg is freed itself and sg_list->count is reset.
  430. */
  431. static inline void
  432. zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
  433. {
  434. struct scatterlist *sg;
  435. unsigned int i;
  436. BUG_ON(sg_list == NULL);
  437. for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++)
  438. free_page((unsigned long) zfcp_sg_to_address(sg));
  439. sg_list->count = 0;
  440. kfree(sg_list->sg);
  441. }
  442. /**
  443. * zfcp_sg_size - determine size of a scatter-gather list
  444. * @sg: array of (struct scatterlist)
  445. * @sg_count: elements in array
  446. * Return: size of entire scatter-gather list
  447. */
  448. size_t
  449. zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
  450. {
  451. unsigned int i;
  452. struct scatterlist *p;
  453. size_t size;
  454. size = 0;
  455. for (i = 0, p = sg; i < sg_count; i++, p++) {
  456. BUG_ON(p == NULL);
  457. size += p->length;
  458. }
  459. return size;
  460. }
  461. /**
  462. * zfcp_sg_list_copy_from_user -copy data from user space to scatter-gather list
  463. * @sg_list: structure describing a scatter-gather list
  464. * @user_buffer: pointer to buffer in user space
  465. * @size: number of bytes to be copied
  466. * Return: 0 on success, -EFAULT if copy_from_user fails.
  467. */
  468. static inline int
  469. zfcp_sg_list_copy_from_user(struct zfcp_sg_list *sg_list,
  470. void __user *user_buffer,
  471. size_t size)
  472. {
  473. struct scatterlist *sg;
  474. unsigned int length;
  475. void *zfcp_buffer;
  476. int retval = 0;
  477. BUG_ON(sg_list == NULL);
  478. if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
  479. return -EFAULT;
  480. for (sg = sg_list->sg; size > 0; sg++) {
  481. length = min((unsigned int)size, sg->length);
  482. zfcp_buffer = zfcp_sg_to_address(sg);
  483. if (copy_from_user(zfcp_buffer, user_buffer, length)) {
  484. retval = -EFAULT;
  485. goto out;
  486. }
  487. user_buffer += length;
  488. size -= length;
  489. }
  490. out:
  491. return retval;
  492. }
  493. /**
  494. * zfcp_sg_list_copy_to_user - copy data from scatter-gather list to user space
  495. * @user_buffer: pointer to buffer in user space
  496. * @sg_list: structure describing a scatter-gather list
  497. * @size: number of bytes to be copied
  498. * Return: 0 on success, -EFAULT if copy_to_user fails
  499. */
  500. static inline int
  501. zfcp_sg_list_copy_to_user(void __user *user_buffer,
  502. struct zfcp_sg_list *sg_list,
  503. size_t size)
  504. {
  505. struct scatterlist *sg;
  506. unsigned int length;
  507. void *zfcp_buffer;
  508. int retval = 0;
  509. BUG_ON(sg_list == NULL);
  510. if (zfcp_sg_size(sg_list->sg, sg_list->count) < size)
  511. return -EFAULT;
  512. for (sg = sg_list->sg; size > 0; sg++) {
  513. length = min((unsigned int) size, sg->length);
  514. zfcp_buffer = zfcp_sg_to_address(sg);
  515. if (copy_to_user(user_buffer, zfcp_buffer, length)) {
  516. retval = -EFAULT;
  517. goto out;
  518. }
  519. user_buffer += length;
  520. size -= length;
  521. }
  522. out:
  523. return retval;
  524. }
  525. #undef ZFCP_LOG_AREA
  526. /****************************************************************/
  527. /****** Functions for configuration/set-up of structures ********/
  528. /****************************************************************/
  529. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  530. /**
  531. * zfcp_get_unit_by_lun - find unit in unit list of port by FCP LUN
  532. * @port: pointer to port to search for unit
  533. * @fcp_lun: FCP LUN to search for
  534. * Traverse list of all units of a port and return pointer to a unit
  535. * with the given FCP LUN.
  536. */
  537. struct zfcp_unit *
  538. zfcp_get_unit_by_lun(struct zfcp_port *port, fcp_lun_t fcp_lun)
  539. {
  540. struct zfcp_unit *unit;
  541. int found = 0;
  542. list_for_each_entry(unit, &port->unit_list_head, list) {
  543. if ((unit->fcp_lun == fcp_lun) &&
  544. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status))
  545. {
  546. found = 1;
  547. break;
  548. }
  549. }
  550. return found ? unit : NULL;
  551. }
  552. /**
  553. * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
  554. * @adapter: pointer to adapter to search for port
  555. * @wwpn: wwpn to search for
  556. * Traverse list of all ports of an adapter and return pointer to a port
  557. * with the given wwpn.
  558. */
  559. struct zfcp_port *
  560. zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter, wwn_t wwpn)
  561. {
  562. struct zfcp_port *port;
  563. int found = 0;
  564. list_for_each_entry(port, &adapter->port_list_head, list) {
  565. if ((port->wwpn == wwpn) &&
  566. !(atomic_read(&port->status) &
  567. (ZFCP_STATUS_PORT_NO_WWPN | ZFCP_STATUS_COMMON_REMOVE))) {
  568. found = 1;
  569. break;
  570. }
  571. }
  572. return found ? port : NULL;
  573. }
  574. /**
  575. * zfcp_get_port_by_did - find port in port list of adapter by d_id
  576. * @adapter: pointer to adapter to search for port
  577. * @d_id: d_id to search for
  578. * Traverse list of all ports of an adapter and return pointer to a port
  579. * with the given d_id.
  580. */
  581. struct zfcp_port *
  582. zfcp_get_port_by_did(struct zfcp_adapter *adapter, u32 d_id)
  583. {
  584. struct zfcp_port *port;
  585. int found = 0;
  586. list_for_each_entry(port, &adapter->port_list_head, list) {
  587. if ((port->d_id == d_id) &&
  588. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status))
  589. {
  590. found = 1;
  591. break;
  592. }
  593. }
  594. return found ? port : NULL;
  595. }
  596. /**
  597. * zfcp_get_adapter_by_busid - find adpater in adapter list by bus_id
  598. * @bus_id: bus_id to search for
  599. * Traverse list of all adapters and return pointer to an adapter
  600. * with the given bus_id.
  601. */
  602. struct zfcp_adapter *
  603. zfcp_get_adapter_by_busid(char *bus_id)
  604. {
  605. struct zfcp_adapter *adapter;
  606. int found = 0;
  607. list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list) {
  608. if ((strncmp(bus_id, zfcp_get_busid_by_adapter(adapter),
  609. BUS_ID_SIZE) == 0) &&
  610. !atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE,
  611. &adapter->status)){
  612. found = 1;
  613. break;
  614. }
  615. }
  616. return found ? adapter : NULL;
  617. }
  618. /**
  619. * zfcp_unit_enqueue - enqueue unit to unit list of a port.
  620. * @port: pointer to port where unit is added
  621. * @fcp_lun: FCP LUN of unit to be enqueued
  622. * Return: pointer to enqueued unit on success, NULL on error
  623. * Locks: config_sema must be held to serialize changes to the unit list
  624. *
  625. * Sets up some unit internal structures and creates sysfs entry.
  626. */
  627. struct zfcp_unit *
  628. zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
  629. {
  630. struct zfcp_unit *unit, *tmp_unit;
  631. scsi_lun_t scsi_lun;
  632. int found;
  633. /*
  634. * check that there is no unit with this FCP_LUN already in list
  635. * and enqueue it.
  636. * Note: Unlike for the adapter and the port, this is an error
  637. */
  638. read_lock_irq(&zfcp_data.config_lock);
  639. unit = zfcp_get_unit_by_lun(port, fcp_lun);
  640. read_unlock_irq(&zfcp_data.config_lock);
  641. if (unit)
  642. return NULL;
  643. unit = kmalloc(sizeof (struct zfcp_unit), GFP_KERNEL);
  644. if (!unit)
  645. return NULL;
  646. memset(unit, 0, sizeof (struct zfcp_unit));
  647. /* initialise reference count stuff */
  648. atomic_set(&unit->refcount, 0);
  649. init_waitqueue_head(&unit->remove_wq);
  650. unit->port = port;
  651. unit->fcp_lun = fcp_lun;
  652. /* setup for sysfs registration */
  653. snprintf(unit->sysfs_device.bus_id, BUS_ID_SIZE, "0x%016llx", fcp_lun);
  654. unit->sysfs_device.parent = &port->sysfs_device;
  655. unit->sysfs_device.release = zfcp_sysfs_unit_release;
  656. dev_set_drvdata(&unit->sysfs_device, unit);
  657. /* mark unit unusable as long as sysfs registration is not complete */
  658. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
  659. if (device_register(&unit->sysfs_device)) {
  660. kfree(unit);
  661. return NULL;
  662. }
  663. if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) {
  664. device_unregister(&unit->sysfs_device);
  665. return NULL;
  666. }
  667. zfcp_unit_get(unit);
  668. scsi_lun = 0;
  669. found = 0;
  670. write_lock_irq(&zfcp_data.config_lock);
  671. list_for_each_entry(tmp_unit, &port->unit_list_head, list) {
  672. if (tmp_unit->scsi_lun != scsi_lun) {
  673. found = 1;
  674. break;
  675. }
  676. scsi_lun++;
  677. }
  678. unit->scsi_lun = scsi_lun;
  679. if (found)
  680. list_add_tail(&unit->list, &tmp_unit->list);
  681. else
  682. list_add_tail(&unit->list, &port->unit_list_head);
  683. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
  684. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status);
  685. write_unlock_irq(&zfcp_data.config_lock);
  686. port->units++;
  687. zfcp_port_get(port);
  688. return unit;
  689. }
  690. void
  691. zfcp_unit_dequeue(struct zfcp_unit *unit)
  692. {
  693. zfcp_unit_wait(unit);
  694. write_lock_irq(&zfcp_data.config_lock);
  695. list_del(&unit->list);
  696. write_unlock_irq(&zfcp_data.config_lock);
  697. unit->port->units--;
  698. zfcp_port_put(unit->port);
  699. zfcp_sysfs_unit_remove_files(&unit->sysfs_device);
  700. device_unregister(&unit->sysfs_device);
  701. }
  702. /*
  703. * Allocates a combined QTCB/fsf_req buffer for erp actions and fcp/SCSI
  704. * commands.
  705. * It also genrates fcp-nameserver request/response buffer and unsolicited
  706. * status read fsf_req buffers.
  707. *
  708. * locks: must only be called with zfcp_data.config_sema taken
  709. */
  710. static int
  711. zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
  712. {
  713. adapter->pool.fsf_req_erp =
  714. mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ERP_NR,
  715. sizeof(struct zfcp_fsf_req_pool_element));
  716. if (!adapter->pool.fsf_req_erp)
  717. return -ENOMEM;
  718. adapter->pool.fsf_req_scsi =
  719. mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_SCSI_NR,
  720. sizeof(struct zfcp_fsf_req_pool_element));
  721. if (!adapter->pool.fsf_req_scsi)
  722. return -ENOMEM;
  723. adapter->pool.fsf_req_abort =
  724. mempool_create_kmalloc_pool(ZFCP_POOL_FSF_REQ_ABORT_NR,
  725. sizeof(struct zfcp_fsf_req_pool_element));
  726. if (!adapter->pool.fsf_req_abort)
  727. return -ENOMEM;
  728. adapter->pool.fsf_req_status_read =
  729. mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
  730. sizeof(struct zfcp_fsf_req));
  731. if (!adapter->pool.fsf_req_status_read)
  732. return -ENOMEM;
  733. adapter->pool.data_status_read =
  734. mempool_create_kmalloc_pool(ZFCP_POOL_STATUS_READ_NR,
  735. sizeof(struct fsf_status_read_buffer));
  736. if (!adapter->pool.data_status_read)
  737. return -ENOMEM;
  738. adapter->pool.data_gid_pn =
  739. mempool_create_kmalloc_pool(ZFCP_POOL_DATA_GID_PN_NR,
  740. sizeof(struct zfcp_gid_pn_data));
  741. if (!adapter->pool.data_gid_pn)
  742. return -ENOMEM;
  743. return 0;
  744. }
  745. /**
  746. * zfcp_free_low_mem_buffers - free memory pools of an adapter
  747. * @adapter: pointer to zfcp_adapter for which memory pools should be freed
  748. * locking: zfcp_data.config_sema must be held
  749. */
  750. static void
  751. zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
  752. {
  753. if (adapter->pool.fsf_req_erp)
  754. mempool_destroy(adapter->pool.fsf_req_erp);
  755. if (adapter->pool.fsf_req_scsi)
  756. mempool_destroy(adapter->pool.fsf_req_scsi);
  757. if (adapter->pool.fsf_req_abort)
  758. mempool_destroy(adapter->pool.fsf_req_abort);
  759. if (adapter->pool.fsf_req_status_read)
  760. mempool_destroy(adapter->pool.fsf_req_status_read);
  761. if (adapter->pool.data_status_read)
  762. mempool_destroy(adapter->pool.data_status_read);
  763. if (adapter->pool.data_gid_pn)
  764. mempool_destroy(adapter->pool.data_gid_pn);
  765. }
  766. void
  767. zfcp_dummy_release(struct device *dev)
  768. {
  769. return;
  770. }
  771. /*
  772. * Enqueues an adapter at the end of the adapter list in the driver data.
  773. * All adapter internal structures are set up.
  774. * Proc-fs entries are also created.
  775. *
  776. * returns: 0 if a new adapter was successfully enqueued
  777. * ZFCP_KNOWN if an adapter with this devno was already present
  778. * -ENOMEM if alloc failed
  779. * locks: config_sema must be held to serialise changes to the adapter list
  780. */
  781. struct zfcp_adapter *
  782. zfcp_adapter_enqueue(struct ccw_device *ccw_device)
  783. {
  784. int retval = 0;
  785. struct zfcp_adapter *adapter;
  786. /*
  787. * Note: It is safe to release the list_lock, as any list changes
  788. * are protected by the config_sema, which must be held to get here
  789. */
  790. /* try to allocate new adapter data structure (zeroed) */
  791. adapter = kmalloc(sizeof (struct zfcp_adapter), GFP_KERNEL);
  792. if (!adapter) {
  793. ZFCP_LOG_INFO("error: allocation of base adapter "
  794. "structure failed\n");
  795. goto out;
  796. }
  797. memset(adapter, 0, sizeof (struct zfcp_adapter));
  798. ccw_device->handler = NULL;
  799. /* save ccw_device pointer */
  800. adapter->ccw_device = ccw_device;
  801. retval = zfcp_qdio_allocate_queues(adapter);
  802. if (retval)
  803. goto queues_alloc_failed;
  804. retval = zfcp_qdio_allocate(adapter);
  805. if (retval)
  806. goto qdio_allocate_failed;
  807. retval = zfcp_allocate_low_mem_buffers(adapter);
  808. if (retval) {
  809. ZFCP_LOG_INFO("error: pool allocation failed\n");
  810. goto failed_low_mem_buffers;
  811. }
  812. /* initialise reference count stuff */
  813. atomic_set(&adapter->refcount, 0);
  814. init_waitqueue_head(&adapter->remove_wq);
  815. /* initialise list of ports */
  816. INIT_LIST_HEAD(&adapter->port_list_head);
  817. /* initialise list of ports to be removed */
  818. INIT_LIST_HEAD(&adapter->port_remove_lh);
  819. /* initialize list of fsf requests */
  820. spin_lock_init(&adapter->fsf_req_list_lock);
  821. INIT_LIST_HEAD(&adapter->fsf_req_list_head);
  822. /* initialize debug locks */
  823. spin_lock_init(&adapter->erp_dbf_lock);
  824. spin_lock_init(&adapter->hba_dbf_lock);
  825. spin_lock_init(&adapter->san_dbf_lock);
  826. spin_lock_init(&adapter->scsi_dbf_lock);
  827. /* initialize error recovery stuff */
  828. rwlock_init(&adapter->erp_lock);
  829. sema_init(&adapter->erp_ready_sem, 0);
  830. INIT_LIST_HEAD(&adapter->erp_ready_head);
  831. INIT_LIST_HEAD(&adapter->erp_running_head);
  832. /* initialize abort lock */
  833. rwlock_init(&adapter->abort_lock);
  834. /* initialise some erp stuff */
  835. init_waitqueue_head(&adapter->erp_thread_wqh);
  836. init_waitqueue_head(&adapter->erp_done_wqh);
  837. /* initialize lock of associated request queue */
  838. rwlock_init(&adapter->request_queue.queue_lock);
  839. /* intitialise SCSI ER timer */
  840. init_timer(&adapter->scsi_er_timer);
  841. /* set FC service class used per default */
  842. adapter->fc_service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  843. sprintf(adapter->name, "%s", zfcp_get_busid_by_adapter(adapter));
  844. ASCEBC(adapter->name, strlen(adapter->name));
  845. /* mark adapter unusable as long as sysfs registration is not complete */
  846. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  847. adapter->ccw_device = ccw_device;
  848. dev_set_drvdata(&ccw_device->dev, adapter);
  849. if (zfcp_sysfs_adapter_create_files(&ccw_device->dev))
  850. goto sysfs_failed;
  851. adapter->generic_services.parent = &adapter->ccw_device->dev;
  852. adapter->generic_services.release = zfcp_dummy_release;
  853. snprintf(adapter->generic_services.bus_id, BUS_ID_SIZE,
  854. "generic_services");
  855. if (device_register(&adapter->generic_services))
  856. goto generic_services_failed;
  857. /* put allocated adapter at list tail */
  858. write_lock_irq(&zfcp_data.config_lock);
  859. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  860. list_add_tail(&adapter->list, &zfcp_data.adapter_list_head);
  861. write_unlock_irq(&zfcp_data.config_lock);
  862. zfcp_data.adapters++;
  863. goto out;
  864. generic_services_failed:
  865. zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
  866. sysfs_failed:
  867. dev_set_drvdata(&ccw_device->dev, NULL);
  868. failed_low_mem_buffers:
  869. zfcp_free_low_mem_buffers(adapter);
  870. if (qdio_free(ccw_device) != 0)
  871. ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
  872. zfcp_get_busid_by_adapter(adapter));
  873. qdio_allocate_failed:
  874. zfcp_qdio_free_queues(adapter);
  875. queues_alloc_failed:
  876. kfree(adapter);
  877. adapter = NULL;
  878. out:
  879. return adapter;
  880. }
  881. /*
  882. * returns: 0 - struct zfcp_adapter data structure successfully removed
  883. * !0 - struct zfcp_adapter data structure could not be removed
  884. * (e.g. still used)
  885. * locks: adapter list write lock is assumed to be held by caller
  886. * adapter->fsf_req_list_lock is taken and released within this
  887. * function and must not be held on entry
  888. */
  889. void
  890. zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
  891. {
  892. int retval = 0;
  893. unsigned long flags;
  894. device_unregister(&adapter->generic_services);
  895. zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
  896. dev_set_drvdata(&adapter->ccw_device->dev, NULL);
  897. /* sanity check: no pending FSF requests */
  898. spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
  899. retval = !list_empty(&adapter->fsf_req_list_head);
  900. spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
  901. if (retval) {
  902. ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
  903. "%i requests outstanding\n",
  904. zfcp_get_busid_by_adapter(adapter), adapter,
  905. atomic_read(&adapter->fsf_reqs_active));
  906. retval = -EBUSY;
  907. goto out;
  908. }
  909. /* remove specified adapter data structure from list */
  910. write_lock_irq(&zfcp_data.config_lock);
  911. list_del(&adapter->list);
  912. write_unlock_irq(&zfcp_data.config_lock);
  913. /* decrease number of adapters in list */
  914. zfcp_data.adapters--;
  915. ZFCP_LOG_TRACE("adapter %s (%p) removed from list, "
  916. "%i adapters still in list\n",
  917. zfcp_get_busid_by_adapter(adapter),
  918. adapter, zfcp_data.adapters);
  919. retval = qdio_free(adapter->ccw_device);
  920. if (retval)
  921. ZFCP_LOG_NORMAL("bug: qdio_free for adapter %s failed\n",
  922. zfcp_get_busid_by_adapter(adapter));
  923. zfcp_free_low_mem_buffers(adapter);
  924. /* free memory of adapter data structure and queues */
  925. zfcp_qdio_free_queues(adapter);
  926. kfree(adapter->fc_stats);
  927. kfree(adapter->stats_reset_data);
  928. ZFCP_LOG_TRACE("freeing adapter structure\n");
  929. kfree(adapter);
  930. out:
  931. return;
  932. }
  933. /**
  934. * zfcp_port_enqueue - enqueue port to port list of adapter
  935. * @adapter: adapter where remote port is added
  936. * @wwpn: WWPN of the remote port to be enqueued
  937. * @status: initial status for the port
  938. * @d_id: destination id of the remote port to be enqueued
  939. * Return: pointer to enqueued port on success, NULL on error
  940. * Locks: config_sema must be held to serialize changes to the port list
  941. *
  942. * All port internal structures are set up and the sysfs entry is generated.
  943. * d_id is used to enqueue ports with a well known address like the Directory
  944. * Service for nameserver lookup.
  945. */
  946. struct zfcp_port *
  947. zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn, u32 status,
  948. u32 d_id)
  949. {
  950. struct zfcp_port *port;
  951. int check_wwpn;
  952. check_wwpn = !(status & ZFCP_STATUS_PORT_NO_WWPN);
  953. /*
  954. * check that there is no port with this WWPN already in list
  955. */
  956. if (check_wwpn) {
  957. read_lock_irq(&zfcp_data.config_lock);
  958. port = zfcp_get_port_by_wwpn(adapter, wwpn);
  959. read_unlock_irq(&zfcp_data.config_lock);
  960. if (port)
  961. return NULL;
  962. }
  963. port = kmalloc(sizeof (struct zfcp_port), GFP_KERNEL);
  964. if (!port)
  965. return NULL;
  966. memset(port, 0, sizeof (struct zfcp_port));
  967. /* initialise reference count stuff */
  968. atomic_set(&port->refcount, 0);
  969. init_waitqueue_head(&port->remove_wq);
  970. INIT_LIST_HEAD(&port->unit_list_head);
  971. INIT_LIST_HEAD(&port->unit_remove_lh);
  972. port->adapter = adapter;
  973. if (check_wwpn)
  974. port->wwpn = wwpn;
  975. atomic_set_mask(status, &port->status);
  976. /* setup for sysfs registration */
  977. if (status & ZFCP_STATUS_PORT_WKA) {
  978. switch (d_id) {
  979. case ZFCP_DID_DIRECTORY_SERVICE:
  980. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  981. "directory");
  982. break;
  983. case ZFCP_DID_MANAGEMENT_SERVICE:
  984. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  985. "management");
  986. break;
  987. case ZFCP_DID_KEY_DISTRIBUTION_SERVICE:
  988. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  989. "key_distribution");
  990. break;
  991. case ZFCP_DID_ALIAS_SERVICE:
  992. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  993. "alias");
  994. break;
  995. case ZFCP_DID_TIME_SERVICE:
  996. snprintf(port->sysfs_device.bus_id, BUS_ID_SIZE,
  997. "time");
  998. break;
  999. default:
  1000. kfree(port);
  1001. return NULL;
  1002. }
  1003. port->d_id = d_id;
  1004. port->sysfs_device.parent = &adapter->generic_services;
  1005. } else {
  1006. snprintf(port->sysfs_device.bus_id,
  1007. BUS_ID_SIZE, "0x%016llx", wwpn);
  1008. port->sysfs_device.parent = &adapter->ccw_device->dev;
  1009. }
  1010. port->sysfs_device.release = zfcp_sysfs_port_release;
  1011. dev_set_drvdata(&port->sysfs_device, port);
  1012. /* mark port unusable as long as sysfs registration is not complete */
  1013. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  1014. if (device_register(&port->sysfs_device)) {
  1015. kfree(port);
  1016. return NULL;
  1017. }
  1018. if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) {
  1019. device_unregister(&port->sysfs_device);
  1020. return NULL;
  1021. }
  1022. zfcp_port_get(port);
  1023. write_lock_irq(&zfcp_data.config_lock);
  1024. list_add_tail(&port->list, &adapter->port_list_head);
  1025. atomic_clear_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  1026. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING, &port->status);
  1027. if (d_id == ZFCP_DID_DIRECTORY_SERVICE)
  1028. if (!adapter->nameserver_port)
  1029. adapter->nameserver_port = port;
  1030. adapter->ports++;
  1031. write_unlock_irq(&zfcp_data.config_lock);
  1032. zfcp_adapter_get(adapter);
  1033. return port;
  1034. }
  1035. void
  1036. zfcp_port_dequeue(struct zfcp_port *port)
  1037. {
  1038. zfcp_port_wait(port);
  1039. write_lock_irq(&zfcp_data.config_lock);
  1040. list_del(&port->list);
  1041. port->adapter->ports--;
  1042. write_unlock_irq(&zfcp_data.config_lock);
  1043. if (port->rport)
  1044. fc_remote_port_delete(port->rport);
  1045. port->rport = NULL;
  1046. zfcp_adapter_put(port->adapter);
  1047. zfcp_sysfs_port_remove_files(&port->sysfs_device,
  1048. atomic_read(&port->status));
  1049. device_unregister(&port->sysfs_device);
  1050. }
  1051. /* Enqueues a nameserver port */
  1052. int
  1053. zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
  1054. {
  1055. struct zfcp_port *port;
  1056. port = zfcp_port_enqueue(adapter, 0, ZFCP_STATUS_PORT_WKA,
  1057. ZFCP_DID_DIRECTORY_SERVICE);
  1058. if (!port) {
  1059. ZFCP_LOG_INFO("error: enqueue of nameserver port for "
  1060. "adapter %s failed\n",
  1061. zfcp_get_busid_by_adapter(adapter));
  1062. return -ENXIO;
  1063. }
  1064. zfcp_port_put(port);
  1065. return 0;
  1066. }
  1067. #undef ZFCP_LOG_AREA
  1068. /****************************************************************/
  1069. /******* Fibre Channel Standard related Functions **************/
  1070. /****************************************************************/
  1071. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
  1072. void
  1073. zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
  1074. struct fsf_status_read_buffer *status_buffer)
  1075. {
  1076. struct fcp_rscn_head *fcp_rscn_head;
  1077. struct fcp_rscn_element *fcp_rscn_element;
  1078. struct zfcp_port *port;
  1079. u16 i;
  1080. u16 no_entries;
  1081. u32 range_mask;
  1082. unsigned long flags;
  1083. fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload;
  1084. fcp_rscn_element = (struct fcp_rscn_element *) status_buffer->payload;
  1085. /* see FC-FS */
  1086. no_entries = (fcp_rscn_head->payload_len / 4);
  1087. for (i = 1; i < no_entries; i++) {
  1088. /* skip head and start with 1st element */
  1089. fcp_rscn_element++;
  1090. switch (fcp_rscn_element->addr_format) {
  1091. case ZFCP_PORT_ADDRESS:
  1092. range_mask = ZFCP_PORTS_RANGE_PORT;
  1093. break;
  1094. case ZFCP_AREA_ADDRESS:
  1095. range_mask = ZFCP_PORTS_RANGE_AREA;
  1096. break;
  1097. case ZFCP_DOMAIN_ADDRESS:
  1098. range_mask = ZFCP_PORTS_RANGE_DOMAIN;
  1099. break;
  1100. case ZFCP_FABRIC_ADDRESS:
  1101. range_mask = ZFCP_PORTS_RANGE_FABRIC;
  1102. break;
  1103. default:
  1104. ZFCP_LOG_INFO("incoming RSCN with unknown "
  1105. "address format\n");
  1106. continue;
  1107. }
  1108. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1109. list_for_each_entry(port, &adapter->port_list_head, list) {
  1110. if (atomic_test_mask
  1111. (ZFCP_STATUS_PORT_WKA, &port->status))
  1112. continue;
  1113. /* Do we know this port? If not skip it. */
  1114. if (!atomic_test_mask
  1115. (ZFCP_STATUS_PORT_DID_DID, &port->status)) {
  1116. ZFCP_LOG_INFO("incoming RSCN, trying to open "
  1117. "port 0x%016Lx\n", port->wwpn);
  1118. zfcp_erp_port_reopen(port,
  1119. ZFCP_STATUS_COMMON_ERP_FAILED);
  1120. continue;
  1121. }
  1122. /*
  1123. * FIXME: race: d_id might being invalidated
  1124. * (...DID_DID reset)
  1125. */
  1126. if ((port->d_id & range_mask)
  1127. == (fcp_rscn_element->nport_did & range_mask)) {
  1128. ZFCP_LOG_TRACE("reopen did 0x%08x\n",
  1129. fcp_rscn_element->nport_did);
  1130. /*
  1131. * Unfortunately, an RSCN does not specify the
  1132. * type of change a target underwent. We assume
  1133. * that it makes sense to reopen the link.
  1134. * FIXME: Shall we try to find out more about
  1135. * the target and link state before closing it?
  1136. * How to accomplish this? (nameserver?)
  1137. * Where would such code be put in?
  1138. * (inside or outside erp)
  1139. */
  1140. ZFCP_LOG_INFO("incoming RSCN, trying to open "
  1141. "port 0x%016Lx\n", port->wwpn);
  1142. zfcp_test_link(port);
  1143. }
  1144. }
  1145. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1146. }
  1147. }
  1148. static void
  1149. zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
  1150. struct fsf_status_read_buffer *status_buffer)
  1151. {
  1152. logi *els_logi = (logi *) status_buffer->payload;
  1153. struct zfcp_port *port;
  1154. unsigned long flags;
  1155. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1156. list_for_each_entry(port, &adapter->port_list_head, list) {
  1157. if (port->wwpn == (*(wwn_t *) & els_logi->nport_wwn))
  1158. break;
  1159. }
  1160. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1161. if (!port || (port->wwpn != (*(wwn_t *) & els_logi->nport_wwn))) {
  1162. ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
  1163. "with d_id 0x%08x on adapter %s\n",
  1164. status_buffer->d_id,
  1165. zfcp_get_busid_by_adapter(adapter));
  1166. } else {
  1167. zfcp_erp_port_forced_reopen(port, 0);
  1168. }
  1169. }
  1170. static void
  1171. zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
  1172. struct fsf_status_read_buffer *status_buffer)
  1173. {
  1174. struct fcp_logo *els_logo = (struct fcp_logo *) status_buffer->payload;
  1175. struct zfcp_port *port;
  1176. unsigned long flags;
  1177. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1178. list_for_each_entry(port, &adapter->port_list_head, list) {
  1179. if (port->wwpn == els_logo->nport_wwpn)
  1180. break;
  1181. }
  1182. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1183. if (!port || (port->wwpn != els_logo->nport_wwpn)) {
  1184. ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
  1185. "with d_id 0x%08x on adapter %s\n",
  1186. status_buffer->d_id,
  1187. zfcp_get_busid_by_adapter(adapter));
  1188. } else {
  1189. zfcp_erp_port_forced_reopen(port, 0);
  1190. }
  1191. }
  1192. static void
  1193. zfcp_fsf_incoming_els_unknown(struct zfcp_adapter *adapter,
  1194. struct fsf_status_read_buffer *status_buffer)
  1195. {
  1196. ZFCP_LOG_NORMAL("warning: unknown incoming ELS 0x%08x "
  1197. "for adapter %s\n", *(u32 *) (status_buffer->payload),
  1198. zfcp_get_busid_by_adapter(adapter));
  1199. }
  1200. void
  1201. zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
  1202. {
  1203. struct fsf_status_read_buffer *status_buffer;
  1204. u32 els_type;
  1205. struct zfcp_adapter *adapter;
  1206. status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
  1207. els_type = *(u32 *) (status_buffer->payload);
  1208. adapter = fsf_req->adapter;
  1209. zfcp_san_dbf_event_incoming_els(fsf_req);
  1210. if (els_type == LS_PLOGI)
  1211. zfcp_fsf_incoming_els_plogi(adapter, status_buffer);
  1212. else if (els_type == LS_LOGO)
  1213. zfcp_fsf_incoming_els_logo(adapter, status_buffer);
  1214. else if ((els_type & 0xffff0000) == LS_RSCN)
  1215. /* we are only concerned with the command, not the length */
  1216. zfcp_fsf_incoming_els_rscn(adapter, status_buffer);
  1217. else
  1218. zfcp_fsf_incoming_els_unknown(adapter, status_buffer);
  1219. }
  1220. /**
  1221. * zfcp_gid_pn_buffers_alloc - allocate buffers for GID_PN nameserver request
  1222. * @gid_pn: pointer to return pointer to struct zfcp_gid_pn_data
  1223. * @pool: pointer to mempool_t if non-null memory pool is used for allocation
  1224. */
  1225. static int
  1226. zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
  1227. {
  1228. struct zfcp_gid_pn_data *data;
  1229. if (pool != NULL) {
  1230. data = mempool_alloc(pool, GFP_ATOMIC);
  1231. if (likely(data != NULL)) {
  1232. data->ct.pool = pool;
  1233. }
  1234. } else {
  1235. data = kmalloc(sizeof(struct zfcp_gid_pn_data), GFP_ATOMIC);
  1236. }
  1237. if (NULL == data)
  1238. return -ENOMEM;
  1239. memset(data, 0, sizeof(*data));
  1240. data->ct.req = &data->req;
  1241. data->ct.resp = &data->resp;
  1242. data->ct.req_count = data->ct.resp_count = 1;
  1243. zfcp_address_to_sg(&data->ct_iu_req, &data->req);
  1244. zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
  1245. data->req.length = sizeof(struct ct_iu_gid_pn_req);
  1246. data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
  1247. *gid_pn = data;
  1248. return 0;
  1249. }
  1250. /**
  1251. * zfcp_gid_pn_buffers_free - free buffers for GID_PN nameserver request
  1252. * @gid_pn: pointer to struct zfcp_gid_pn_data which has to be freed
  1253. */
  1254. static void
  1255. zfcp_gid_pn_buffers_free(struct zfcp_gid_pn_data *gid_pn)
  1256. {
  1257. if ((gid_pn->ct.pool != 0))
  1258. mempool_free(gid_pn, gid_pn->ct.pool);
  1259. else
  1260. kfree(gid_pn);
  1261. return;
  1262. }
  1263. /**
  1264. * zfcp_ns_gid_pn_request - initiate GID_PN nameserver request
  1265. * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
  1266. */
  1267. int
  1268. zfcp_ns_gid_pn_request(struct zfcp_erp_action *erp_action)
  1269. {
  1270. int ret;
  1271. struct ct_iu_gid_pn_req *ct_iu_req;
  1272. struct zfcp_gid_pn_data *gid_pn;
  1273. struct zfcp_adapter *adapter = erp_action->adapter;
  1274. ret = zfcp_gid_pn_buffers_alloc(&gid_pn, adapter->pool.data_gid_pn);
  1275. if (ret < 0) {
  1276. ZFCP_LOG_INFO("error: buffer allocation for gid_pn nameserver "
  1277. "request failed for adapter %s\n",
  1278. zfcp_get_busid_by_adapter(adapter));
  1279. goto out;
  1280. }
  1281. /* setup nameserver request */
  1282. ct_iu_req = zfcp_sg_to_address(gid_pn->ct.req);
  1283. ct_iu_req->header.revision = ZFCP_CT_REVISION;
  1284. ct_iu_req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
  1285. ct_iu_req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
  1286. ct_iu_req->header.options = ZFCP_CT_SYNCHRONOUS;
  1287. ct_iu_req->header.cmd_rsp_code = ZFCP_CT_GID_PN;
  1288. ct_iu_req->header.max_res_size = ZFCP_CT_MAX_SIZE;
  1289. ct_iu_req->wwpn = erp_action->port->wwpn;
  1290. /* setup parameters for send generic command */
  1291. gid_pn->ct.port = adapter->nameserver_port;
  1292. gid_pn->ct.handler = zfcp_ns_gid_pn_handler;
  1293. gid_pn->ct.handler_data = (unsigned long) gid_pn;
  1294. gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
  1295. gid_pn->ct.timer = &erp_action->timer;
  1296. gid_pn->port = erp_action->port;
  1297. ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
  1298. erp_action);
  1299. if (ret) {
  1300. ZFCP_LOG_INFO("error: initiation of gid_pn nameserver request "
  1301. "failed for adapter %s\n",
  1302. zfcp_get_busid_by_adapter(adapter));
  1303. zfcp_gid_pn_buffers_free(gid_pn);
  1304. }
  1305. out:
  1306. return ret;
  1307. }
  1308. /**
  1309. * zfcp_ns_gid_pn_handler - handler for GID_PN nameserver request
  1310. * @data: unsigned long, contains pointer to struct zfcp_gid_pn_data
  1311. */
  1312. static void zfcp_ns_gid_pn_handler(unsigned long data)
  1313. {
  1314. struct zfcp_port *port;
  1315. struct zfcp_send_ct *ct;
  1316. struct ct_iu_gid_pn_req *ct_iu_req;
  1317. struct ct_iu_gid_pn_resp *ct_iu_resp;
  1318. struct zfcp_gid_pn_data *gid_pn;
  1319. gid_pn = (struct zfcp_gid_pn_data *) data;
  1320. port = gid_pn->port;
  1321. ct = &gid_pn->ct;
  1322. ct_iu_req = zfcp_sg_to_address(ct->req);
  1323. ct_iu_resp = zfcp_sg_to_address(ct->resp);
  1324. if (ct->status != 0)
  1325. goto failed;
  1326. if (zfcp_check_ct_response(&ct_iu_resp->header)) {
  1327. /* FIXME: do we need some specific erp entry points */
  1328. atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
  1329. goto failed;
  1330. }
  1331. /* paranoia */
  1332. if (ct_iu_req->wwpn != port->wwpn) {
  1333. ZFCP_LOG_NORMAL("bug: wwpn 0x%016Lx returned by nameserver "
  1334. "lookup does not match expected wwpn 0x%016Lx "
  1335. "for adapter %s\n", ct_iu_req->wwpn, port->wwpn,
  1336. zfcp_get_busid_by_port(port));
  1337. goto mismatch;
  1338. }
  1339. /* looks like a valid d_id */
  1340. port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
  1341. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  1342. ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n",
  1343. zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
  1344. goto out;
  1345. mismatch:
  1346. ZFCP_LOG_DEBUG("CT IUs do not match:\n");
  1347. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_req,
  1348. sizeof(struct ct_iu_gid_pn_req));
  1349. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, (char *) ct_iu_resp,
  1350. sizeof(struct ct_iu_gid_pn_resp));
  1351. failed:
  1352. ZFCP_LOG_NORMAL("warning: failed gid_pn nameserver request for wwpn "
  1353. "0x%016Lx for adapter %s\n",
  1354. port->wwpn, zfcp_get_busid_by_port(port));
  1355. out:
  1356. zfcp_gid_pn_buffers_free(gid_pn);
  1357. return;
  1358. }
  1359. /* reject CT_IU reason codes acc. to FC-GS-4 */
  1360. static const struct zfcp_rc_entry zfcp_ct_rc[] = {
  1361. {0x01, "invalid command code"},
  1362. {0x02, "invalid version level"},
  1363. {0x03, "logical error"},
  1364. {0x04, "invalid CT_IU size"},
  1365. {0x05, "logical busy"},
  1366. {0x07, "protocol error"},
  1367. {0x09, "unable to perform command request"},
  1368. {0x0b, "command not supported"},
  1369. {0x0d, "server not available"},
  1370. {0x0e, "session could not be established"},
  1371. {0xff, "vendor specific error"},
  1372. {0, NULL},
  1373. };
  1374. /* LS_RJT reason codes acc. to FC-FS */
  1375. static const struct zfcp_rc_entry zfcp_ls_rjt_rc[] = {
  1376. {0x01, "invalid LS_Command code"},
  1377. {0x03, "logical error"},
  1378. {0x05, "logical busy"},
  1379. {0x07, "protocol error"},
  1380. {0x09, "unable to perform command request"},
  1381. {0x0b, "command not supported"},
  1382. {0x0e, "command already in progress"},
  1383. {0xff, "vendor specific error"},
  1384. {0, NULL},
  1385. };
  1386. /* reject reason codes according to FC-PH/FC-FS */
  1387. static const struct zfcp_rc_entry zfcp_p_rjt_rc[] = {
  1388. {0x01, "invalid D_ID"},
  1389. {0x02, "invalid S_ID"},
  1390. {0x03, "Nx_Port not available, temporary"},
  1391. {0x04, "Nx_Port not available, permament"},
  1392. {0x05, "class not supported"},
  1393. {0x06, "delimiter usage error"},
  1394. {0x07, "TYPE not supported"},
  1395. {0x08, "invalid Link_Control"},
  1396. {0x09, "invalid R_CTL field"},
  1397. {0x0a, "invalid F_CTL field"},
  1398. {0x0b, "invalid OX_ID"},
  1399. {0x0c, "invalid RX_ID"},
  1400. {0x0d, "invalid SEQ_ID"},
  1401. {0x0e, "invalid DF_CTL"},
  1402. {0x0f, "invalid SEQ_CNT"},
  1403. {0x10, "invalid parameter field"},
  1404. {0x11, "exchange error"},
  1405. {0x12, "protocol error"},
  1406. {0x13, "incorrect length"},
  1407. {0x14, "unsupported ACK"},
  1408. {0x15, "class of service not supported by entity at FFFFFE"},
  1409. {0x16, "login required"},
  1410. {0x17, "excessive sequences attempted"},
  1411. {0x18, "unable to establish exchange"},
  1412. {0x1a, "fabric path not available"},
  1413. {0x1b, "invalid VC_ID (class 4)"},
  1414. {0x1c, "invalid CS_CTL field"},
  1415. {0x1d, "insufficient resources for VC (class 4)"},
  1416. {0x1f, "invalid class of service"},
  1417. {0x20, "preemption request rejected"},
  1418. {0x21, "preemption not enabled"},
  1419. {0x22, "multicast error"},
  1420. {0x23, "multicast error terminate"},
  1421. {0x24, "process login required"},
  1422. {0xff, "vendor specific reject"},
  1423. {0, NULL},
  1424. };
  1425. /**
  1426. * zfcp_rc_description - return description for given reaon code
  1427. * @code: reason code
  1428. * @rc_table: table of reason codes and descriptions
  1429. */
  1430. static inline const char *
  1431. zfcp_rc_description(u8 code, const struct zfcp_rc_entry *rc_table)
  1432. {
  1433. const char *descr = "unknown reason code";
  1434. do {
  1435. if (code == rc_table->code) {
  1436. descr = rc_table->description;
  1437. break;
  1438. }
  1439. rc_table++;
  1440. } while (rc_table->code && rc_table->description);
  1441. return descr;
  1442. }
  1443. /**
  1444. * zfcp_check_ct_response - evaluate reason code for CT_IU
  1445. * @rjt: response payload to an CT_IU request
  1446. * Return: 0 for accept CT_IU, 1 for reject CT_IU or invlid response code
  1447. */
  1448. int
  1449. zfcp_check_ct_response(struct ct_hdr *rjt)
  1450. {
  1451. if (rjt->cmd_rsp_code == ZFCP_CT_ACCEPT)
  1452. return 0;
  1453. if (rjt->cmd_rsp_code != ZFCP_CT_REJECT) {
  1454. ZFCP_LOG_NORMAL("error: invalid Generic Service command/"
  1455. "response code (0x%04hx)\n",
  1456. rjt->cmd_rsp_code);
  1457. return 1;
  1458. }
  1459. ZFCP_LOG_INFO("Generic Service command rejected\n");
  1460. ZFCP_LOG_INFO("%s (0x%02x, 0x%02x, 0x%02x)\n",
  1461. zfcp_rc_description(rjt->reason_code, zfcp_ct_rc),
  1462. (u32) rjt->reason_code, (u32) rjt->reason_code_expl,
  1463. (u32) rjt->vendor_unique);
  1464. return 1;
  1465. }
  1466. /**
  1467. * zfcp_print_els_rjt - print reject parameter and description for ELS reject
  1468. * @rjt_par: reject parameter acc. to FC-PH/FC-FS
  1469. * @rc_table: table of reason codes and descriptions
  1470. */
  1471. static inline void
  1472. zfcp_print_els_rjt(struct zfcp_ls_rjt_par *rjt_par,
  1473. const struct zfcp_rc_entry *rc_table)
  1474. {
  1475. ZFCP_LOG_INFO("%s (%02x %02x %02x %02x)\n",
  1476. zfcp_rc_description(rjt_par->reason_code, rc_table),
  1477. (u32) rjt_par->action, (u32) rjt_par->reason_code,
  1478. (u32) rjt_par->reason_expl, (u32) rjt_par->vendor_unique);
  1479. }
  1480. /**
  1481. * zfcp_fsf_handle_els_rjt - evaluate status qualifier/reason code on ELS reject
  1482. * @sq: status qualifier word
  1483. * @rjt_par: reject parameter as described in FC-PH and FC-FS
  1484. * Return: -EROMTEIO for LS_RJT, -EREMCHG for invalid D_ID, -EIO else
  1485. */
  1486. int
  1487. zfcp_handle_els_rjt(u32 sq, struct zfcp_ls_rjt_par *rjt_par)
  1488. {
  1489. int ret = -EIO;
  1490. if (sq == FSF_IOSTAT_NPORT_RJT) {
  1491. ZFCP_LOG_INFO("ELS rejected (P_RJT)\n");
  1492. zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
  1493. /* invalid d_id */
  1494. if (rjt_par->reason_code == 0x01)
  1495. ret = -EREMCHG;
  1496. } else if (sq == FSF_IOSTAT_FABRIC_RJT) {
  1497. ZFCP_LOG_INFO("ELS rejected (F_RJT)\n");
  1498. zfcp_print_els_rjt(rjt_par, zfcp_p_rjt_rc);
  1499. /* invalid d_id */
  1500. if (rjt_par->reason_code == 0x01)
  1501. ret = -EREMCHG;
  1502. } else if (sq == FSF_IOSTAT_LS_RJT) {
  1503. ZFCP_LOG_INFO("ELS rejected (LS_RJT)\n");
  1504. zfcp_print_els_rjt(rjt_par, zfcp_ls_rjt_rc);
  1505. ret = -EREMOTEIO;
  1506. } else
  1507. ZFCP_LOG_INFO("unexpected SQ: 0x%02x\n", sq);
  1508. return ret;
  1509. }
  1510. #undef ZFCP_LOG_AREA