zfcp_aux.c 48 KB

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