zfcp_aux.c 48 KB

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